Jump to content
  • Advertisement
Sign in to follow this  
Leo_E_49

Stencil shadows or shadow mapping?

This topic is 4830 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

In your opinion, which is the best method of handling shadows to learn first for an aspiring game programmer? I'm going to learn both but time is a premium so I need one method which can handle self-shadowing and environment shadowing to start with. Are there any other methods which can handle self-shadowing on dynamic objects? Also, do you have any articles/book references/tutorials on these topics? If you want to write an explanation here, feel free. I know of one or two in GPU Gems and Game Programming Gems 2 but I am having a bit of trouble understanding how they work. (Particularly, how to apply the shadows to non-planar surfaces and how to self-shadow) It's preferable if the method can be implemented in both OpenGL and DirectX.

Share this post


Link to post
Share on other sites
Advertisement
the article in game programming gems 2 doesn't speak of shadow buffers, just projected shadows [as in, no self shadows]

I'd argue that neither technique is difficult to understand, but a time limit might make implementing them interesting

nvidia's website has papers on both techniques
do a search for "shadow" on it:
http://developer.nvidia.com/page/home.html

hey look, some links for you:
http://developer.nvidia.com/object/hwshadowmap_paper.html
http://developer.nvidia.com/object/robust_shadow_volumes.html

Share this post


Link to post
Share on other sites
Hmm, well, I'm dense, I found shadows to be one of the harder things to do in a full pipeline.. I had to completely alter my pipeline for them, so it is good to think about it before you go to far ahead.

Anyways:

Shadow volumes - pros, on OpenGL, it is easier. Cons, uses alot of fill rate, need a fast video card. Also, uses alot of CPU. Also, alot of pathological cases and checks. Can be a pain in the neck to implement.

Shadow Maps - probably the future of shadows. In opengl, can be a real nightmare with pbuffers. Cons, aliases, but there are some techniques now to deal with that problem.

Either way they are both a pain to implement IMHO..

Share this post


Link to post
Share on other sites
Ok, I've decided to go with the stencil shadow approach first, simply because my graphics card can't handle shadow mapping.

Now, I understand how to get the silhouette and I sort-of understand the extrusion into a shadow volume, however from here I'm lost [help]. How does this algorithm sort out which areas of each model is inside the shadow volume and how does the algorithm darken them? I took a look at the code (which doesn't seem very complete) and I'm completely befuddled. I don't even know what's happening after I compute the shadow volume...

Also, I don't really understand how the stencil buffer is used in applying the shadows to non-planar surfaces. [bawling]

Share this post


Link to post
Share on other sites
there is a nice article here at gamedev explaining what to do with those volumes, though I never implemented shadow volumes, I was recently reading up on it myself and found it quite understandable:
http://www.gamedev.net/reference/articles/article1873.asp

sry, still don´t know how to make links clickable :)
hope it helps.

Share this post


Link to post
Share on other sites
Quote:
Original post by Leo_E_49
Ok, I've decided to go with the stencil shadow approach first, simply because my graphics card can't handle shadow mapping.

Now, I understand how to get the silhouette and I sort-of understand the extrusion into a shadow volume, however from here I'm lost [help]. How does this algorithm sort out which areas of each model is inside the shadow volume and how does the algorithm darken them? I took a look at the code (which doesn't seem very complete) and I'm completely befuddled. I don't even know what's happening after I compute the shadow volume...

Also, I don't really understand how the stencil buffer is used in applying the shadows to non-planar surfaces. [bawling]


It's magic!

It's a trick that works with the Z-buffer. For that to work, the shadow volume has to be a closed volume. That is, for example, when you cast a ray from outside the volume, you will hit an even number of faces. If you are inside, you will hit a odd number of faces. That's an old trick for deciding if a point is in the volume or not.

You usually start off with clearing the stencil to a value (usually, mid-range, like 128).

OK, so, when you render the volume quad extrusions that are facing the light (the 'front' quads), for each pixel that gets rendered, it's stencil value is increased.

Then you render the back-facing quads. For each pixel of the quad that gets hit, you decrease it's stencil value.

So, for pixels that are part of both front and back faces, the stencil value remains unchanged. Those pixels belong to the 'empty' part of the scene, the part where there is nothing between the front and back faces of the silhouette, since both sides gets rendered.

Identically, the parts of the scene outside the shadow volume will also be unchanged (nothing gets drawn there).

Now, if there is something solid between the front and the back faces, at the pixel position, the front face will pass the z-test (since it's in front of the occlusion), and the stencil is incremented. But, the back face will fail the z-test, since it will be behind the occlusion. So in the end, on the pixel inside the shadow volume, the value will be greater than the clear value.

These pixels with a non-default value is where the shadow should be rendered. To do it simplistically, setup the stencil so that only pixels with values !+ default pass the test, and draw a full screen transparent quad. Pixels which pass the test will only be rendered, drawing a shaded area where the shadow is.

problems... When the camera is inside the volume. The effect is effectively reversed.

To counteract that, there are a few articles explaining how to fix those problems.

The stencil shadow work, whatever the surfaces. All it needs is a filled Z-buffer, and a stencil buffer.

*But*, to make it robust is a pain in the ass. Geometry has to be 2-manifold. No T-junctions, no stray polygons, all geometry had to be closed (as if it could hold a liquid). It's also incredibly expensive (fill rate, silhouette calculations).

example of a multilight stencil shadow, relatively robust.

you will need GLUT.

Share this post


Link to post
Share on other sites
Just my two cents: I would personally go with Shadow Buffers (Shadow Maps, whatever you want to call them) over Shadow Volumes. The reasons being:

1) Shadow Volumes require that all skinning/extrusion be done on the CPU, and thus cannot be accelerated. Shadow Buffers are already handled in hardware, and it's likely to be something that receives a lot of attention from graphics cards vendors in the future.

2) The requirements for Shadow Volumes grow drastically as your meshes increase in complexity, due to the difficulty in finding the edges to extrude. Shadow Maps don't suffer from this, and scale very well with the complexity of your scene.

3) Shadow Volumes are difficult to get working (well) with self shadowing.

4) Shadow Volumes require significant changes to get soft shadowing, and it generally much easier to simply stick with hard edged shadows. Shadow Maps tend to adapt to soft shadowing better through various shader tricks.

Finally, the old OpenGL pbuffer excuse is no longer valid since the FBO extension is avalible on pretty much any card that's powerful enough to do shadows anyways.

I don't want to discourage your from doing Shadow Volumes if you want, as it's still a perfectly valid method. Just thought you should be aware of some of the baggage they come with. ^_^

Share this post


Link to post
Share on other sites
Quote:
Original post by Toji
1) Shadow Volumes require that all skinning/extrusion be done on the CPU, and thus cannot be accelerated. Shadow Buffers are already handled in hardware, and it's likely to be something that receives a lot of attention from graphics cards vendors in the future.

2) The requirements for Shadow Volumes grow drastically as your meshes increase in complexity, due to the difficulty in finding the edges to extrude. Shadow Maps don't suffer from this, and scale very well with the complexity of your scene.

You can do shadow volume extrusion on the GPU. linky.

Enigma

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!