From 176f0102eaacc9f9caa5de24326137a8c3fa0f89 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 4 Nov 2014 16:50:29 +0500 Subject: 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. --- source/blender/nodes/shader/nodes/node_shader_math.c | 12 ++++++++++-- source/blender/nodes/shader/nodes/node_shader_mixRgb.c | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) (limited to 'source/blender/nodes') diff --git a/source/blender/nodes/shader/nodes/node_shader_math.c b/source/blender/nodes/shader/nodes/node_shader_math.c index dc5971909d2..a33b33682ce 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 2da51c19ef8..7d052810489 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; } -- cgit v1.2.3