# problems implementing parallel split shadow mapping

This topic is 3865 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

i want to implement parallel split shadow mapping as shown in this demo: http://hax.fi/asko/PSSM.html. i understand the theory and i already have ssm working. for pssm, i have to split the frustum in smaller parts and then zoom in the projection matrix. for this i need to compute the eight vertices of the current frustum split. i actually just copied the code from the demo:
void CalculateFrustumCorners(Vector3D pPoints[8], Vector3D vPos, Vector3D vView, Vector3D vUp, float fNear, float fFar, float fScale, float fFOV, float fAspect)
{
Vector3D vZ= vView-vPos;
vZ.Normalize();

Vector3D vX = CrossProduct( vUp, vZ );
vX.Normalize();

Vector3D vY = CrossProduct( vZ, vX );

#define PI (float)3.1415
#define GET_RADIANS(degree) (float)(degree / 180.0f * PI)

float fNearPlaneHeight = tanf(GET_RADIANS(fFOV) * 0.5f) * fNear;
float fNearPlaneWidth = fNearPlaneHeight * fAspect;

float fFarPlaneHeight = tanf(GET_RADIANS(fFOV) * 0.5f) * fFar;
float fFarPlaneWidth = fFarPlaneHeight * fAspect;

Vector3D vNearPlaneCenter = vPos + (vZ *= fNear);
Vector3D vFarPlaneCenter = vPos + (vZ *= fFar);

pPoints[0] = Vector3D(vNearPlaneCenter - (vX*=fNearPlaneWidth) - (vY*=fNearPlaneHeight));
pPoints[1] = Vector3D(vNearPlaneCenter - (vX*=fNearPlaneWidth) + (vY*=fNearPlaneHeight));
pPoints[2] = Vector3D(vNearPlaneCenter + (vX*=fNearPlaneWidth) + (vY*=fNearPlaneHeight));
pPoints[3] = Vector3D(vNearPlaneCenter + (vX*=fNearPlaneWidth) - (vY*=fNearPlaneHeight));

pPoints[4] = Vector3D(vFarPlaneCenter - (vX*=fFarPlaneWidth) - (vY*=fFarPlaneHeight));
pPoints[5] = Vector3D(vFarPlaneCenter - (vX*=fFarPlaneWidth) + (vY*=fFarPlaneHeight));
pPoints[6] = Vector3D(vFarPlaneCenter + (vX*=fFarPlaneWidth) + (vY*=fFarPlaneHeight));
pPoints[7] = Vector3D(vFarPlaneCenter + (vX*=fFarPlaneWidth) - (vY*=fFarPlaneHeight));

Vector3D vCenter(0.0f, 0.0f, 0.0f);
for(int i = 0; i < 8; i++)
vCenter = vCenter + pPoints;

vCenter /= 8.0f;

for(int i = 0; i < 8; i++)
pPoints = pPoints + ((pPoints-vCenter)*=(fScale-1.0f));
}

i tried using this function with the following dummy parameters:
Vector3D pFrustum[8];
CalculateFrustumCorners( pFrustum, Vector3D(0, 0, 0), Vector3D(0, 1, 0), Vector3D(0, 0, -1), 10, 100, 1, 45, 1 );

the output is:
-4.14 10.00 4.14
-17.16 10.00 -17.16
71.06 10.00 -71.06
294.33 10.00 294.33
-12191.32 1000.00 12191.32
-504964.34 1000.00 -504964.34
20915624.00 1000.00 -20915624.00
866325184.00 1000.00 866325184.00

the first four vertices look ok, but what's wrong with the others? any idea what i'm doing wrong? thanks!

##### Share on other sites
For a symmetric frustum (aspect = 1.0) with its apex at the origin, pointing to the positive y-axis, i would expect the x, z values to be symmetric around the origin, for all points. E.g. the 4 points of the near plane should look like this:

-a near  a-a near -a a near -a a near  a

where 'a' is a positive value (the order of the vertices may be different).

Try substituting all '*=' in the calculations with '*' and check the results.

HellRaiZer

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 14
• 46
• 22
• 27
• ### Forum Statistics

• Total Topics
634045
• Total Posts
3015218
×