@@ -54,9 +54,9 @@ varying vec2 v_texCoord;
54
54
// Smaller values can cause problems with "color" and "brightness" effects on some mobile devices
55
55
const float epsilon = 1e-3 ;
56
56
57
- // Convert an RGB color to Hue, Saturation, and Lightness .
57
+ // Convert an RGB color to Hue, Saturation, and Value .
58
58
// All components of input and output are expected to be in the [0,1] range.
59
- vec3 convertRGB2HSL (vec3 rgb)
59
+ vec3 convertRGB2HSV (vec3 rgb)
60
60
{
61
61
// Hue calculation has 3 cases, depending on which RGB component is largest, and one of those cases involves a "mod"
62
62
// operation. In order to avoid that "mod" we split the M==R case in two: one for G<B and one for B>G. The B>G case
@@ -80,13 +80,13 @@ vec3 convertRGB2HSL(vec3 rgb)
80
80
// Chroma = M - m
81
81
float C = temp2.x - m;
82
82
83
- // Lightness = 1/2 * (M + m)
84
- float L = 0.5 * ( temp2.x + m) ;
83
+ // Value = M
84
+ float V = temp2.x;
85
85
86
86
return vec3 (
87
87
abs (temp2.z + (temp2.w - temp2.y) / (6.0 * C + epsilon)), // Hue
88
- C / (1.0 - abs ( 2.0 * L - 1.0 ) + epsilon), // Saturation
89
- L ); // Lightness
88
+ C / (temp2.x + epsilon), // Saturation
89
+ V ); // Value
90
90
}
91
91
92
92
vec3 convertHue2RGB(float hue)
@@ -97,11 +97,11 @@ vec3 convertHue2RGB(float hue)
97
97
return clamp (vec3 (r, g, b), 0.0 , 1.0 );
98
98
}
99
99
100
- vec3 convertHSL2RGB (vec3 hsl )
100
+ vec3 convertHSV2RGB (vec3 hsv )
101
101
{
102
- vec3 rgb = convertHue2RGB(hsl .x);
103
- float c = ( 1.0 - abs ( 2.0 * hsl.z - 1.0 )) * hsl .y;
104
- return ( rgb - 0.5 ) * c + hsl.z ;
102
+ vec3 rgb = convertHue2RGB(hsv .x);
103
+ float c = hsv.z * hsv .y;
104
+ return rgb * c + hsv.z - c ;
105
105
}
106
106
#endif // !defined(DRAW_MODE_silhouette) && (defined(ENABLE_color) || defined(ENABLE_brightness))
107
107
@@ -166,27 +166,27 @@ void main()
166
166
167
167
#if defined(ENABLE_color) || defined(ENABLE_brightness)
168
168
{
169
- vec3 hsl = convertRGB2HSL (gl_FragColor .xyz);
169
+ vec3 hsv = convertRGB2HSV (gl_FragColor .xyz);
170
170
171
171
#ifdef ENABLE_color
172
172
{
173
173
// this code forces grayscale values to be slightly saturated
174
174
// so that some slight change of hue will be visible
175
175
const float minLightness = 0.11 / 2.0 ;
176
176
const float minSaturation = 0.09 ;
177
- if (hsl .z < minLightness) hsl = vec3 (0.0 , 1.0 , minLightness);
178
- else if (hsl .y < minSaturation) hsl = vec3 (0.0 , minSaturation, hsl .z);
177
+ if (hsv .z < minLightness) hsv = vec3 (0.0 , 1.0 , minLightness);
178
+ else if (hsv .y < minSaturation) hsv = vec3 (0.0 , minSaturation, hsv .z);
179
179
180
- hsl .x = mod (hsl .x + u_color, 1.0 );
181
- if (hsl .x < 0.0 ) hsl .x += 1.0 ;
180
+ hsv .x = mod (hsv .x + u_color, 1.0 );
181
+ if (hsv .x < 0.0 ) hsv .x += 1.0 ;
182
182
}
183
183
#endif // ENABLE_color
184
184
185
185
#ifdef ENABLE_brightness
186
- hsl .z = clamp (hsl .z + u_brightness, 0.0 , 1.0 );
186
+ hsv .z = clamp (hsv .z + u_brightness, 0.0 , 1.0 );
187
187
#endif // ENABLE_brightness
188
188
189
- gl_FragColor .rgb = convertHSL2RGB(hsl );
189
+ gl_FragColor .rgb = convertHSV2RGB(hsv );
190
190
}
191
191
#endif // defined(ENABLE_color) || defined(ENABLE_brightness)
192
192
0 commit comments