public static class ShadowCascadesWhere cascades are split, and how each one is fitted to the camera.
No guide page documents this yet — the page shows what the code says about itself.
Remarks
Pure arithmetic with no device and no state, which is the point: cascaded shadow maps go wrong in two specific, famous ways, and both are properties of these functions alone. That makes them assertable without rendering anything.
Shimmering when the camera turns is fixed by Fit bounding a sphere rather than the eight frustum corners. A corner fit produces an extent that depends on the camera's orientation, so rotating on the spot changes the cascade's size, which changes the texel grid, which makes every shadow edge crawl. A sphere's radius depends only on the split distances and the field of view.
Shimmering when the camera moves is fixed by snapping the fitted centre to whole texels of the shadow map. Without it, sub-texel translation slides the sampling grid under static geometry and the same fixed edge flickers between two texel rows.
Fields and properties (1)
public const int MaxCascadesThe most cascades one call will produce.
Methods (9)
public static void Split(float near, float far, float lambda, Span<float> distances)Splits [near, far] into cascade boundaries.
public static (Vector3 Centre, float Radius) Sphere(Vector3 eye, Vector3 forward, float fieldOfView, float aspectRatio, float near, float far)The bounding sphere of one slice of the camera's frustum.
public static bool Covers(in ShadowCascade cascade, Vector3 centre, float radius)Whether a cascade still covers a slice's sphere entirely.
public static ShadowCascade Fit(Vector3 eye, Vector3 forward, Vector3 up, Vector3 lightDirection, float fieldOfView, float aspectRatio, float near, float far, int resolution, float extrusion = 50, float slack = 0)Fits one cascade to a slice of the camera's frustum and returns its light transform.
public static (Vector2 Scale, Vector2 Offset) AtlasTile(int index, int count)The scale and offset that map a cascade's clip-space XY into its tile of an atlas.
public static int CascadeOf(float viewDepth, ReadOnlySpan<float> splits)Which cascade shades a fragment at this distance.
public static Matrix4x4 AtlasProjection(in ShadowCascade cascade, int index, int count)A cascade's matrix, projecting straight into its tile of the atlas.
public static Viewport TileViewport(int index, int count, int resolution)Where an atlas tile sits, in texels.
public static Int2 AtlasSize(int count, int resolution)How big an atlas holding tiles has to be, in texels.
Used by (4)
- ShadowAtlasTileDeviceTestsVixen.Graphics.Golden.Tests
- ShadowCacheTestsVixen.Rendering.Tests
- ShadowCascadeTestsVixen.Rendering.Tests
- ShadowMapRendererVixen.Rendering