Fix T61470: inconsistent HSV node results with saturation > 1.0.

Values outside the 0..1 range produce negative colors, so now clamp to that
range everywhere. Also fixes improper handling of hue > 2.0 in some places.
This commit is contained in:
Brecht Van Lommel 2019-02-13 16:58:54 +01:00
parent 79f5b825a9
commit ec559912fb
4 changed files with 9 additions and 15 deletions

@ -28,9 +28,8 @@ shader node_hsv(
color Color = rgb_to_hsv(ColorIn);
// remember: fmod doesn't work for negative numbers
Color[0] += Hue + 0.5;
Color[0] = fmod(Color[0], 1.0);
Color[1] *= Saturation;
Color[0] = fmod(Color[0] + Hue + 0.5, 1.0);
Color[1] *= clamp(Saturation, 0.0, 1.0);
Color[2] *= Value;
Color = hsv_to_rgb(Color);

@ -37,9 +37,8 @@ ccl_device void svm_node_hsv(KernelGlobals *kg, ShaderData *sd, float *stack, ui
color = rgb_to_hsv(color);
/* remember: fmod doesn't work for negative numbers here */
color.x += hue + 0.5f;
color.x = fmodf(color.x, 1.0f);
color.y *= sat;
color.x = fmodf(color.x + hue + 0.5f, 1.0f);
color.y *= saturate(sat);
color.z *= val;
color = hsv_to_rgb(color);

@ -881,12 +881,9 @@ void hue_sat(float hue, float sat, float value, float fac, vec4 col, out vec4 ou
rgb_to_hsv(col, hsv);
hsv[0] += (hue - 0.5);
if (hsv[0] > 1.0) hsv[0] -= 1.0; else if (hsv[0] < 0.0) hsv[0] += 1.0;
hsv[1] *= sat;
if (hsv[1] > 1.0) hsv[1] = 1.0; else if (hsv[1] < 0.0) hsv[1] = 0.0;
hsv[2] *= value;
if (hsv[2] > 1.0) hsv[2] = 1.0; else if (hsv[2] < 0.0) hsv[2] = 0.0;
hsv[0] = fract(hsv[0] + hue + 0.5);
hsv[1] = hsv[1] * clamp(sat, 0.0, 1.0);
hsv[2] = hsv[2] * value;
hsv_to_rgb(hsv, outcol);

@ -46,9 +46,8 @@ static void do_hue_sat_fac(bNode *UNUSED(node), float *out, float hue, float sat
float col[3], hsv[3], mfac = 1.0f - fac;
rgb_to_hsv(in[0], in[1], in[2], hsv, hsv + 1, hsv + 2);
hsv[0] += (hue - 0.5f);
if (hsv[0] > 1.0f) hsv[0] -= 1.0f; else if (hsv[0] < 0.0f) hsv[0] += 1.0f;
hsv[1] *= sat;
hsv[0] = fmodf(hsv[0] + hue + 0.5f, 1.0f);
hsv[1] *= clamp_f(sat, 0.0f, 1.0f);
hsv[2] *= val;
hsv_to_rgb(hsv[0], hsv[1], hsv[2], col, col + 1, col + 2);