I've got a basic cascaded shadow map up and working but I'm having stability problems. My implementation is closely following the ShaderX6 article by Michal Valient. I was able to achieve perfect stability in the first and closest cascade as described in this post http://www.gamedev.n...ed-shadow-maps/. My problem is that the other 3 further cascades shimmer quite awfully now.

The 4 cascade view projection matricies are calculated as

ShadowMat = LightLookAt * OrthoProjection * RoundingMat

where the rounding mat is as mention in the previous post. (pasted here)

//--------------------------

// xShadowMatrix is the light view projection matrix

D3DXVECTOR3 ptOriginShadow(0,0,0);

D3DXVec3TransformCoord(&ptOriginShadow, &ptOriginShadow, &xShadowMatrix);

// Find nearest shadow map texel. The 0.5f is because x,y are in the

// range -1 .. 1 and we need them in the range 0 .. 1

float texCoordX = ptOriginShadow.x * SHADOW_MAP_SIZE * 0.5f;

float texCoordY = ptOriginShadow.y * SHADOW_MAP_SIZE * 0.5f;

// Round to the nearest 'whole' texel

float texCoordRoundedX = round(texCoordX);

float texCoordRoundedY = round(texCoordY);

// The difference between the rounded and actual tex coordinate is the

// amount by which we need to translate the shadow matrix in order to

// cancel sub-texel movement

float dx = texCoordRoundedX - texCoordX;

float dy = texCoordRoundedY - texCoordY;

// Transform dx, dy back to homogenous light space

dx /= SHADOW_MAP_SIZE * 0.5f;

dy /= SHADOW_MAP_SIZE * 0.5f;

D3DXMATRIX xRounding;

D3DXMatrixTranslation(&xRounding, dx, dy, 0);

//--------------------------

This gives me a perfectly stable result for the first cascade. The remaining 3 cascades are being looked-up in the shadow map atlas via an offset and scale passed to the pixel shader.

float3 offset[n] = ShadowMat[0] * lookat[n].translation

float scale[n] = splitRadius[0] / splitRadius[n]

I'm missing something here and can't figure it out. Seems to me that even though I'm using the properly rounded shadow matrix for each cascade caster rendering, I'm disregarding it in the lookup because I'm scaling and offseting in a fractional pixel way. Is there a way to derive the scale and offset purely from the set of cascade shadow matricies? I'm probably getting it wrong by using the projection of the nth lookat's translation as it's before the rounding adjustment.

Thanks in advance,

ref_cracker