Stencil Buffer Shadow Volumes

Started by
10 comments, last by Darrell L 21 years, 4 months ago
And my apologies for not explaining the scene I posted when I posted it. The only pieces I had rendering shadows in that version were the kings and queens. This is because, at that point, having all pieces render shadows created a really big mess due to the problem I was having.
Advertisement
I want to clarify couple of issues. I don''t use infinate projection matrix so all shadow poly vertices have w=1 before xform. I''ve been working on infinate projections using d3dfvf_rhw. You must construct projection matrix then a viewport matrix like it''s described in d3d8 docs. I concatenate view/proj/viewport then do w-divide on verts then they should get clipped. I still have to write clipping code. You could have software do the clipping but that''s inefficient as the api has to back xform thru the viewport matrix and rhw. The gf2 I''m on won''t back project in hw mode only with using software vertex processing. At this junction, the code is getting more complex than non-infinate projected code and not sure it''s worth it over the other method. You don''t have to use lit vertices for shadow volumes since color buffer writes are disabled when drawing them to stencil buffer. You can use stencil/zbuffer test on post-xformed rhw coordinates. You can use FOVLH() d3dx function to make projection matrix then GetViewport() to get vp params from which you can make viewport matrix as described in the docs. Try to avoid negating DWORD before multiplication is done as this will get you incorrect value as I think DWORDs are unsigned. Negate result after you done multiplication. D3D api sets viewport to screen size by default, this is just what we want unless you''re not drawing to entire view screen. Your verts after infinate or not infinate shadow volumes should have their w=1 as d3d docs describe. The w=0 verts will turn into w=1 after infinate projection matrix xform except when you have vertex such as (0,0,0,0). Hopefully, the api detects w=0 in post-xform and won''t divide the components by zero. Reason why w might equal zero is because your z=0. The infinate proj. matrix''s third row third column will be 1 and fourth row and third column will be near plane''s value. Read nvidia''s robust shadow volumes paper for detailed information. Don''t use Opengl''s matrix as described in that paper not even if you transpose it since I don''t think it will work. Look up D3DXMatrixPerspectiveLH() function and multiply (3,3) and (4,3) components by (f-n)/f to yield 1 and near value as I described above. Keep the rest of projection matrix as is. If you''re not going to infinate project your shadow volume verts then use unmodified D3DXMatrixPerspectiveLH() projection matrix. All points w''s are 1 in this case(set by d3d api internally) as you''re using d3dfvf_xyz vertex stride, no room for ''w''. You''ll get hw vertex xform with this algo.

This topic is closed to new replies.

Advertisement