diff options
author | Jeroen Bakker <jeroen@blender.org> | 2020-02-27 10:55:49 +0300 |
---|---|---|
committer | Jeroen Bakker <jeroen@blender.org> | 2020-02-27 18:02:20 +0300 |
commit | 50f9c08979bfd336616e31f3fc71a901e310db5b (patch) | |
tree | 312f373d4357855deb361549c01036940b4f19b7 /source/blender/draw/engines | |
parent | 403bb357ae2b1d2561a0d77c96035ba54c197cbd (diff) |
Fix T74063: EEVEE Render Passes
Cycles recently fixed this issue, EEVEE needed to be adapted to output
similar results in the light passes.
This patch implements cycles `safe_divide_even_color` function to a GLSL
function that will be used when extracting the light passes.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D6948
Diffstat (limited to 'source/blender/draw/engines')
-rw-r--r-- | source/blender/draw/engines/eevee/shaders/renderpass_postprocess_frag.glsl | 64 |
1 files changed, 34 insertions, 30 deletions
diff --git a/source/blender/draw/engines/eevee/shaders/renderpass_postprocess_frag.glsl b/source/blender/draw/engines/eevee/shaders/renderpass_postprocess_frag.glsl index 5214301bc03..03520c55a85 100644 --- a/source/blender/draw/engines/eevee/shaders/renderpass_postprocess_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/renderpass_postprocess_frag.glsl @@ -15,6 +15,38 @@ uniform sampler2D inputColorBuffer; out vec4 fragColor; +vec3 safe_divide_even_color(vec3 a, vec3 b) +{ + vec3 result = vec3((b.r != 0.0) ? a.r / b.r : 0.0, + (b.g != 0.0) ? a.g / b.g : 0.0, + (b.b != 0.0) ? a.b / b.b : 0.0); + /* try to get gray even if b is zero */ + if (b.r == 0.0) { + if (b.g == 0.0) { + result = result.bbb; + } + else if (b.b == 0.0) { + result = result.ggg; + } + else { + result.r = 0.5 * (result.g + result.b); + } + } + else if (b.g == 0.0) { + if (b.b == 0.0) { + result = result.rrr; + } + else { + result.g = 0.5 * (result.r + result.b); + } + } + else if (b.b == 0.0) { + result.b = 0.5 * (result.r + result.g); + } + + return result; +} + void main() { ivec2 texel = ivec2(gl_FragCoord.xy); @@ -58,41 +90,13 @@ void main() else if (postProcessType == PASS_POST_ACCUMULATED_LIGHT) { vec3 accumulated_light = texelFetch(inputBuffer, texel, 0).rgb; vec3 accumulated_color = texelFetch(inputColorBuffer, texel, 0).rgb; - - /* Fix INF in the case a color component is 0.0 */ - if (accumulated_color.r == 0.0) { - accumulated_color.r = 1.0; - accumulated_light.r = 0.0; - } - if (accumulated_color.g == 0.0) { - accumulated_color.g = 1.0; - accumulated_light.g = 0.0; - } - if (accumulated_color.b == 0.0) { - accumulated_color.b = 1.0; - accumulated_light.b = 0.0; - } - fragColor = vec4(accumulated_light / accumulated_color, 1.0); + fragColor = vec4(safe_divide_even_color(accumulated_light, accumulated_color), 1.0); } else if (postProcessType == PASS_POST_TWO_LIGHT_BUFFERS) { vec3 accumulated_light = texelFetch(inputBuffer, texel, 0).rgb + texelFetch(inputSecondLightBuffer, texel, 0).rgb; vec3 accumulated_color = texelFetch(inputColorBuffer, texel, 0).rgb; - - /* Fix INF in the case a color component is 0.0 */ - if (accumulated_color.r == 0.0) { - accumulated_color.r = 1.0; - accumulated_light.r = 0.0; - } - if (accumulated_color.g == 0.0) { - accumulated_color.g = 1.0; - accumulated_light.g = 0.0; - } - if (accumulated_color.b == 0.0) { - accumulated_color.b = 1.0; - accumulated_light.b = 0.0; - } - fragColor = vec4(accumulated_light / accumulated_color, 1.0); + fragColor = vec4(safe_divide_even_color(accumulated_light, accumulated_color), 1.0); } else { /* Output error color: Unknown how to post process this pass. */ |