Vixen
02b45cc4
csharp
public sealed class SpriteRenderFeature

Draws sprites: textured quads in their own plane, cut into nine when they have a border.

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

Remarks

Doc 06 § Geometry and materials, the row that says sprites share the UI batcher. What is shared is the arithmetic and the shape of the answer, not the assembly: the nine pairs of rectangles come from NineSlice in Vixen.Core.Mathematics, which is also what UiGeometryBuilder cuts a panel's background with, and both sides expand a batch of quads into one buffer and draw it in one call. They cannot share code beyond that, because Vixen.Ui describes a frame without a device and this describes a device without an element tree.

Local space, and that is the whole difference from the particle feature. A sprite's quads are built around its pivot with no camera in them, so the geometry is the same for every view that draws it — one expansion a frame rather than one a view — and where the sprite is comes from TransformRenderFeature pushing a matrix, the same way a mesh's does. A camera-facing sprite is therefore not this feature's job: that is a billboard, it has to be built against a view, and asking one object to answer "where am I" twice is how a shadow pass ends up drawing a different scene from the camera.

⚠ Rebuilt every frame, including the sprites that did not move. A still sprite has the same nine quads it had last frame and this writes them again — which is the cost the particle feature pays for a reason that does not apply here, and it is a deliberate holdover rather than an oversight: caching needs a version per object and an invalidation on every field of SpriteAppearance, and the write is thirty-six vertices. What would make it worth doing is a scene of tens of thousands of static sprites — a tile map — which is the case that wants one batched mesh rather than one object each anyway.

Fields and properties (10)

  • public override string Name

    The feature's name, for logging and profiling.

  • public RenderDataKey<SpriteDraw> Draws

    Where each sprite's run is. One entry per object.

  • public RenderDataKey<int> SpriteIndices

    Each object's sprite, as one more than its index in Known. Zero for none.

  • public RenderDataKey<SpriteAppearance> Appearances

    How each object's sprite is drawn.

  • public IReadOnlyList<Sprite> Known

    The distinct sprites this feature has been given.

  • public IGraphicsDevice? Device

    The device the buffers live on. Set before the first frame that draws.

  • public PipelineCache? Pipelines

    Where pipelines come from. Set before the first frame that draws.

  • public IPipelineDescriber? Describer

    How a pipeline is described for a given effect, stage and output.

  • public int VertexLayout

    Which vertex layout SpriteVertex is, as an index into the describer's table.

  • public int LastQuadCount

    How many quads the last frame expanded, across every sprite.

Methods (8)

Used by (2)

  • HarnessVixen.Rendering.Tests
  • SpriteRenderFeatureTestsVixen.Rendering.Tests