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.
This commit is contained in:
Sergey Sharybin
2014-11-04 16:50:29 +05:00
parent 988b3d7188
commit 176f0102ea
3 changed files with 30 additions and 4 deletions

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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;
}