[Bf-blender-cvs] [460d1a4cb36] master: Eevee: support the no-op Bump node optimization like in Cycles.

Alexander Gavrilov noreply at git.blender.org
Tue Feb 8 12:47:43 CET 2022


Commit: 460d1a4cb36a6ae222721a9721c627292fdd77ec
Author: Alexander Gavrilov
Date:   Tue Feb 8 14:12:30 2022 +0300
Branches: master
https://developer.blender.org/rB460d1a4cb36a6ae222721a9721c627292fdd77ec

Eevee: support the no-op Bump node optimization like in Cycles.

A Bump node without a Height input is meaningless and does nothing.
As such, it is available as an old workaround that allows making Node
Group inputs that default to normal when not connected, by routing
via a no-op Bump node before doing math.

Cycles specifically recognizes this use case and either bypasses
the node, or converts it into a Geometry Normal node, but Eevee
was still evaluating it as usual. That incurred performance cost,
and also normalized the vector unlike Cycles.

This implements the same bypass logic for Eevee. Since I'm not
sure if it's possible to totally remove the node at this stage,
it emits a no-op function call to copy the input vector.

Differential Revision: https://developer.blender.org/D14045

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

M	source/blender/gpu/shaders/material/gpu_shader_material_math_util.glsl
M	source/blender/nodes/shader/nodes/node_shader_bump.cc

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

diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_math_util.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_math_util.glsl
index c6203bc36ab..2a98d9fadd0 100644
--- a/source/blender/gpu/shaders/material/gpu_shader_material_math_util.glsl
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_math_util.glsl
@@ -109,6 +109,11 @@ void vector_normalize(vec3 normal, out vec3 outnormal)
   outnormal = normalize(normal);
 }
 
+void vector_copy(vec3 normal, out vec3 outnormal)
+{
+  outnormal = normal;
+}
+
 /* Matirx Math */
 
 mat3 euler_to_mat3(vec3 euler)
diff --git a/source/blender/nodes/shader/nodes/node_shader_bump.cc b/source/blender/nodes/shader/nodes/node_shader_bump.cc
index 252abd02ad7..690eacf30ff 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bump.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_bump.cc
@@ -60,6 +60,17 @@ static int gpu_shader_bump(GPUMaterial *mat,
                            GPUNodeStack *in,
                            GPUNodeStack *out)
 {
+  /* If there is no Height input, the node becomes a no-op. */
+  if (!in[2].link) {
+    if (!in[5].link) {
+      return GPU_link(mat, "world_normals_get", &out[0].link);
+    }
+    else {
+      /* Actually running the bump code would normalize, but Cycles handles it as total no-op. */
+      return GPU_link(mat, "vector_copy", in[5].link, &out[0].link);
+    }
+  }
+
   if (!in[5].link) {
     GPU_link(mat, "world_normals_get", &in[5].link);
   }



More information about the Bf-blender-cvs mailing list