Sign in to follow this  
SiS-Shadowman

cloud rendering

Recommended Posts

i know, here are alot of threads about cloud rendering, but i haven't found a single post wich explicitly explains how to shade the clouds. finally i've managed to write a cloud generator ( using perlin noise, done on the cpu ). the created texture then is just mapped on a curved skyplane ( the texture defines the alpha channel ). ( http://www.shadowman-works.de/forum/files/2/clouds1.png & http://www.shadowman-works.de/forum/files/2/clouds2.png ) but how can i shade the clouds? can somebody explain me how this could be done? i think a simple model ( taking into account the density of the clouds and the color of the sun ) would be enough.

Share this post


Link to post
Share on other sites
as long as i can see these articles cover clouds for a flight sim or something similar. the cloud systems are all particle based and their lighting formulas are much more complicated as for a "static" sky, aren't they? is there a possibility to adapt them for my ( and many others ) method?

Share this post


Link to post
Share on other sites
the thread is interesting, but i can't get it right. some people speak of raytracing a ray from the sun trough the cloud => how am i supposed to do that o.O

another thing that is missing: how do i calculate the density of a cloud? should i just take the r g b value of the cloudmap, multiply it and this is its density?

the last thing that is really bugged: i want to light my clouds, not with the standart paralell lighting method, but with the sun as a point light.


Out.Pos = mul(Pos, matWorldViewProjection);

// Sunrays from pointlight
// lightDir is the Position of the Sun on the Skydome
Out.hemi = saturate(dot(normalize(lightDir - Out.Pos), normalize(mul(Normal, matRotation))));



the funny thing is that my clouds change color, depending how the camera is aligned to them *g
i have no idea why this is happening, since lightDir is definately the position of the sun. the rotation of the cam doesn't even appear in the code for the cloud rendering.

Share this post


Link to post
Share on other sites
You're transforming the position into clip space and then finding the vector between that and the light (which I assume is in world space). That will just give you garbage since they are in different coordinate systems. I think you would be better off lighting in world space.

Btw having a variable named 'lightDir' be the light position is kindof misleading.

Also assuming the result of mul(Normal, matRotation) is a float4 you must specify that the .xyz are being normalized and not the w as well, or you will get incorrect restults.

Share this post


Link to post
Share on other sites
Quote:
Original post by SiS-Shadowman
the funny thing is that my clouds change color, depending how the camera is aligned to them *g
i have no idea why this is happening, since lightDir is definately the position of the sun. the rotation of the cam doesn't even appear in the code for the cloud rendering.


Try resetting the lightDir variable every frame, basically right before using it. I ran into a similar lighting problem and this fixed it for me, so I never got around to actually figuring out why my lighting changed with the camera angle... I just assumed lighting was tied to the view matrix somehow.

Share this post


Link to post
Share on other sites
Quote:
Original post by jamesw
You're transforming the position into clip space and then finding the vector between that and the light (which I assume is in world space). That will just give you garbage since they are in different coordinate systems. I think you would be better off lighting in world space.


*slap* ok, so i need to multiply the Position with the Transformation Matrix, right?

Quote:

Btw having a variable named 'lightDir' be the light position is kindof misleading.


yeah, i was just to lazy to introduce another variable for the Position of the light, since i have one shader file for the whole environment ( starbox, skydome, sun, etc... )

Quote:

Also assuming the result of mul(Normal, matRotation) is a float4 you must specify that the .xyz are being normalized and not the w as well, or you will get incorrect restults.


i don't get what you mean here. isn't the .w var uninteresting?

Share this post


Link to post
Share on other sites
Here's what I meant by lighting in world space:

Out.Pos = mul(Pos, matWorldViewProjection);

Out.hemi = saturate(dot(normalize(lightWorldPos - Pos.xyz), normalize(mul(Normal, matRotation).xyz)));




Off topic, but it helps to include the coordinate space of positions and vectors. This gets really useful when you are doing any combination of operations in object, world, view, clip and tangent space all in the same shader.

Quote:
i don't get what you mean here. isn't the .w var uninteresting?


I haven't had this problem myself but heard about it from Jack's journal entry

Quote:
Almost as stupid as the time I forgot to specify .rgb and my normalization was working on a 4D instead of 3D vector. That was an odd mistake to track down and fix...

Share this post


Link to post
Share on other sites
does someone have a technique to shade those 2d clouds to make them look at least good? it doesn't have to be perfect, but i think i need a sample to be able to do that, i have no idea to start, except when it comes to the sun.


float4 SmoothBlending(float4 a, float4 b)
{
return (a + b - (a*b));
}

tempFloat = 1.0 - tex2D(AlphaSampler, Tex0); // the more white the texture is, the denser the cloud should be => 1 - CloudTexture
tempDiffuse = SmoothBlending(tempFloat, CloudColor);
tempDiffuse.a = tex2D(AlphaSampler, Tex0);



how should i now add the sunlight ( and use the dotproduct between the vertex's position and the sunlight direction ) to shade the clouds?

Share this post


Link to post
Share on other sites
can you show me how this looks?

*edit*

anyway....

this is a link to a movie of my engine ( with 500x speed )

this is pretty much what i could do. i still stuck with lighting the clouds.
all i am doing for now is using the perlin noise for the alpha channel and for the cloud color:


tempFloat = 1.0 - tex2D(AlphaSampler, Tex0); // the cloud density from the perlin noise needs to be "inverted", because the more white a cloud appears on the map, the denser it is
tempFloat = pow(tempFloat, 0.3f); // if i just took the inverted value, the cloud would be too dark, so i scale it "down": since 0<tempFloat<1 pow(tempFloat, 0.3) will give a higher value
tempDiffuse = CloudColor * tempFloat; // just multiply the cloud color ( wich is 1.0f by now ) with the density
tempDiffuse.a = tex2D(AlphaSampler, Tex0); // add alpha channel according to the perlin noise map

return tempDiffuse;




perhaps someone can offer me a tipp how to integrate the light comming from the sun and thus influencing the cloud color by the sun's color.
any help would be appretiated :)

[Edited by - SiS-Shadowman on October 14, 2006 3:13:27 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this