zoom in function for pssm

i’m implementing parallel split shadow mapping (http://appsrv.cse.cuhk.edu.hk/~fzhang/pssm_vrcia), and i can’t manage to zoom in to the frustum splits. this code is supposed to compute the bounding extents of the frustum split and to manipulate the projection matrix to zoom in onto the split… Vector3D pFrustum[8] contains the frustum’s vertices (non-transformed):

float fMaxX = -1.0f;
float fMaxY = -1.0f;
float fMinX =  1.0f;
float fMinY =  1.0f;
float fMaxZ =  -1.0f;

for( int i = 0; i < 8; i++ )
{
	Vector4D vTransformed = (m_kProjectionMatrix*m_kInverseViewMatrix)*Vector4D(pFrustum[i], 1.0);

	// We project the x and y values prior to determining the max values
	vTransformed.x /= vTransformed.w;
	vTransformed.y /= vTransformed.w;

	// We find the min and max values for X, Y and Z
	if(vTransformed.x > fMaxX) fMaxX = vTransformed.x;
	if(vTransformed.y > fMaxY) fMaxY = vTransformed.y;
	if(vTransformed.y < fMinY) fMinY = vTransformed.y;
	if(vTransformed.x < fMinX) fMinX = vTransformed.x;
	if(vTransformed.z > fMaxZ) fMaxZ = vTransformed.z;
}

fMaxX = Clamp(fMaxX, -1.0f, 1.0f);
fMaxY = Clamp(fMaxY, -1.0f, 1.0f);
fMinX = Clamp(fMinX, -1.0f, 1.0f);
fMinY = Clamp(fMinY, -1.0f, 1.0f);

// We make an appropriate matrix for zooming in on the current split, just as in the paper
float fScaleX = 2.0f / (fMaxX-fMinX);
float fScaleY = 2.0f / (fMaxY-fMinY);
float fOffsetX = -0.5f * (fMaxX+fMinX) * fScaleX;
float fOffsetY = -0.5f * (fMaxY+fMinY) * fScaleY;

Matrix CropView;
CropView[0][0] = fScaleX;
CropView[1][1] = fScaleY;
CropView[3][0] = fOffsetX;
CropView[3][1] = fOffsetY;

m_kProjectionMatrix = CropView*m_kProjectionMatrix;

does this look okay? if yes, any idea what might be wrong? it only results in a distorted prjection… :frowning: thanks!