[Bf-blender-cvs] [50f9c08979b] master: Fix T74063: EEVEE Render Passes

Jeroen Bakker noreply at git.blender.org
Thu Feb 27 16:02:40 CET 2020


Commit: 50f9c08979bfd336616e31f3fc71a901e310db5b
Author: Jeroen Bakker
Date:   Thu Feb 27 08:55:49 2020 +0100
Branches: master
https://developer.blender.org/rB50f9c08979bfd336616e31f3fc71a901e310db5b

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

===================================================================

M	source/blender/draw/engines/eevee/shaders/renderpass_postprocess_frag.glsl

===================================================================

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. */



More information about the Bf-blender-cvs mailing list