[Bf-blender-cvs] [d9ddc99] master: Fix T42184: Normal not displayed correctly in Material Viewport

Sergey Sharybin noreply at git.blender.org
Wed Dec 10 15:15:08 CET 2014


Commit: d9ddc99a27a4b50b54c1582d780c21f78483375d
Author: Sergey Sharybin
Date:   Wed Dec 10 19:12:54 2014 +0500
Branches: master
https://developer.blender.org/rBd9ddc99a27a4b50b54c1582d780c21f78483375d

Fix T42184: Normal not displayed correctly in Material Viewport

There was a differences between how Cycles and BI treats Normal shader:

- Different normal direction assumption
- Different policy about vector normalization

Previous idea of trying to use single function and flip the output if
needed becomes more tricky, so i've just added new GLSL function which
corresponds to how Cycles deals with the Normal shader.

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

M	source/blender/gpu/shaders/gpu_shader_material.glsl
M	source/blender/nodes/shader/nodes/node_shader_normal.c

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

diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl
index b68a1ee..3a04a36 100644
--- a/source/blender/gpu/shaders/gpu_shader_material.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_material.glsl
@@ -357,6 +357,12 @@ void normal(vec3 dir, vec3 nor, out vec3 outnor, out float outdot)
 	outdot = -dot(dir, nor);
 }
 
+void normal_new_shading(vec3 dir, vec3 nor, out vec3 outnor, out float outdot)
+{
+	outnor = normalize(nor);
+	outdot = dot(normalize(dir), nor);
+}
+
 void curves_vec(float fac, vec3 vec, sampler2D curvemap, out vec3 outvec)
 {
 	outvec.x = texture2D(curvemap, vec2((vec.x + 1.0)*0.5, 0.0)).x;
diff --git a/source/blender/nodes/shader/nodes/node_shader_normal.c b/source/blender/nodes/shader/nodes/node_shader_normal.c
index 847d2e6..092fc20 100644
--- a/source/blender/nodes/shader/nodes/node_shader_normal.c
+++ b/source/blender/nodes/shader/nodes/node_shader_normal.c
@@ -61,12 +61,12 @@ static void node_shader_exec_normal(void *UNUSED(data), int UNUSED(thread), bNod
 static int gpu_shader_normal(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
 {
 	GPUNodeLink *vec = GPU_uniform(out[0].vec);
-	int ret = GPU_stack_link(mat, "normal", in, out, vec);
-	if (ret && GPU_material_use_new_shading_nodes(mat)) {
-		float fac[3] = {-1.0f, -1.0f, -1.0f};
-		GPU_link(mat, "math_multiply", GPU_uniform(fac), out[1].link, &out[1].link);
+	if (GPU_material_use_new_shading_nodes(mat)) {
+		return GPU_stack_link(mat, "normal_new_shading", in, out, vec);
+	}
+	else {
+		return GPU_stack_link(mat, "normal", in, out, vec);
 	}
-	return ret;
 }
 
 void register_node_type_sh_normal(void)




More information about the Bf-blender-cvs mailing list