I made a damn pretty shader, if I may say so myself, that will generate a texture on a sphere using the Ken Perlin’s Simplex Noise but with a twist. Some guys have made that algorithm for GLSL without using a LUT (lookup texture).
Right now I’m using the 4D noise that is directly applied to a sphere. Everything works great except for one small problem; coloring.
Noise textures are greyscale. What I need to do is colorize the grayscaled image with a color parameter passed to the shader so that it’ll end up like the image below, only with the right color applied to it. That picture is fine because it’s red. The green and blue channel remain at 0.
Using the above, it’s simple to apply the color by using:
[java]
// n = the noise greyscale for that pixel.
// m_sunColor = color passed to the shader from the material.
// r = the new “tinted” color.
float r = (n * m_sunColor.r * 0.33);
[/java]
But, with a color like light blue (154, 175, 255) I can’t use the formula above.
That’s where you guys come in.
I found some information saying this:
The algorithm would be something like this:
- Pick the target color in terms of two values, a Hue and a Saturation. The hue determines the tone of the color (green, red, etc.), and the saturation determines how pure the color is (the less pure the more the color turns to gray).
- Now for each pixel in your grayscale image, compute the new pixel in the HLS color model, where H and S are your target hue and saturation, and L is the gray value of your pixel.
- Convert this HLS color to RGB and save to the new picture.
For the algorithm to convert HLS to RGB see this page or this page.
But I can't make sense of this. I'm also worried it might bring severe performance issues.
I'm continuing to work on this but it'd be nice if one of you had an idea or knew how to do this.