Skip to main content
gamedev.net
🔒 Locked

Stencil shadow question

Started by Toni Petrina May 5, 2004 at 2:40 PM 6 replies 600+ views
Original Post
Toni Petrina
Toni Petrina
Please excuse my lack of knowledge but I am reading about stencil shadow volumes. I read about errors when using Depth-Pass algorithm and it hit me: every frame we perform raytracing test from camera to each light from which shadow volume is constructed. If ray intersects some geometry we can state that camera is in shadow volume for that particular light and we increase shadowRefCount by one. Now we set stencil buffer to shadowRefCount. If we now perform standard Depth-Pass algorithm for shadow volumes we''ll get correct values. I know that I am missing something, but isn''t this possible?
So... Muira Yoshimoto sliced off his head, walked 8 miles, and defeated a Mongolian horde... by beating them with his head?

Documentation? "We are writing games, we don't have to document anything".
Toni Petrina
Toni Petrina
OK, maybe I haven't asked the right question.

If camera is inside shadow volume, depthpass algorith fails because its ray didn't enter shadow volume and therefore stencil wasn't incremented by one. If ray now intersects object within shadow volume (which is shadowed because it is inside) it will set stencil value to 0 (because we haven't yet entered shadow volume) and object won't be shadowed.

What I thought of is that if camera is inside shadow volume it should start stencil counting at number that is nonzero and represents number that denotes in how many shadow volumes camer is placed. Back to original example, if camera is inside shadow volume, we start counting at 1 and object previosly not shadowed will now be shadowed.

Now I want to know if this is possible?

[edited by - ffx on May 5, 2004 3:56:03 PM]
So... Muira Yoshimoto sliced off his head, walked 8 miles, and defeated a Mongolian horde... by beating them with his head?

Documentation? "We are writing games, we don't have to document anything".
MumbleFuzz
MumbleFuzz
In principle, this method does work, and I''ve seen it implemented in some demos. However, I think there are probably some serious performance problems.

Thing is, determining whether the camera is within a shadow volume is a very CPU expensive process. If you can guarantee your volumes are all convex, then for each volume, you would firstly calculate the equations of the planes in the volume (if the volumes are dynamic, anyway), and then find the distance of the camera from each plane. This has to be done for every shadow volume for every light.

If your volumes aren''t convex, I honestly don''t know how you''d do it, other than form a volume for every single polygon.

The method I use is to put a simple bounding box around each object and check to see if this comes between the light and the camera. If it does, use z-fail, otherwise, use z-pass. This will then use the z-pass algorithm most of the time, and is much faster to calculate.
MumbleFuzz
imajor
imajor
ffx it will work only if you have single shadow volumes. Imagine that you have two spheres and both casting a shadow on the same location on a wall. Then the camera may be in both shadow volumes so you should start with 2 as shadowRefCount. So you should check out all objects one by one and see if the ray intersects or not. A much better solutuion is to use the z-fail method instead of z-pass. That means that you increase/decrease stencil values when z test fails and do nothing when it passes. Very interesting idea, perfect solution for your problem, although you must cap shadow volumes to get correct result. Google for it.
Toni Petrina
Toni Petrina
Ah. Thanks. I knew that it is too complex. I''ll stick with shadow maps anyway.
So... Muira Yoshimoto sliced off his head, walked 8 miles, and defeated a Mongolian horde... by beating them with his head?

Documentation? "We are writing games, we don't have to document anything".
BlackSheep
BlackSheep
quote:
Original post by MumbleFuzz

Thing is, determining whether the camera is within a shadow volume is a very CPU expensive process. If you can guarantee your volumes are all convex, then for each volume, you would firstly calculate the equations of the planes in the volume (if the volumes are dynamic, anyway), and then find the distance of the camera from each plane. This has to be done for every shadow volume for every light.

If your volumes aren''t convex, I honestly don''t know how you''d do it, other than form a volume for every single polygon.



To check if a camera is inside a shadow volume, why not just do a line of sight test to every light that''s in range? The geometry of the volume is irrelevant, it''s either lit, or it isn''t

Toni Petrina
Toni Petrina
quote:
Original post by BlackSheep


To check if a camera is inside a shadow volume, why not just do a line of sight test to every light that''s in range? The geometry of the volume is irrelevant, it''s either lit, or it isn''t




That is what I meant when I said raytracing test in my first post. Would that be an actual optimization to shadow volume algorithm?
So... Muira Yoshimoto sliced off his head, walked 8 miles, and defeated a Mongolian horde... by beating them with his head?

Documentation? "We are writing games, we don't have to document anything".
MumbleFuzz
MumbleFuzz
D'oh. Don't know why I didn't think of that. I suppose that would give an increase in speed. I might try it.

It's worth mentioning though that such an implementation is not totally robust; in some cases, the near clip plane will span both sides of a shadow plane, resulting in incorrect shadows which cannot be compensated for by changing the reference value. Depending on what your engine is used for, this may or may not be an issue, but it's worth keeping in mind.

[edited by - MumbleFuzz on May 10, 2004 11:52:52 AM]
MumbleFuzz

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.