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;
|
2016-09-05 17:03:20 +02:00
|
|
|
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;
|
2016-09-05 17:03:20 +02:00
|
|
|
|
2018-05-17 22:47:00 +02:00
|
|
|
// Save the blending and color texture fetch cost
|
|
|
|
if (revealage >= 1.0) {
|
|
|
|
// discard;
|
|
|
|
fragColor = vec4(accum.rgb, 1.0);
|
|
|
|
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
|
|
|
}
|