Skip to main content
GameDev.net gamedev.net
🔒 Locked

Strange problem

Started by ayush3017 Sep 10, 2010 at 7:09 AM 0 replies 950+ views
Original Post
ayush3017
ayush3017
I am trying to develop VSM.
Here is the problem:
">

Previously I had a problem of aliasing in my shadows. I solved that problem by cropping the shadow matrices depending upon the view frustum and then this new problem. I developed my code for extracting frustum corners (same problem), then copied the code from MJP's website(same problem). I think my view frustum coreners are now ok. But the problem I think is of light clipping plane. I used PIX and the shadow is formed only for the brighter areas. The shadow map ends where the black area in the video starts. Here is the code for calculating the view frustum coreners:
//Calculate cornersfloat nearH = 2 * tanf(D3DX_PI/8) * fNear;	float nearW = nearH * fAspect;	float farH = 2 * tanf(D3DX_PI/8) * fFar;	float farW = farH * fAspect;	float nearX = nearW / 2;	float nearY = nearH / 2;	float farX = farW / 2;	float farY = farH / 2;	D3DXVECTOR3 frustumCoordsVS[8];	frustumCoordsVS[0] = D3DXVECTOR3(-nearX,  nearY,  fNear);	frustumCoordsVS[1] = D3DXVECTOR3( nearX,  nearY,  fNear);	frustumCoordsVS[2] = D3DXVECTOR3( nearX, -nearY,  fNear);	frustumCoordsVS[3] = D3DXVECTOR3(-nearX, -nearY,  fNear);	frustumCoordsVS[4] = D3DXVECTOR3(-farX,  farY,  fFar);	frustumCoordsVS[5] = D3DXVECTOR3( farX,  farY,  fFar);	frustumCoordsVS[6] = D3DXVECTOR3( farX, -farY,  fFar);	frustumCoordsVS[7] = D3DXVECTOR3(-farX, -farY,  fFar);	D3DXMATRIX worldMatrix;	D3DXMatrixInverse(&worldMatrix, NULL, &viewMatrix);	D3DXVec3TransformCoordArray(pPoints, sizeof(D3DXVECTOR3), frustumCoordsVS, sizeof(D3DXVECTOR3), &worldMatrix, 8);  // calculate center of points  D3DXVECTOR3 vCenter(0,0,0);  for(int i=0;i<8;i++) vCenter+=pPoints;  vCenter/=8;


Then calculate light ortho projection matrix.
 D3DXVECTOR3 vTransformed[8];	  D3DXVec3TransformCoordArray(vTransformed, sizeof(D3DXVECTOR3), frustumCoordsVS, sizeof(D3DXVECTOR3), &lightViewMatrix, 8);	  D3DXVECTOR3 mins, maxes;	mins = vTransformed[0];	maxes = vTransformed[1];	UINT minIndices[3] = {0, 0, 0};	UINT maxIndices[3] = {1, 1, 1};	for(int i=0 ; i<8 ; i++)	{		if(vTransformed.x < mins.x)		{			mins.x = vTransformed.x;		}		else if(vTransformed.x > maxes.x)		{			maxes.x = vTransformed.x;					        }		if(vTransformed.y < mins.y)		{			mins.y = vTransformed.y;					}		else if(vTransformed.y > maxes.y)		{			maxes.y = vTransformed.y;					}		if(vTransformed.z < mins.z)		{			mins.z = vTransformed.z;					}		else if(vTransformed.z > maxes.z)		{			maxes.z = vTransformed.z;					}	}	float farZ1  = maxes.z;	float nearZ1 = mins.z / 2;	float width  = maxes.x - mins.x;	float height = maxes.y - mins.y;	D3DXMatrixOrthoLH(&lightProjectionMatrix, width, height, nearZ1, farZ1);


Also used the code given in the PSSM sample to calculate perspective projection of light but exactly same results. Please help have spent last 2 nights figuring out whats the prob..
Thanks
ayush3017
ayush3017
I added 1000 to width and height and all the problems disappeared. But this is not optimal solution. :)

Edit:
I changed my code and used bounding sphere and problem solved although it is occupying somewhat larger area but its ok...

[Edited by - ayush3017 on September 10, 2010 2:21:58 PM]

Topic Locked

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

Sign in to reply to this topic.