ZLab.Discrete ZLab.Discrete
ZLab.Discrete ZLab.Discrete
Developed by Zeke Zhang

Search Results for

    Edit this page

    Method SampleGradient

    | Edit this page View Source

    SampleGradient(DistanceGrid, Vector3, bool)

    Estimates the gradient of the signed distance field at a world-space position using central differences over one voxel step per axis.

    Declaration
    public static Vector3 SampleGradient(this DistanceGrid grid, Vector3 worldPos, bool clampToBounds = true)
    Parameters
    Type Name Description
    DistanceGrid grid

    Distance grid to sample

    Vector3 worldPos

    Query position in world space.

    bool clampToBounds

    If true, samples outside the grid are clamped to the outermost valid cell; if false, an ArgumentOutOfRangeException is thrown when sampling out of bounds.

    Returns
    Type Description
    Vector3

    Gradient vector in world units (X,Y,Z). For a true SDF, normalizing this vector yields the surface normal at worldPos.

    Remarks

    Uses trilinear samples per axis. Degenerate axes (dimension = 1) produce zero derivative on that axis. Result quality depends on grid resolution and SDF accuracy (it is an approximation of the mesh normal).