armory/Shaders/translucent_resolve/translucent_resolve.frag.glsl

34 lines
741 B
Plaintext
Raw Normal View History

2016-05-27 01:12:21 +02:00
// Weighted blended OIT by McGuire and Bavoil
#version 450
2018-05-17 22:47:00 +02:00
// uniform sampler2D gbufferD;
uniform sampler2D gbuffer0; // saccum
uniform sampler2D gbuffer1; // srevealage
2016-05-27 01:12:21 +02:00
2018-05-17 22:47:00 +02:00
uniform vec2 texSize;
2016-05-27 01:12:21 +02:00
in vec2 texCoord;
2016-10-12 17:52:27 +02:00
out vec4 fragColor;
2016-05-27 01:12:21 +02:00
2018-05-17 22:47:00 +02:00
float maxComponent(vec4 v) {
return max(max(max(v.x, v.y), v.z), v.w);
}
2016-05-27 01:12:21 +02:00
void main() {
2018-05-17 22:47:00 +02:00
vec4 accum = texelFetch(gbuffer0, ivec2(texCoord * texSize), 0);
float revealage = 1.0 - accum.a;
2018-05-17 22:47:00 +02:00
// Save the blending and color texture fetch cost
2018-05-19 14:35:00 +02:00
if (revealage == 0.0) {
discard;
2018-05-17 22:47:00 +02:00
return;
2016-10-17 17:39:40 +02:00
}
2016-05-27 01:12:21 +02:00
2018-05-17 22:47:00 +02:00
if (isinf(maxComponent(abs(accum)))) {
accum.rgb = vec3(revealage);
}
2016-11-24 17:35:12 +01:00
2018-05-17 22:47:00 +02:00
float f = texelFetch(gbuffer1, ivec2(texCoord * texSize), 0).r;
fragColor = vec4(accum.rgb / clamp(f, 1e-4, 5e4), revealage);
2016-05-27 01:12:21 +02:00
}