• Create Account

### #ActualMJP

Posted 03 December 2012 - 06:52 PM

So say you have a shadow matrix, such that WorldPosition * ShadowMatrix gives you the position that you want in shadow map space. If you have a view-space position, then you could get the same result by doing ViewPosition * InvViewMatrix * ShadowMatrix. The nice thing about matrices is that you can combine two matrix transformations into a single matrix, which means that if you can pre-multiply InvViewMatrix * ShadowMatrix on the CPU and pass that to the GPU. Then in your shader you just do ViewPosition * ViewShadowMatrix and you'll get the result that you want.

EDIT: I made a rough diagram to illustrate what I'm talking about:

The picture shows a top-down view of the view frustum (the green trapezoid), with two shadow cascades (the red rectangles) whose sizes are marked (which are not to scale). Ignoring the Z dimension for a minute, in terms of X and Y the second cascade is 2x the width and height of the first cascade and is located 1 unit to the right and 0.75 units downwards. Using that, you could project using the first cascade matrix and then apply the appropriate offset and scale to get coordinates in terms of the second cascade. I left out the Z coordinate, but it works the same way.

### #2MJP

Posted 30 November 2012 - 01:25 AM

So say you have a shadow matrix, such that WorldPosition * ShadowMatrix gives you the position that you want in shadow map space. If you have a view-space position, then you could get the same result by doing ViewPosition * InvViewMatrix * ShadowMatrix. The nice thing about matrices is that you can combine two matrix transformations into a single matrix, which means that if you can pre-multiply InvViewMatrix * ShadowMatrix on the CPU and pass that to the GPU. Then in your shader you just do ViewPosition * ViewShadowMatrix and you'll get the result that you want.

EDIT: I made a rough diagram to illustrate what I'm talking about: