Jump to content

View more

Image of the Day

WIP title screen for #DeathOfAPartisan #screenshotsaturday #gamedev https://t.co/qJNhfZCvd4
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

Cascade Stability

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 REF_Cracker   Members   


Posted 17 January 2012 - 12:16 AM

Hey all,

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,

Check out my project @ www.exitearth.com

#2 REF_Cracker   Members   


Posted 17 January 2012 - 02:58 AM


There is a way to calculate the proper scale and offset directly form your cascade shadow viewproj matricies. It's right in the article but wasn't working due to a bug in my matrix inversion code.

The way to get the scale remains

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

The offset is calculated as

float4 offset[n] = float4(0.0f,0.0f,0.0f,1.0f) * Inverse(

ShadowMat[n]) *


Check out my project @ www.exitearth.com

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.