#### Archived

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

# Another Stencil Shadow Volume Question

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

## Recommended Posts

Okay, I've implemented the shadow volume technique as in the Direct3D samples. Everything seems to work great. I have a couple of questions that I can't seem to find answers to however and I was hoping for a little help if anyone has any ideas. Before I get into that, I'll give you the overview of what I'm doing.... I use the standard 2-pass where I increment if the front faces pass and decrement if the back faces pass. For each edge, I extrude it's vertices along the light vector by some constant (say 100.0f units). 1) If I'm using a directional light, why am I concerned with it clipping against the far plane? Nothing won't be visible past that far plane anyway so why would I be worried about artifacts (if there are any)? 2) How do I know what distance to extrude the edges from my light source? Right now I'm using a constant (100) but that really could be any number. How do I know what's right? 3) I started to do it so that I use an infinite far plane projection matrix for drawing the shadow volume (I assume this would fix my question 2?) The standard D3D projection matrix is defined as:


float    h, w, Q;

w = (float)1/tan(fov_horiz*0.5);  // 1/tan(x) == cot(x)

h = (float)1/tan(fov_vert*0.5);   // 1/tan(x) == cot(x)

Q = far_plane/(far_plane - near_plane);

D3DXMATRIX ret;
ZeroMemory(&ret, sizeof(ret));

ret(0, 0) = w;
ret(1, 1) = h;
ret(2, 2) = Q;
ret(3, 2) = -Q*near_plane;
ret(2, 3) = 1;
return ret;

So I use this as my infinite far plane projection matrix...

float    h, w, Q;

w = (float)1/tan(fov_horiz*0.5);  // 1/tan(x) == cot(x)

h = (float)1/tan(fov_vert*0.5);   // 1/tan(x) == cot(x)

Q = far_plane/(far_plane - near_plane);

D3DXMATRIX ret;
ZeroMemory(&ret, sizeof(ret));

ret(0, 0) = w;
ret(1, 1) = h;
ret(2, 2) = 1.0;
ret(3, 2) = -near_plane;
ret(2, 3) = 1;
return ret;

Does this seem correct? When I enable that matrix as my projection for the shadow volume, my shadow moves away from my object depending on where my camera is placed. In other words, it don't seem right. What could be the problem here? Thanks everyone. That's my initial set of problems here. I've read the nvidia docs and gamasutra docs on the subject but didn't make it much clearer and they do most of their work in OpenGL. SO I hope someone here can help. edit: Okay, I've seen the problem to my first question. I can see the far plane slice my shadow volume so I understand the problem there. I still have the problem with my infinite matrix however. The further I am from my object, the further away the shadow is from my object. And the closer the camera is to the object, the more correct the shadow is in relation to the object. Does anyone have any idea what's going on there? Do I need to do anything different with respect to creating my shadow volume given that I'm using an infinite far view plane? Here's a link to some pics showing the problem... http://www.geocities.com/dpicco2002/ [edited by - Draigan on October 21, 2002 10:52:51 PM] [edited by - Draigan on October 21, 2002 11:54:41 PM]

##### Share on other sites
Also, with regards to Carmack's Reverse, does it have to be capped? I took the D3D sample that renders shadow volumes and changed it so that the backfacing ones incremented on z-fail and the front ones decremented on z-fail and it didn't look right.

I could see the shadow of the bi-plane and another shadow further away on the left which I guess is where it intersects the far plane.

[edited by - Draigan on October 21, 2002 11:36:11 PM]

Anyone?

##### Share on other sites
Yep, the zFail (Carmack''s Reverse) approach requires volumes to be capped both at the model and at the far plane (at infinity).

http://users.ox.ac.uk/~univ1234

##### Share on other sites
OKay, I''ve been trying to implement the zfail approach without putting the far plane at infinity. I believe this should still work because the Nvidia articles by Mark Kilgard mentions that carmack''s method had problems because carmack didn''t extrude the silohuete to infinity... that should mean that J. Carmack had it nearly working without this right? I should be able to get it nearly working without the infinite far plane shouldn''t I?

##### Share on other sites
Carmack optimized his algoritm for use in the DoomIII engine which is primarily meant for "eerily, scary, indoors environment" in his own words. That means the clipping problems cause by the far plane not being at infinity will almost never happen. Indoors environment do not extent forever. This way, he can speed up the shadow vol calculations without extruding to infinity. Yes, using the reverse method, u will need to cap the shadow vol at the front and at the back(infinity or not).
Since he is focusing on indoors, theres no point in going infinity becos theres a whole load of other problems to deal with if u extrude the shadow vol that way.

"To focus, is to know what you are NOT going to do" ~J.Carmack

______________________________________________
(MSG_POST_DONE) ? InsertWittySignature() : ContinuePosting()

http://www.geocities.com/codeman_net/

##### Share on other sites
I''m just curious.... what other problem arise if you extrude to infinity?

##### Share on other sites
You have to draw more pixels to the screen, slowing things down.
Other than that, I see no more problems.

[edited by - bakery2k1 on October 23, 2002 3:09:02 PM]

##### Share on other sites
Yeah, that''s the only thing I could think of as well. That doesn''t seem like a problem in a pure sense... seems more like an area for optimization. I would consider a problem something where''d you''d have to put in extra code to deal with some visual/other anomaly.

##### Share on other sites
But i guess it must have been a problem for optimization-mad carmack. He evidently do not have a liking for overdraw. There are also issues with intersecting shadow vols at infinity. You could trash a lot of code if u do not need to extrude to infinity and shorter code "usually" meant faster and easier to maintain code.

[edited by - flipstar on October 28, 2002 6:35:54 AM]

1. 1
Rutin
19
2. 2
3. 3
JoeJ
16
4. 4
5. 5

• 26
• 20
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631700
• Total Posts
3001781
×