Gradient
Color points sampled with Linear, Constant or Cubic interpolation.
Gradient stores position/color pairs, not texture pixels. Defaults are opaque black at 0 and white at 1, with Linear and Srgb interpolation. Sample returns a color at a position; outside the endpoints it retains the nearest endpoint color. An empty point array samples opaque black.
Indices are not stable identifiers: Sample, GetColor and GetOffset can sort points. Assign matching Colors and Offsets lengths because each setter resizes the point count. Returned arrays are copies; editing them does not change the resource. Use finite, unique positions.
LinearSrgb and Oklab convert RGB for interpolation and back to sRGB; Constant uses the point color directly. Cubic can produce values above 1 or below 0. Account for UseHdr when sending results to a gradient texture: RGBA8 clamps range, while RGBAF retains extended values.
Sampling, modes, color spaces, sorting, arrays and connected texture updates were checked in the current Runtime. Duplicate positions, NaN/Infinity and invalid indices were not accepted as tested input.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
GradientConstructor
public Gradient();Creates two points: opaque black at 0 and white at 1, with Linear and Srgb interpolation.
Properties4
ColorsProperty
public Color[] Colors { get; set; }Colors of the current points. Reading returns an independent Color[] without forcing point sorting. Editing that copy does not change the resource. Assigning an array resizes the point count to its length and can discard existing points. Prepare matching Colors and Offsets lengths; assignment is not a partial update.
InterpolationColorSpaceProperty
public Gradient.ColorSpace InterpolationColorSpace { get; set; }Interpolation space: Srgb by default, LinearSrgb or Oklab. The latter two transform RGB for interpolation and convert the result back to sRGB; alpha is interpolated separately. Constant returns the point color without that conversion. This is not a texture HDR flag.
InterpolationModeProperty
public Gradient.InterpolationModeEnum InterpolationMode { get; set; }Sampling between points: Linear by default, Constant holds the left color until the next point, and Cubic uses neighboring points and can exceed the 0…1 component range. At an exact point position, Sample returns that point color. This is not texture antialiasing or sampler filtering.
OffsetsProperty
public float[] Offsets { get; set; }Point positions. Reading returns an independent float[] in current internal order without forcing sorting. Assignment resizes the point count to the array length and schedules sorting for a later point operation. Normally use finite, unique positions in 0…1; the setter does not clamp them to that range.
Methods19
AddPointvoid
public void AddPoint(float offset, Color color);Adds a position/color pair, increases the point count and marks the order unsorted. Sample, GetColor/GetOffset and SetColor/SetOffset perform sorting. Track a point’s meaning separately because its index can change after sorting.
| Name | Type | Default |
|---|---|---|
offset | float | — |
color | Color | — |
offsetA finite position, normally 0…1; it is not automatically clamped.
colorThe point color. Account for the destination texture format when using extended-range interpolation.
GetColorColor
public Color GetColor(int point);Sorts points by position, then returns the indexed color. The index must exist; an invalid index is not a way to sample outside the gradient.
| Name | Type | Default |
|---|---|---|
point | int | — |
pointAn existing point index; sorting can change point order.
ColorThe existing point color after sorting.
GetColorsColor[]
public Color[] GetColors();Returns the value of Gradient.Colors.
GetInterpolationColorSpaceGradient.ColorSpace
public Gradient.ColorSpace GetInterpolationColorSpace();Returns the value of Gradient.InterpolationColorSpace.
GetInterpolationModeGradient.InterpolationModeEnum
public Gradient.InterpolationModeEnum GetInterpolationMode();Returns the value of Gradient.InterpolationMode.
GetOffsetfloat
public float GetOffset(int point);Sorts points by position, then returns the indexed position. This read can change the internal order exposed by Colors and Offsets.
| Name | Type | Default |
|---|---|---|
point | int | — |
pointAn existing point index; sorting can change point order.
floatThe existing point position after sorting.
GetOffsetsfloat[]
public float[] GetOffsets();Returns the value of Gradient.Offsets.
GetPointCountint
public int GetPointCount();Returns the current position/color pair count, including zero after assigning an empty array. Reading the count does not trigger sorting.
intThe current point count; initially 2.
RemovePointvoid
public void RemovePoint(int point);Removes an existing index in the current order without first sorting. This method cannot remove the last remaining point. Assign an empty Offsets or Colors array to clear all points. Do not reuse an index after operations that change the order.
| Name | Type | Default |
|---|---|---|
point | int | — |
pointAn existing point index; sorting can change point order.
Reversevoid
public void Reverse();Replaces each position with 1 − offset, retains its color and sorts the result. It does not clamp original positions to 0…1: −0.5 becomes 1.5.
SampleColor
public Color Sample(float offset);Returns the color at a finite position using the selected interpolation mode and space, sorting points if needed. Before the first or after the last point it returns the endpoint color. An empty gradient returns opaque black; one point returns its color. Cubic can exceed 0…1; avoid duplicate positions, NaN and Infinity.
| Name | Type | Default |
|---|---|---|
offset | float | — |
offsetA finite position, normally 0…1; it is not automatically clamped.
ColorThe sampled color; components are not guaranteed to stay in 0…1.
SetColorvoid
public void SetColor(int point, Color color);Sorts points, replaces the color at an existing index and emits the resource change notification. A connected gradient texture queues pixel regeneration.
| Name | Type | Default |
|---|---|---|
point | int | — |
color | Color | — |
pointAn existing point index; sorting can change point order.
colorThe point color. Account for the destination texture format when using extended-range interpolation.
SetColors2 overloads
public void SetColors(Color[] colors);Assigns the value of Gradient.Colors.
| Name | Type | Default |
|---|---|---|
colors | Color[] | — |
colorsThe complete color array: its length becomes the point count. Prepare matching Offsets.
public void SetColors(ReadOnlySpan<Color> colors);Assigns the value of Gradient.Colors.
| Name | Type | Default |
|---|---|---|
colors | ReadOnlySpan<Color> | — |
colorsThe complete color array: its length becomes the point count. Prepare matching Offsets.
SetInterpolationColorSpacevoid
public void SetInterpolationColorSpace(Gradient.ColorSpace interpolationColorSpace);Assigns the value of Gradient.InterpolationColorSpace.
| Name | Type | Default |
|---|---|---|
interpolationColorSpace | Gradient.ColorSpace | — |
interpolationColorSpaceSrgb, LinearSrgb or Oklab; Constant does not use the conversion.
SetInterpolationModevoid
public void SetInterpolationMode(Gradient.InterpolationModeEnum interpolationMode);Assigns the value of Gradient.InterpolationMode.
| Name | Type | Default |
|---|---|---|
interpolationMode | Gradient.InterpolationModeEnum | — |
interpolationModeLinear, Constant or Cubic; Cubic can exceed the 0…1 component range.
SetOffsetvoid
public void SetOffset(int point, float offset);Sorts points, changes the position at an existing index and marks the order unsorted again. The position is not clamped to 0…1. This point can have a different index after the next sort.
| Name | Type | Default |
|---|---|---|
point | int | — |
offset | float | — |
pointAn existing point index; sorting can change point order.
offsetA finite position, normally 0…1; it is not automatically clamped.
SetOffsets2 overloads
public void SetOffsets(ReadOnlySpan<float> offsets);Assigns the value of Gradient.Offsets.
| Name | Type | Default |
|---|---|---|
offsets | ReadOnlySpan<float> | — |
offsetsThe complete array of finite, unique positions. Its length becomes the point count.
public void SetOffsets(float[] offsets);Assigns the value of Gradient.Offsets.
| Name | Type | Default |
|---|---|---|
offsets | float[] | — |
offsetsThe complete array of finite, unique positions. Its length becomes the point count.
Gradient.ColorSpace
| Value | Description |
|---|---|
LinearSrgb = 1 | Linear sRGB color space. |
Oklab = 2 | Oklab(https://bottosson.github.io/posts/oklab/) color space. This color space provides a smooth and uniform-looking transition between colors. |
Srgb = 0 | sRGB color space. |
Gradient.InterpolationModeEnum
| Value | Description |
|---|---|
Constant = 1 | Constant interpolation, color changes abruptly at each point and stays uniform between. This might cause visible aliasing when used for a gradient texture in some cases. |
Cubic = 2 | Cubic interpolation. |
Linear = 0 | Linear interpolation. |