Archived

This topic is now archived and is closed to further replies.

Shadowing... need a little guidance

This topic is 5377 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m rendering a terrain. On the terrain there may be several hundred ornament meshes. I am quite keen to get some kind of shadowing going. As I understand it, I have a couple of choices: 1) Shadow-maps. This is where I create textures to represent each ornament''s shadow, and then blend the texture on the terrain. 2) Shadow-volumes with a z-buffer. This creates the most realistic types of shadow, but, correct me if I''m wrong, I have to basically draw every ornament twice, which is seriously slow going. I''m relatively OK with reading up about how to do these things (although I do think it''s about time for DirectX to have a function called D3DxRenderShadows()), but I just want to make sure that my thinking is straight before I go off and invest huge amounts of time. I''m guessing that because I want to have a time-of-day thing going, I''m probably going to have to use shadow volumes, but... that will almost certainly be far too slow for everything right? Are there any other techniques I can use? Learning to fly is easy, but as a tortoise, the landings are really rough.

Share this post


Link to post
Share on other sites
Both shadow volumes and shadow maps are very slow. If your shadows are not animated and don''t affect anything but the terrain, you should do something else. For example, decals or projected textures, or simpler shadows.

Share this post


Link to post
Share on other sites
You can use projective textures.. or you create the shadow directly on your terrain-batch texture (like you can do it with shading) - depends on your needs.

narbo

Share this post


Link to post
Share on other sites
If you want to have a time-of-day shadows, I think you have to go with texturing - you can prerender the textures in advance (if there won`t be many changes of lighting) or you can do it every time you need to move the shadows a bit - you only calculate it once and then just use the texture which is OK, because today`s and yesterday`s HW makes multitexturing easy and fast. If there`s a short-time slowdown during calculating, it`s still better than low performance all the time.

This has disadvantage that the shadows are dependant on resolution of shadow texture but shadow texture could be B/W (minimal mem size) so there is not a big problem with texture resolution.

You can definitely render shadows to texture on terrain. I calculate the shadows this way on complex objects triangle after triangle - although I do it only few times during gameplay - realtime is not an option with 10.000 triangles on screen - slows things down pretty much.

So you have a light position and a triangle that is obstacle. You calc.intersection of that ray with terrain. When you find out the triangle it intersects, find the specific position of intersection with that triangle. According to triangle`s texture coordinates you can calculate the texel coordinate for shadow triangles. Repeat it for all three points and fill that triangle in memory (just watch for intersection with neigbhbouring triangles).
Repeat it for all obstacle triangles and you`ve got a texture map of shadows. It`s all clear when you draw it on paper.
If your terrain is heightmap, finding texel coordinates for intersected is really easy - just take a look from above the terrain down on interesection point and you`ll see it.

And no, DirectX can`t have a function for shadows.I don`t think there`s gonna be a time n near future that we can afford having everything shadowed on everything. Besides every game needs different type of shadows co it`s you who tweaks the shadow algorithm to fit your needs.

Share this post


Link to post
Share on other sites
quote:
Original post by SoaringTortoise
1) Shadow-maps. This is where I create textures to represent each ornament''s shadow, and then blend the texture on the terrain.

Not exactly. You actually create one shadow map for the whole scene (more acurately, one per light source), not for each object. You then use that to decide which fragments need to be shadowed and take appropriate action.
quote:

2) Shadow-volumes with a z-buffer. This creates the most realistic types of shadow, but, correct me if I''m wrong, I have to basically draw every ornament twice, which is seriously slow going.

Correct, once to get the initial depth values, and once as part of the shadow volumes (although the latter can be replaced by simpler geometry). Plus you need to draw the rest of shadow volumes'' geometry. Not to mention that you need to construct that geometry in the first place (note: that can be done entirely on the GPU, using a vertex shader). Athough it actually isn''t that slow on modern hardware.
quote:
I''m guessing that because I want to have a time-of-day thing going, I''m probably going to have to use shadow volumes, but... that will almost certainly be far too slow for everything right?

For simple scenes, shadow volumes will do fine. For more complex ones, calculating and drawing them becomes a pain, and will likely kill your perfromance. Shadow maps work well for both, but being an image-based technique, they have their own set of problems.
They can both be adapted for dynamic scenes (e.g. moving sun).

Note: while texture are used for shadow-maps, do not confuse that with what VladR described (he described a different techique)...

Michael K.,
Designer and Graphics Programmer of "The Keepers"



We come in peace... surrender or die!

Share this post


Link to post
Share on other sites
It seems to me that shadow maps would be the fastest to use (not in real-time) but least flexible since you''d need several different maps for each position of the light.

I''ve seen other methods that use shadow volumes and vertex shaders to create shadows in real time but it seems that this would be much too slow to do on the entire terrain or even in one node of the visible terrain of an octree or something.

Share this post


Link to post
Share on other sites
quote:

It seems to me that shadow maps would be the fastest to use (not in real-time) but least flexible since you''d need several different maps for each position of the light.


You mean projection shadow textures ? Shadowmaps are something different, since they are created on the fly.

Share this post


Link to post
Share on other sites