[Bf-blender-cvs] [176f010] master: Fix T42445: Clamp flag has no effect on result value in Math and MixRGB shader nodes (Blender Render)

Sergey Sharybin noreply at git.blender.org
Tue Nov 4 12:57:21 CET 2014


Commit: 176f0102eaacc9f9caa5de24326137a8c3fa0f89
Author: Sergey Sharybin
Date:   Tue Nov 4 16:50:29 2014 +0500
Branches: master
https://developer.blender.org/rB176f0102eaacc9f9caa5de24326137a8c3fa0f89

Fix T42445: Clamp flag has no effect on result value in Math and MixRGB shader nodes (Blender Render)

Quite striaghtforward implementation, with the only weird thing that for some reason
my video driver wasn't happy with calling the function "clamp" giving some weirdo
shader compilation error messages.

Called the GPU function clamp_val which can handle float and vec3.

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

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

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

diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl
index 5a0812c..39e8b31 100644
--- a/source/blender/gpu/shaders/gpu_shader_material.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_material.glsl
@@ -722,6 +722,16 @@ void invert(float fac, vec4 col, out vec4 outcol)
 	outcol.w = col.w;
 }
 
+void clamp_val(vec3 vec, vec3 min, vec3 max, out vec3 out_vec)
+{
+	out_vec = clamp(vec, min, max);
+}
+
+void clamp_val(float value, float min, float max, out float out_value)
+{
+	out_value = clamp(value, min, max);
+}
+
 void hue_sat(float hue, float sat, float value, float fac, vec4 col, out vec4 outcol)
 {
 	vec4 hsv;
diff --git a/source/blender/nodes/shader/nodes/node_shader_math.c b/source/blender/nodes/shader/nodes/node_shader_math.c
index dc59719..a33b336 100644
--- a/source/blender/nodes/shader/nodes/node_shader_math.c
+++ b/source/blender/nodes/shader/nodes/node_shader_math.c
@@ -222,7 +222,9 @@ static void node_shader_exec_math(void *UNUSED(data), int UNUSED(thread), bNode
 			break;
 		}
 	}
-	
+	if (node->custom2 & SHD_MATH_CLAMP) {
+		CLAMP(r, 0.0f, 1.0f);
+	}
 	out[0]->vec[0] = r;
 }
 
@@ -272,7 +274,13 @@ static int gpu_shader_math(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(
 		default:
 			return 0;
 	}
-	
+
+	if (node->custom2 & SHD_MATH_CLAMP) {
+		float min[3] = {0.0f, 0.0f, 0.0f};
+		float max[3] = {1.0f, 1.0f, 1.0f};
+		GPU_link(mat, "clamp_val", out[0].link, GPU_uniform(min), GPU_uniform(max), &out[0].link);
+	}
+
 	return 1;
 }
 
diff --git a/source/blender/nodes/shader/nodes/node_shader_mixRgb.c b/source/blender/nodes/shader/nodes/node_shader_mixRgb.c
index 2da51c1..7d05281 100644
--- a/source/blender/nodes/shader/nodes/node_shader_mixRgb.c
+++ b/source/blender/nodes/shader/nodes/node_shader_mixRgb.c
@@ -59,6 +59,9 @@ static void node_shader_exec_mix_rgb(void *UNUSED(data), int UNUSED(thread), bNo
 	nodestack_get_vec(vec, SOCK_VECTOR, in[2]);
 
 	ramp_blend(node->custom1, col, fac, vec);
+	if (node->custom2 & SHD_MIXRGB_CLAMP) {
+		CLAMP3(col, 0.0f, 1.0f);
+	}
 	copy_v3_v3(out[0]->vec, col);
 }
 
@@ -68,8 +71,13 @@ static int gpu_shader_mix_rgb(GPUMaterial *mat, bNode *node, bNodeExecData *UNUS
 		                          "mix_screen", "mix_div", "mix_diff", "mix_dark", "mix_light",
 		                          "mix_overlay", "mix_dodge", "mix_burn", "mix_hue", "mix_sat",
 		                          "mix_val", "mix_color", "mix_soft", "mix_linear"};
-
-	return GPU_stack_link(mat, names[node->custom1], in, out);
+	int ret = GPU_stack_link(mat, names[node->custom1], in, out);
+	if (ret && node->custom2 & SHD_MIXRGB_CLAMP) {
+		float min[3] = {0.0f, 0.0f, 0.0f};
+		float max[3] = {1.0f, 1.0f, 1.0f};
+		GPU_link(mat, "clamp_val", out[0].link, GPU_uniform(min), GPU_uniform(max), &out[0].link);
+	}
+	return ret;
 }




More information about the Bf-blender-cvs mailing list