• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

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

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.

### #1REF_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

// 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

// 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

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

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.

ref_cracker

Check out my project @ www.exitearth.com

### #2REF_Cracker  Members

Posted 17 January 2012 - 02:58 AM

Solved:

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

The offset is calculated as

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