Hi,
Using a noise texture I want to adjust the brightness of the terrain texture in the shader to make an artistic effect. So for example, instead of grass and dirt having the same color saturation and brightness all over the place I want to smoothly modify the color to have darker/brighter grass.
I am doing this by converting RGB color to HSV in the fragment shader and adjusting the brightness and then converting it back to the RGB model. (get the rgb2hsv
code from StackOverflow)
vec3 rgb2hsv(vec3 c) {
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
float d = q.x - min(q.w, q.y);
float e = 1.0e-10;
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}
vec3 hsv2rgb(vec3 c) {
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
and using it like this
vec4 colorNoise = texture(m_NoiseMap, texCoord * 6.0);
vec3 hsb = rgb2hsv(color.rgb);
float b = 1.0 + (colorNoise.x * 0.5);
hsb.z *= b;
color.rgb = hsv2rgb(hsb);
I am curious to know if it is possible to do this without converting to HSV color possibly using some other trick?
Edit:
Or is it possible to cache the result and reuse it later inside the shader? because it is purely based on diffuse color and noise texture and does not depend on lighting or so…
And yes, I am a shader noob!