Skip to main content
gamedev.net
🔒 Locked

Perspective shadow map math

Started by duhroach May 17, 2003 at 1:31 PM 1 replies 750+ views
Original Post
duhroach
duhroach
Howdy, I''m having some trouble finalizing the PSM math, thus far, I''ve concieved the following steps: 1. Translate the world From the camera''s view (gluLookat from the camera) And store the modelview and projection matrcies (MV and P) 2. Transform the light position by the matrix, giving LightPos=P*MV 3. do a gluLookAt(lightPos.x,lightPos.y,lightPos.z,0.f,0.f,0.f,0.f,0.f,1.f); which looks at the center of the unit cube, and grab the new modelview matrix from this process (MVL) 4. Compute the perspective opening angle to enclose the entire unit cube, grab the projection matrix from the process (PL) 5. The final projection matrix is PM=PL*MVL*P; And the MV stays the same as the transformed camera MV (not MVL) 6. Load up the PM and MV matrcies via LoadMatrix() 7. Render the scene and load into a shadow map Now, i think i have this process right, but when i project the texture, and render the final scene, I''m getting no results. I''m not even sure if the texture has any data in it. Can someone please help me with where my math is going wrong on this? thanks ~Main == Colt "MainRoach" McAnlis Programmer www.badheat.com/sinewave
assen
assen
I presume you already have:

- got non-perspective shadowmaps to work?

- checked out Thatcher Ulrich's demo at http://tulrich.com/geekstuff ?

His math looks something like this:
You have 7 matrices:

matView is the normal view matrix for your scene/camera
matViewPrime is matView slightly modified to reduce the "perspectiveness" in cases where the view is aligned with the light
matProj is the normal projection matrix for your scene/camera
matProjPrime is matProj slightly tweaked to account for modified Zfar/Znear
matViewLight is the view matrix from the light; calculated from post-perspective light position and looking at unit cube center
matProjLight is the projection matrix from the light; calculated to encompass the unit cube
matTexTweak it the matrix that tweaks the texture coordinates, taking into account different texel/pixel addressing rules (thus should be different in OpenGL <--> Direct3D) and adds a slight bias.

Now, when rendering into the shadowbuffer, you transform your vertices by

matViewPrime * matProjPrime * matViewLight * matProjLight

and when rendering with the shadowbuffer as a texture, you calculate the texture coords by multiplying world position coordinates by

matViewPrime * matProjPrime * matViewLight * matProjLight * matTexTweak

works for me :-)

PS. In your final application, you should definitely disable colorwrites when rendering the shadowbuffer, but while you debug, it certainly helps to save the colorbuffer and even display it minimap-style over your view... this will help you get some intuition about what happens if you tweak this or that constant.

[edited by - assen on May 17, 2003 3:42:52 PM]
duhroach
duhroach
assen, thanks for the break down. I''ve checked out thatcher''s demo, but the code conversion from D3D to OGL confused me. Also, I wasn''t aware i had to modify my final render and projection in order to get the correct shadow mapping. I though i could just use the former projective textuer method. I was wrong?

~Main

==
Colt "MainRoach" McAnlis
Programmer
www.badheat.com/sinewave

Topic Locked

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

Sign in to reply to this topic.