Terrain cloud shadows

Started by
4 comments, last by Digitalfragment 12 years, 2 months ago
Hello,

I have a terrain and I want to render moving cloud shadows onto this terrain. Something like this:


Anyone has an idea how this effect could be achieved in a simple way with DirectX 9?
Advertisement
Projected textures are the most simple way of doing it.
I haven't done anything with projected textures, so I am not quite sure how to do it.

I understand I could use a orthographic projection (with a huuuge box) to project a texture with many cloud shapes onto the terrain. But isn't this overly complicated? Plus, how do I make the clouds move? I need some scrolling texture coordinates on my terrain vertices but I can't get up with a good idea how to implement this:/

I haven't done anything with projected textures, so I am not quite sure how to do it.

I understand I could use a orthographic projection (with a huuuge box) to project a texture with many cloud shapes onto the terrain. But isn't this overly complicated? Plus, how do I make the clouds move? I need some scrolling texture coordinates on my terrain vertices but I can't get up with a good idea how to implement this:/


If you want a simple solution and don't have separate geometry on-top of the terrain, then you can simply just pass a cloud texture along to your terrain shader and multiply against the output terrain color, then you also pass the current time along to the shader as a variable and use it to offset the cloud texture ... voila, moving cloud shadows on the terrain.


Since I have objects on my terrain (houses, trees) that should be in the cloud shadows too, I guess I have to go the projected texture way.

There are still some questions left:
1) I guess I should use a orthographic projection with a frustum box that covers the whole terrain?
2) I guess I can just use one big texture that contains several clouds? Maybe the clouds are just black and everything else in the texture is transparent. Good idea?
3) My biggest question is how to make the projected texture move. If I move the projector (the box) then eventually the terrain will be out of the frustum box. How can I implement infinite scrolling with projected textures? Maybe just add time to the projected texture coordinates?

1) I guess I should use a orthographic projection with a frustum box that covers the whole terrain?

Ortho is the easiest to get working, and is close enough to correct anyway when dealing with sunlight. As far as covering the whole terrain, i would instead make it a configurable width/depth on the terrain. See 3)


2) I guess I can just use one big texture that contains several clouds? Maybe the clouds are just black and everything else in the texture is transparent. Good idea?

Yeah, that works. You could use photoshop to cread a perlin noise pattern, and sample the texture multiple times with slightly different projections to get layers of clouds. You can also remap the texture output to make the clouds lighter or denser, if you want a dynamic cloudcover.


3) My biggest question is how to make the projected texture move. If I move the projector (the box) then eventually the terrain will be out of the frustum box. How can I implement infinite scrolling with projected textures? Maybe just add time to the projected texture coordinates?

If your texture sampler is set to repeat, instead of clamp, then its not a problem. By translating the projection matrix in the direction of the wind, you automatically get scrolling textures. This way scrolling cloud cover does not add any additional GPU time to your shader.

To avoid precision issues though, it might be a good idea to snap the projection coordinate system to a stable local center - but thats an afterthought for once its working if you do see precision issues.

This topic is closed to new replies.

Advertisement