public sealed class TerrainWeightsThe paint channels of a terrain, and the invariant that keeps them meaning something.
Remarks
[docs/plan/31 § D5]. Weight-blended layers at a sample sum to one — stored as Byte summing to 255 — and painting one raises it while lowering the others proportionally. Proportionally rather than uniformly is Unreal's rule and it is the only one that does not produce a layer which can never be removed: subtracting the same amount from every other layer drives the small ones to zero first and then has nowhere left to take from, so the layer being painted stops being able to reach one.
Four channels per weightmap on the device, but not here. A layer is added and removed on its own, so it gets its own array; the packing into RGBA textures is the renderer's, and it is why the layer count is what the generated material permutes on.
⚠ The invariant is asserted with the offending layer named. A weight-sum drift is a rounding bug that presents as a barely-visible tint and is otherwise unattributable — the terrain looks very slightly wrong and nothing says where. Verify is the gate, and it reports which layer is carrying the excess.
Fields and properties (7)
public const int TotalWhat the weight-blended layers sum to at every sample.
public TerrainDescription DescriptionThe terrain's shape.
public int LayerCountHow many paint layers there are.
public IReadOnlyList<string> NamesWhat each layer is called, in order.
public IReadOnlyList<TerrainLayerDescription> LayersWhat ground each layer is, in order — the .vxlayer each one names.
public int WeightmapCountHow many weightmap textures the device needs, at four channels each.
public int MaterialLayerSlotsWhich layer-count permutation the generated material compiles for.
Methods (19)
public TerrainWeights(TerrainDescription description)Creates the paint channels of a terrain, with no layers in them.
public int AddLayer(string name, TerrainBlend blend = Weight)Adds a paint layer.
public int AddLayer(TerrainLayerDescription layer, TerrainBlend blend = Weight)Adds a paint layer with the ground it paints.
public void RemoveLayer(int layer)Removes a paint layer, redistributing what it held.
public byte WeightAt(int layer, int x, int z)How much of a layer covers a sample, 0…Total.
public float FractionAt(int layer, int x, int z)How much of a layer covers a sample, as a fraction.
public void Paint(int layer, int x, int z, int amount)Paints a layer at a sample, taking the difference from the other weight-blended layers.
public void SetWeight(int layer, int x, int z, byte weight)Sets a layer's weight at a sample, taking the difference from the others.
public int SumAt(int x, int z)The sum of the weight-blended layers at a sample.
public string? Verify()Checks the sum-to-one invariant everywhere, and says which layer broke it.
public ReadOnlySpan<byte> ChannelOf(int layer)A layer's raw channel, for a renderer packing it into a texture.
public TerrainBlend BlendOf(int layer)How a layer combines with the ones beside it.
public TerrainLayerDescription LayerOf(int layer)What ground a layer paints.
public void SetLayer(int layer, TerrainLayerDescription description)Changes what ground a layer paints, keeping everything painted with it.
public float CoverageOf(int layer)How much of the terrain a layer covers, as a fraction of its samples.
public int DominantAt(int x, int z)Which layer covers a sample most, which is what the ground under a foot is.
public int FillCollisionMaterials(int tileX, int tileZ, Span<sbyte> destination)Fills a tile's per-quad ground materials, so a footstep knows what it is standing on.
public TerrainLayerDescription? GroundAt(int x, int z)What ground a quad is, as the layer that claims it.
public void Restore(int x, int z, ReadOnlySpan<byte> weights)Puts a whole sample's weights back, exactly as they were.
Used by (30)
- TerrainVixen.Terrain
- TerrainPaintVixen.Terrain
- TerrainPaintTestsVixen.Terrain.Tests
- TerrainRendererVixen.Rendering.Terrain
- TerrainRendererTestsVixen.Rendering.Terrain.Tests
- TerrainResizeVixen.Terrain
- TerrainResizeTestsVixen.Terrain.Tests
- TerrainSculptVixen.Terrain
- TerrainSplatVixen.Rendering.Terrain
- TerrainSplatTestsVixen.Rendering.Terrain.Tests
- TerrainSplineVixen.Terrain
- TerrainSplineTestsVixen.Terrain.Tests
- TerrainStoreVixen.Terrain
- TerrainStoreTestsVixen.Terrain.Tests
- TerrainSurfaceVixen.Rendering.Terrain
- TerrainSurfaceTestsVixen.Rendering.Terrain.Tests
- TerrainWeightRedoVixen.Terrain
- TerrainWeightStrokeVixen.Terrain
- TerrainWeightTestsVixen.Terrain.Tests
- TerrainWeightmapVixen.Terrain
- TerrainWeightmapTestsVixen.Terrain.Tests
- AssignTargetCommandVixen.Editor.Terrain
- SculptSessionTestsVixen.Editor.Terrain.Tests
- TargetLayerCommandVixen.Editor.Terrain
- TerrainEditVixen.Editor.Terrain
- TerrainLayerCommandsVixen.Editor.Terrain
- TerrainLayerSettingsVixen.Editor.Terrain
- TerrainModeVixen.Editor.Terrain
- TerrainModeTestsVixen.Editor.Terrain.Tests
- TerrainPaintModeTestsVixen.Editor.Terrain.Tests