public sealed class MeshDistanceFieldHow far every point in a box is from a mesh's surface, and which side of it the point is on.
No guide page documents this yet — the page shows what the code says about itself.
Remarks
Negative inside, positive outside, zero on the surface, in world units. That sign convention is the one every published tracing formulation assumes, and getting it backwards is a mesh that repels rays instead of stopping them.
Samples sit on grid points, not in voxel centres. The first sample along an axis is exactly at Bounds' minimum and the last exactly at its maximum, so the field is defined on the whole box rather than on a slightly smaller one inset by half a voxel. Trilinear interpolation between grid points then covers the box with no extrapolation anywhere, which is what makes Sample exact at the corners and continuous everywhere between them.
The field is only as true as it is dense. Between samples it is a trilinear interpolation of distances, and a trilinear interpolation of a distance function is not a distance function: it under-estimates near a concave corner and over-estimates near a convex one. A sphere tracer reading it therefore takes conservative steps rather than exact ones, which is the standard trade and the reason a step scale below one exists at all.
Stored as Single rather than quantised into a narrow band. Correctness first: the exit criterion in docs/plan/19 is agreement with a closed form, and a quantisation would be measured against this rather than instead of it.
Fields and properties (5)
public BoundingBox BoundsThe box the field covers, in the mesh's own space.
public Int3 ResolutionHow many samples along each axis. At least two everywhere.
public float[] DistancesThe samples, Resolution's volume of them, with X varying fastest and Z slowest.
public Vector3 CellSizeThe world-space size of one cell along each axis.
public float this[int x, int y, int z]The signed distance at one grid point.
Methods (7)
public MeshDistanceField(BoundingBox bounds, Int3 resolution, float[] distances)Reconstructs a field from its parts.
public MeshDistanceField()Creates an empty field, for the serializer.
public Vector3 PositionOf(int x, int y, int z)Where one grid point is, in the field's own space.
public Vector3 TextureCoordinate(Vector3 position)Where a point sits in a volume texture holding Distances, as 0..1.
public float Sample(Vector3 position)The signed distance at any point, trilinearly interpolated.
public Vector3 SampleGradient(Vector3 position)Which way the distance grows fastest at a point — the surface normal, near one.
public void Validate()Throws if the field's parts do not describe a field.
Used by (18)
- ArenaThirdPersonShooter
- DistanceFieldAoImageTestsVixen.Graphics.Golden.Tests
- DistanceFieldInstanceVixen.Rendering.DistanceFields
- DistanceFieldInstanceTestsVixen.Rendering.DistanceFields.Tests
- GlobalDistanceFieldVixen.Rendering.DistanceFields
- GlobalDistanceFieldRendererTestsVixen.Rendering.Tests
- GlobalDistanceFieldTestsVixen.Rendering.DistanceFields.Tests
- MeshDistanceFieldBakerVixen.Rendering.DistanceFields
- MeshDistanceFieldBakerTestsVixen.Rendering.DistanceFields.Tests
- MeshDistanceFieldTestsVixen.Rendering.DistanceFields.Tests
- ReflectionTraceDeviceTestsVixen.Graphics.Golden.Tests
- RenderedSceneTestsVixen.Rendering.DistanceFields.Tests
- SamplingConventionTestsVixen.Rendering.DistanceFields.Tests
- ScrollTestsVixen.Rendering.DistanceFields.Tests
- SurfaceCacheRadiosityDeviceTestsVixen.Graphics.Golden.Tests
- Vixen_Rendering_DistanceFields_MeshDistanceFieldSerializerVixen.Rendering.DistanceFields
- ModelImporterVixen.Editor.Assets
- ModelImporterTestsVixen.Editor.Assets.Tests