Perspective Shadow Maps - squeezed a lot

maxest

Newcomer
So I'm trying to do PSM with this recipe: http://www-sop.inria.fr/reves/Marc.Stamminger/psm/
The code:

Code:
void setupMatrices()
{
	D3DXMATRIX matView, matProj;
	D3DXMatrixLookAtLH(&matView, &cameraPosition, &D3DXVECTOR3(0.0f, 0.0f, 0.0f), &D3DXVECTOR3(0.0f, 1.0f, 0.0f));
	D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI/4, 800.0f/600.0f, 10.0f, 10000.0f);

	matrixWVP = matView * matProj;

	D3DXVECTOR4 lightPosPPS(-500.0f, 500.0f, 500.0f, 1.0f);
	D3DXVec4Transform(&lightPosPPS, &lightPosPPS, &matrixWVP);
	lightPosPPS.x /= lightPosPPS.w;
	lightPosPPS.y /= lightPosPPS.w;
	lightPosPPS.z /= lightPosPPS.w;

	D3DXMATRIX matLightViewPPS, matLightProjPPS;
	D3DXMatrixLookAtLH(&matLightViewPPS, &D3DXVECTOR3(lightPosPPS.x, lightPosPPS.y, lightPosPPS.z), &D3DXVECTOR3(0.0f, 0.0f, 0.5f), &D3DXVECTOR3(0.0f, 0.0f, 1.0f));
	D3DXMatrixPerspectiveFovLH(&matLightProjPPS, D3DX_PI/3.0f, 1.0f, 0.1f, 10000.0f);

	matrixLightWVP = matrixWVP * matLightViewPPS * matLightProjPPS;
}
First I'm creating a standard matrix for the camera and derive matrixWVP. Then I transform point light position (-500, 500, 500) to my unit cube. The final step is to make a new virtual camera located at post-perspective light position and looking down the unit cube origin.
What I get when viewing from matrixLightWVP is my scene very very squeezed to only few pixels width (the direction of squeezing depends on matLightProjPPS up vector).
I realize that PSM is not commonly used and there are better techniques but I just want to get it work in it's most standard way. I must be sure I understand how PSM works and this not-working piece of code doesn't give me a break.
What's wrong with it?
 
Back
Top