Vixen
02b45cc4
csharp
public sealed class PunctualShadowRenderer

Renders spot and point light shadows into one atlas.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

The same idea as ShadowMapRenderer — a shadow map is a view, and an atlas is one pass with a viewport per tile — applied to lights that have a position. What differs is that nothing has to be fitted or stabilised: a spot light's shadow frustum is its cone and a point light's is six of them, so the whole projection question that cascades spend two hundred lines on does not arise.

A point light is six tiles and a spot light is one. That ratio is the real cost of the two and it is worth seeing: six times the culling, six times the draws, six times the atlas. It is also why the atlas is allocated in tile units rather than per light — the alternative reserves a cube's worth of space for every light in case it turns out to be one.

When the atlas runs out, lights are dropped and counted. Not silently: DroppedLights is what turns "some shadows disappeared in the big fight" into a number a profiler can show. Dropping the ones furthest down the list is arbitrary and deliberate — importance ordering belongs to whoever fills the list, which is the only place that knows what the scene is about.

Fields and properties (20)

  • public required RenderStage CasterStage

    The stage that draws depth-only casters.

  • public string Atlas

    The name of the atlas to render into.

  • public IList<RenderLight> Lights

    The lights to shadow. Directional lights are skipped — they are the cascades'.

  • public ViewConstants? Constants

    The per-view block to bind before each tile's casters.

  • public ParameterCollection? Scene

    Where to publish what a shading pass needs to read the atlas, or null to publish nothing.

  • public string ShaderName

    The compose-slot prefix the tile bindings are written under.

  • public IList<string> Passes

    Any further prefixes the same atlas is published under.

  • public IGraphicsDevice? Device

    Where the tile buffer lives. Without one, nothing is uploaded and nothing published.

  • public SamplerCache? Samplers

    Where the atlas's sampler comes from. Without one, no sampler is published.

  • public float ConstantBias

    How far the depth comparison is nudged, in depth units.

  • public float SlopeBias

    How much more of that a surface gets as it turns away from the light.

  • public int Resolution

    One tile's side in texels.

  • public int TilesPerSide

    How many tiles the atlas is across, so it holds this squared.

  • public float NearPlane

    The near plane every punctual shadow projection uses.

  • public IReadOnlyList<ShadowTile> Tiles

    The tiles this frame allocated.

  • public int TileBase

    Which record of the tile buffer this frame's tiles start at.

  • public IReadOnlyList<RenderView> Views

    The views the tiles are drawn from.

  • public int DroppedLights

    How many lights did not fit in the atlas this frame.

  • public int Capacity

    How many tiles the atlas holds.

  • public Int2 AtlasSize

    The atlas's size in texels, for whoever creates the texture.

Methods (4)

  • protected internal override void Collect(GraphicsCompositor compositor)

    Declares the views and stages this node needs, before anything is culled.

  • protected internal override void Build(GraphicsCompositor compositor, CompositorFrame frame)

    Declares this node's render-graph passes.

  • public void Dispose()

    Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

  • public override string ToString()

    Returns a string that represents the current object.

Used by (3)

  • CompositorBuilderVixen.Rendering
  • HarnessVixen.Rendering.Tests
  • PunctualShadowTestsVixen.Rendering.Tests