Vixen
02b45cc4
csharp
public sealed class ImpostorBake

Rendering a mesh once from every direction of an ImpostorGrid into one atlas.

Read the guide page for this →

Remarks

[docs/plan/31 § T7]'s owed item. ImpostorGrid, ImpostorAtlas and ImpostorView are the arithmetic — the fold, the layout and the per-cell camera — and this is the pass that uses them. It owns the atlas textures and the depth target, and it records one render pass with a viewport per cell.

⚠ One render pass for the whole atlas, not one per cell. A 9×9 grid is eighty-one cells; a pass each would clear and store a 1152-texel target eighty-one times, which on a tiler is eighty-one full-frame resolves to bake one tree. The clear happens once and the viewport moves.

⚠ It does not know what a mesh is, and that is the seam. The caller draws — it owns the pipeline, the vertex and index buffers and the material — and what this supplies is the camera and the rectangle. A baker that bound a mesh would need an asset database in a class whose job is a render pass.

⚠ The draw rectangle is inset by the padding, and the gutter is left for the dilation to fill. A bake that used the whole cell would put the silhouette's edge texels against the neighbouring cell's, and a bilinear tap at four hundred metres reaches across — which is a tree wearing a stripe of the tree next to it.

⚠ Depth is cleared to zero, which is far. The engine's convention is reversed-Z; clearing to one here is the classic mistake and produces an atlas that depth tests away entirely — eighty-one blank cells and no error anywhere.

Fields and properties (5)

  • public ImpostorAtlas Atlas

    The layout this bake fills.

  • public TextureViewHandle Albedo

    The albedo atlas, for the material that draws the impostor.

  • public TextureViewHandle Normals

    And the normals.

  • public int CellsBaked

    How many cells the last Record drew.

  • public int Dispatches

    How many dispatches the last Finish recorded.

Methods (7)

  • public ImpostorBake(IGraphicsDevice device, ImpostorAtlas atlas, PixelFormat colourFormat = Rgba8UNorm, PixelFormat normalFormat = Rgba8UNorm, PixelFormat depthFormat = Depth32Float)

    Creates the atlas textures a bake renders into.

  • public Viewport ViewportOf(ImpostorCell cell)

    Where a cell's mesh is drawn, in atlas pixels.

  • public ScissorRect ScissorOf(ImpostorCell cell)

    And the scissor that goes with it, so a draw cannot spill into the gutter.

  • public int Record(ICommandList commands, Vector3 centre, float radius, Action<ICommandList, ImpostorBakeCell> draw)

    Records the whole bake: one render pass, one viewport and one draw per cell.

  • public void Finishing(ShaderHandle dilate, ShaderHandle reduce)

    Gives the bake the shaders that finish an atlas: the dilation and the reduce.

  • public int Finish(ICommandList commands)

    Records the dilation and the whole mip chain, for both atlases.

  • public void Dispose()

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

Used by (3)

  • ImpostorBakeTestsVixen.Rendering.Tests
  • ImpostorCapturePassVixen.Rendering
  • ImpostorCapturePassTestsVixen.Rendering.Tests