Archived

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

Rodolfo

Easyer way to implement shadows

Recommended Posts

Do anyone know an easyer way to implement shadowing to a 3D scene than the one in the 28th NeHe''s tutorial? That''s not a very adaptable code... How can I implement this on any kind of scene? If I''ve said something lame, and you don''t pretend to answer me, at least let me know I did it, so I''ll try to learn a little more before posting something here Thank you, Rodolfo

Share this post


Link to post
Share on other sites
I''m actually not sure, but I''ll bet if there were an easier way to do it then the author of tutorial 28 would have used the other method.

You could use lightmapping, that is always good

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The code in lesson 28 is reusable. You can give it other shapes. Shadow volumes like in lesson 28 is great if you want shadows on a complex (non planar) object. If you want shadows on something flat like a wall is projective shadows probably better.

The different methods can be combined. Many good documents about this can be found on the nvidia developer pages.

Share this post


Link to post
Share on other sites
From what I''ve seen, using a shadow volume (like nehe''s lesson 28, I think) is the most popular way to do shadows. Once you understand how it works, you realize that the idea is rather extensible, but it tends to be a bit slower, and doesn''t work on some computers (like mine...). There are some other ways to do it, but most don''t work nearly as well as this one. For a good explanation, check out gamasutra''s article. http://www.gamasutra.com/features/19991115/bestimt_freitag_01.htm

Share this post


Link to post
Share on other sites
Almost nobody uses the lesson 28 technique, it requires the stencil buffer which many 3d cards today don''t support so it goes slow. Also the shadows it produces have very sharp edges and don''t look realistic at all. Lightmapping is what almost everybody uses, I actually can''t think of a game today that uses anything else, maybe I just can''t remember them.

Share this post


Link to post
Share on other sites
all cards built today have a hardware stencil (well maybe not the noname cards out of china) the only popular cards that dont have one are voodoo1/2/3. if a card can do 32bit colour it should have a hardware stencil

http://members.xoom.com/myBollux

Share this post


Link to post
Share on other sites
I can think of a ways to do dynamic shadows:
  • Do a parallel projection into a single plane using the modelview matrix. If you setup your matrix well, you can draw like you always do, and the vertices will end up on the same plane. The problem is: it''s only one plane, and the projection is parallel. No stencil buffer needed though
  • You can project your vertices onto a single plane with your own calculation, so it''s not parallel. It''s like doing point on plane calculation. With the vector from the light to the vertex you''re projecting. Check out raytracing tutorials to find more on this math. Still no stencil buffer needed
  • Use a depthmap. Render view seen from the light. Safe Z-buffer and use it as a texture to project onto your objects. Pretty slow because you have to copy from depthbuffer to texture.
  • The best: calculate the silouette seen from the light. Use these edges and draw polygons in the stencil buffer. The value in this stencil buffer tells you if you are in the shadows or not. Best techique if you ask me, but cannot do without stencil buffer. Calculating the silouette FAST is not easy.


  • What am I babbling about anyway. You can find it all on NVIDIA''s site. The developer section!

    Share this post


    Link to post
    Share on other sites
    Check

    http://www.ronfrazier.net/apparition/index.html under research projects. In particular look at

    http://www.ronfrazier.net/apparition/index.asp?appmain=research/advanced_per_pixel_lighting.html

    but I''d also suggest reading the other material on his site as well.

    After all that, I''d suggest going with shadow mapping-hybrid approach. I''ve been told the GeForce3 has some nice way of dealing with the artifacts, though since I didn''t read about it for myself, I can''t say off hand what it does.

    For more info on shadow mapping check out

    http://www.nvidia.com/Marketing/developer/devrel.nsf/e7355303c372563288256825006836c6/a0d00bbf5afbfb0b882568a5007f8c66/$FILE/GDC2K_ogl_shadowmap.pdf

    It''s kilgards presentation from GDC 2000 on shadowmapping in GL.

    It might take a while to get through all of this, but I hope it helps.

    DN

    Share this post


    Link to post
    Share on other sites
    For the pdf on kilgards Shadowmapping technique, check

    http://www.nvidia.com/marketing/developer/devrel.nsf/045cfdb95e306a4d882568170059fa93/c89b7fc5f0497efc88256a1800672176/$FILE/GDC01_Shadows.pdf

    This is newer than the one I previously posted.

    Sorry ''bout the mishap

    DN.

    Share this post


    Link to post
    Share on other sites
    All said here so far is true.

    As far as the shadows being too sharp - it would be good to do some sort of pass (anti-aliasing) to "fuzzy them up" a bit to make it look better. But in terms of light penetration they are dead accurate.

    As for being reusable, that''s definitely the case. After writing up the HTML I found it pretty easy to convert the code to render Milkshape models with shadows.

    That''s all available in PortaLib3D... I think gamedev need a little plug icon at the top for me to put on all my posts



    ~~~
    Cheers!
    Brett Porter
    PortaLib3D : A portable 3D game/demo libary for OpenGL

    Share this post


    Link to post
    Share on other sites