Vixen
02b45cc4
csharp
public sealed class TerrainRenderer

Draws a terrain: one indexed instanced call over the patches a quadtree chose.

Read the guide page for this →

Remarks

[docs/plan/31 § T2]. The selection and the morph are arithmetic in Vixen.Terrain and are tested without a device; this is the part that needs one — the textures, the records, the descriptor set and the draw.

⚠ An atlas of per-tile blocks, which is the split of the layout the plan asked for without the split of the texture it did not. A tile is the unit of load ([§ D13]); a CDLOD patch straddles a tile boundary except by luck, and a texture per tile would make every straddling patch either two draws or a shader sampling two textures. One texture holding a TileSamples² block per tile is both: one thing to bind, and a block to upload, evict and mip on its own. See TerrainAtlas for why the blocks duplicate their boundary samples rather than sharing them.

⚠ And it is what makes the mip chain legal at all. A 2×2 reduction of the atlas never crosses a block boundary, because every block is a power of two starting at a multiple of one. Reducing the packed grid instead would mix two tiles at every level — [§ D2]'s seam arriving through the mip chain.

Only what changed is re-uploaded. Upload asks the terrain which tiles Resolve dirtied and copies those rows; a stroke on one tile of a hundred moves one hundredth of the bytes. Uploading the whole heightmap per frame would make a 33 MB transfer the cost of moving the brush.

Fields and properties (17)

  • public const int MaxLayers

    The most weight-blended layers a terrain can carry.

  • public const int MaxWeightMaps

    How many weightmap textures that is.

  • public Terrain Terrain

    The terrain being drawn.

  • public TextureViewHandle Holes

    The hole mask, for anything that has to stop where the ground does.

  • public SamplerHandle HoleSampler

    And how it is read — clamped, unfiltered, at level 0.

  • public TerrainStreamer? Streaming

    Which tiles are loaded, or null while every tile always is.

  • public List<StreamingSource> StreamingSources

    Where the world has to be loaded around, in the terrain's own space.

  • public float StreamingRadius

    How far around a source a terrain's fine levels are kept, in metres.

  • public ITerrainTextures? Textures

    What turns a layer's texture reference into something to sample.

  • public int ResolvedTextures

    How many layer textures the last Upload resolved.

  • public TerrainLodTree Tree

    The quadtree the selection descends.

  • public int PatchCount

    How many patches the last Upload chose.

  • public TerrainSplat Splat

    What the generated splat material compiles as, from the terrain's layer list.

  • public int Draws

    How many draws the last Record made.

  • public int Triangles

    How many triangles the last Record submitted.

  • public int Capacity

    How many patch records the buffer can hold.

  • public long UploadedBytes

    How many bytes the last Upload copied into the heightmap.

Methods (4)

  • public TerrainRenderer(IGraphicsDevice device, Terrain terrain, TerrainShaders shaders, RenderOutput output, TerrainLodRanges ranges, int gridQuads = 32)

    Creates a renderer for one terrain.

  • public int Upload(ICommandList commands, in TerrainView view)

    Chooses this frame's patches and stages what the device needs.

  • public void Record(ICommandList commands)

    Draws this frame's patches.

  • public void Dispose()

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

Used by (3)

  • TerrainRendererTestsVixen.Rendering.Terrain.Tests
  • TerrainStreamingTestsVixen.Rendering.Terrain.Tests
  • ScenePresenterVixen.Editor.App