Sign in to follow this  
akira32

shadow maps with directional light

Recommended Posts

akira32    112
The difference of directional light and point light in shadow maps is the light projection,right? I want to modify the shadow maps source code of point light to directional light. But I have a confuse about the projection matrix of directional light in line11. The line11 should be float h=2*NEARPLANE*tanf(0.5f/2.0f);, the angle should be equal to fovY/2. In practice, the angle is not equal to fovY/2. Could somebody tell why? Is the angle is incorrect in calculation. How do calculate the Width of the view plane and the Height of view plane in the function of D3DXMatrixOrthoLH?
HRESULT CreateShadowMap()
{
	D3DXMATRIX mS, mT, mR;

	// view and projection matrix for the light source
	D3DXMATRIX mView, mProj;
	D3DXVECTOR3 vLookatPt = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
	D3DXVECTOR3 vUpVec    = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
	D3DXMatrixLookAtLH(&mView, &m_LightPos, &vLookatPt, &vUpVec);

	float h=2*NEARPLANE*tanf(0.5f*2.0f);
	float w=h;

#define _USE_DIR_LIGHT_
#ifdef _USE_DIR_LIGHT_
	D3DXMatrixOrthoLH(&mProj,w,h,NEARPLANE, FARPLANE);
#else
	D3DXMatrixPerspectiveFovLH(&mProj, 0.5f, 1.0f, NEARPLANE, FARPLANE);
#endif


[Edited by - akira32 on November 23, 2008 8:56:32 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this