Calling shader gurus! I need help with Animated Procedural Texture

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.

mhhh wait it’s a gray scale…so why not just multiply with the full color?



[java]vec4 finalColor = vec4(n) * m_sunColor * vec4(0.33);[/java]

1 Like

Seriously @nehon WTF!?



You made a pact with the devil or what? I did that earlier (not exactly that code, but still) but got my color skewed one way or the other, but …



Oh to hell with that. Thanks. :stuck_out_tongue:



Seriously though, I was doing something similar and colors were wrong everywhere except for red. I was doing something wrong, that’s for sure.



Working great now.

@madjack said:
You made a pact with the devil or what?

Actually thats one of the core membership prerequisites ;)

I should’ve known. :stuck_out_tongue:

@madjack said:
You made a pact with the devil or what?

not at all...the devil made a pact with me! :evil:

BTW I want a nice screen shot of a blue sun!!

How’s that for you? A binary system at that. It’s all faked though. :wink:



http://www.danyrioux.com/files/fornehon.png



Just for you. Cyan. Not that you’ll see that color in my game though. :wink:

1 Like

NIce!