Archived

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

bltiger

How to draw a static scene's shadow?

Recommended Posts

I have read some articles, it suggest me to use stencil buffer, but stencil buffer need hardware support, How can I draw the shadow? Can anybody give some sample code?

Share this post


Link to post
Share on other sites
quote:

How to draw a static scene''s shadow?



if it''s a truly static scene (nothing will ever move in it) then you should just precalculate everything using some kind of raytracing and use light maps.

Share this post


Link to post
Share on other sites
You could knife you geometry where the shadows fall, and burn the shadow colour into the approperate verts colour.

(Watch out for gourard effects though - usually solved with more sub division)

Share this post


Link to post
Share on other sites
Thanks for your help,

My scene is a truly static scene (nothing will ever move in it) ,

I do not know how can i calc the lightmap,

Can I get some sample code about lightmap?

Share this post


Link to post
Share on other sites
there is no simple code for calculating light maps... spend a couple of weeks researching ray tracing if you want to do a really good job of it.

Share this post


Link to post
Share on other sites
A lot of console games do the vertex method. Off the top of my head I know FFX and Wild Arms 3 does it. I think it looks pretty decent actually, and it still gives room to be a little dynamic.

Share this post


Link to post
Share on other sites
Given enough vertices, you don''t need a lightmap.

I can''t remember the name of the game that tried this at the moment, but I know it has been done. I think Hardware T&L is a must if you take this approach. This also frees up a texture stage to use for something else (such as a bump map or environment map).

I''m working on algorithms that actually slices polygons where shadows are cast, and changes the diffuse values of the vertices accordingly. This would theoretically be faster than calculating light maps, but it would have to be done before putting the data into video memory (due to the splitting of polygons).

This results in shadows that look like those from older games (like Doom and Duke Nukem 3D) that designers manually put in, but they would be automatic.

If this doesn''t work, I have considered rendering more polygons on top of the scene with alpha blending. It would be based on the same principles as my other idea, but instead of "cutting up" the geometry it would just add layers to it. I think this would look like a high-res light map with sharp edges.

For shadows cast by models, don''t rule out the use of a projection matrix to project the vertices onto a flat surface. However, this will double the count of triangles rendered for each model, and doesn''t work if you want an alpha-blended shadow.

I personally don''t like the look of (most) lightmaps. I don''t like blocky shadows with textels orthogonal to the axes. From a distance things look okay, but dramatic shadows seem to lose their effect when up close. But in many cases lightmaps are the best solution.

This is why I''m really looking forward to Doom 3. Especially teh fact that everything is treated the same (be it the world or the characters). Shadows being cast on the ground and moving across a creature just delights me to no end. Even better, the fact that the shadow can be moved.

Then again, John Carmack knows more about 3-D than I do, and he''s been doing it longer.

--TheMuuj

Share this post


Link to post
Share on other sites
quote:
Original post by bltiger
Thanks, I think I have to do it with raytracing....


If you dare searching through a German page :-)

www.stefanzerbst.de
Tutorials (left side)
then "Lightmapping by Johannes Leimbach" (that''s me :-)
The tutorial is in German, but the source is in English
and _heavily_ commented.

Mail me if you have questions :
johannes.leimbach@gmx.de

Share this post


Link to post
Share on other sites
That code is very heavily commented

will be putting some of those tuts through a translation site... hope they still make sense

Cheers m8

Gordon.

Share this post


Link to post
Share on other sites