public void PrepareProjection(SceneNode root, PerspectiveCameraNode cam, int shadowMapIdx) { Matrix4 proj = GetSliceFrustumProjection(shadowMapIdx, cam); Vector4 shadowOffsetAndScale = _shadowCascades[shadowMapIdx].PrepareProjection(root, proj, cam, this); _shadowParameters.SetShadowOffsetAndScale(shadowMapIdx, shadowOffsetAndScale); }
private Matrix4 GetSliceFrustumProjection(int shadowMapIdx, PerspectiveCameraNode cam) { float nearPlane = cam.FarPlane - cam.NearPlane; if (shadowMapIdx > 0) { for (int i = _shadowCascades.Count - 1; i > shadowMapIdx - 1; i--) { nearPlane /= 4f; } } else { nearPlane = cam.NearPlane; } float farPlane = cam.FarPlane - cam.NearPlane; for (int i = _shadowCascades.Count - 1; i > shadowMapIdx; i--) { farPlane /= 4f; } return(Matrix4.PerspectiveFovRH(cam.Fov, cam.Aspect, nearPlane, farPlane)); }