DistanceBuffer

Description

sealed class Tinman.Terrain.Buffers.DistanceBuffer

Derived from

SampleBufferFloat32 abstract

A distance buffer stores signed distance values towards the border of a two-dimensional shape (negative is inside).

Distance textures can be used for high-quality rendering of shapes (for example terrain decals). The samples in a distance buffer have a pixel-is-area semantic (see PixelCoverage.PixelIsArea): The sample value is the distance from the center of the sample area towards the nearest point on the shape border.

Public / Constants

Scanline​Range​Default


public static readonly attribute ScanlineRangeDefault → (PixelRange)

The default value of ISampleBuffer.ScanlineRange.

The distance value range is exploited during rasterization: regions that only contain distance values below the minimum bound or above the maximum bound will be skipped.

For image coding, the raw pixel value corresponds to the signed distance value.

The default pixel range maps signed distance values as follows:
-1 : 16777215 (i.e. maximum pixel channel value when inside of shape)
+1 : 0 (i.e. minimum pixel channel value when outside of shape).

Public / Constructors

Distance​Buffer


public constructor DistanceBuffer → (2)

width in : int32

[>0]
The buffer width, in samples.

height in : int32

[>0]
The buffer height, in samples.

Creates a new instance of DistanceBuffer.

Public / Methods

Downsample


public method Downsample → (2)

output opt : DistanceBuffer = null

The output buffer or null. If null a new color buffer of the required minimum size is created.

filter opt : DownsampleFilter = DownsampleFilter.Average

The filter to use for downsampling.

returns → DistanceBuffer

The downsampled color buffer.

Performs downsampling on the samples of this distance buffer.

Each block of 2x2 input samples is downsampled to a single output sample.

+---+---+
| a | b |      +---+
+---+---+  =>  | x |
| c | d |      +---+
+---+---+

If this distance buffer has a width and/or height that is not divisible by two, samples will be duplicated in order to get a full input sample block for downsampling. If the output opt buffer is too small, overhang samples will be discarded. The input and output buffers can be the same.

Encode​Pixels

2 overloads


public method EncodePixels1 → (2)

ramp in : IColorRamp

[not-null]
The color ramp to use for mapping signed distance values to pixel colors.

buffer opt : ColorBuffer = null

The output buffer or null to create a new one.

returns → ColorBuffer

The encoded pixel buffer.

Encodes the signed distances in this buffer into pixels.


public method EncodePixels2 → (3)

ramp in : IColorRamp

[not-null]
The color ramp to use for mapping signed distance values to pixel colors.

buffer in : ColorBuffer

The output buffer or null to create a new one.

colorOp in : ColorOp

The ColorOp to use to combine the samples in buffer in (first) with the encoded pixels (second).

returns → ColorBuffer

buffer in

Encodes the signed distances in this buffer into pixels.

To​Distance


[Pure]
public method ToDistance → (1)

pixel in : int32

The pixel channel value, in the range [0..16777215].

returns → float32

The signed distance.

Converts the given pixel channel value to a signed distance.

See also

Range

To​Pixel


[Pure]
public method ToPixel → (1)

distance in : float32

The signed distance.

returns → int32

The pixel channel value.

Converts the given signed distance into a pixel channel value.

See also

Range