Jump to content
  • Advertisement


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


Perspective Shadow Map Math..

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

hey all, I''m working on implimenting PSM, and all my projections are off slightly. Not to mention, I''m not getting any shadow map result itself. from my understanding, this is the process: 1. Our transformation from world space to post perspective space is the matrix T=P*MV where P= our camera''s Perspective matrix MV= our camera''s ModelView matrix Thus T maps a visible scene point in world space to the unit cube [-1,1] in R3. IE transformation by T puts stuff in "post-perspective" space 2.We then have to transform our light pos & light dir by T to put it in Post-perspective space. 3.We load T into our current modelview matrix in order to transform all other points relative to this transformation 4.Then, set up our shadow map as normal, using gluLookAt(loc.x, loc.y,loc.z,dir.x, dir.y, dir.z,0.f,1.f,0.f); 5.Once the shadow Map is updated, restore Modelview matrix Via glLoadIdentity();translate via camera.LookAt(); I know there''s some more conceptual stuff in there, however, i was trying to just get the basic method working. Below is the math i''m using.
float T[16];
	//we want to get the mvp for what is ultimatly going to be the camera


	//Get our model view matrix

	glGetFloatv(GL_MODELVIEW_MATRIX, mv);

	//push our model view, so we can use it later


	//multiply our current p with mv: p*mv


	//get the result of p*mv



	//Transform our light position by T

	l->loc.x=T[0]*l->loc.x + T[1]*l->loc.y + T[2]*l->loc.z; //T[3]

	l->loc.y=T[4]*l->loc.x + T[5]*l->loc.y + T[6]*l->loc.z; //T[7]

	l->loc.z=T[8]*l->loc.x + T[9]*l->loc.y + T[11]*l->loc.z; //T[12]


	//also, transform our dir by T

	l->dir.x=T[0]*l->dir.x + T[1]*l->dir.y + T[2]*l->dir.z; //T[3]

	l->dir.y=T[4]*l->dir.x + T[5]*l->dir.y + T[6]*l->dir.z; //T[7]

	l->dir.z=T[8]*l->dir.x + T[9]*l->dir.y + T[11]*l->dir.z; //T[12]


//setup view from our light

gluLookAt(loc.x, loc.y,	loc.z,			  
dir.x, dir.y, dir.z,	
//render scene, copy to SM image

Firstly, Do i have the concept correct? or am i completly lost? Secondly, am i doing something wrong with my math? thanks ~Main == Colt "MainRoach" McAnlis Programmer www.badheat.com/sinewave

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!