armory/Shaders/translucent_resolve/translucent_resolve.frag.glsl

32 lines
704 B
Plaintext
Raw Normal View History

2016-05-27 01:12:21 +02:00
// Weighted blended OIT by McGuire and Bavoil
#version 450
#ifdef GL_ES
precision mediump float;
#endif
uniform sampler2D gbufferD;
uniform sampler2D gbuffer0; // saccum
uniform sampler2D gbuffer1; // srevealage
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
void main() {
vec4 accum = texture(gbuffer0, texCoord);
2016-05-27 09:46:35 +02:00
float revealage = accum.a;
2016-05-27 01:12:21 +02:00
if (revealage == 1.0) {
2016-10-17 17:39:40 +02:00
// Save the blending and color texture fetch cost
discard;
}
2016-05-27 01:12:21 +02:00
float accumA = texture(gbuffer1, texCoord).r;
// accum.a = texture(gbuffer1, texCoord).r;
2016-05-27 01:12:21 +02:00
2016-10-12 17:52:27 +02:00
// fragColor = vec4(accum.rgb / clamp(accum.a, 1e-4, 5e4), revealage);
2016-05-27 01:12:21 +02:00
const float epsilon = 0.00001;
2016-10-12 17:52:27 +02:00
fragColor = vec4(accum.rgb / max(accumA, epsilon), 1.0 - revealage);
2016-05-27 01:12:21 +02:00
}