reckfellENGINE

Gradient

Color points sampled with Linear, Constant or Cubic interpolation.

On this page
class GradientReckfellSharpInherits Resource

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
# Gradient
C#
public Gradient();

Creates two points: opaque black at 0 and white at 1, with Linear and Srgb interpolation.

Properties4

ColorsProperty
# Colors
C#
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
# InterpolationColorSpace
C#
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
# InterpolationMode
C#
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
# Offsets
C#
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
# AddPoint
C#
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.

Parameters
NameTypeDefault
offsetfloat—
colorColor—
offset

A finite position, normally 0…1; it is not automatically clamped.

color

The point color. Account for the destination texture format when using extended-range interpolation.

GetColorColor
# GetColor
C#
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.

Parameters
NameTypeDefault
pointint—
point

An existing point index; sorting can change point order.

Returns Color

The existing point color after sorting.

GetColorsColor[]
# GetColors
C#
public Color[] GetColors();

Returns the value of Gradient.Colors.

Returns Color[]

The current Gradient.Colors value; array copies are not linked to the resource.

GetInterpolationColorSpaceGradient.ColorSpace
# GetInterpolationColorSpace
C#
public Gradient.ColorSpace GetInterpolationColorSpace();

Returns the value of Gradient.InterpolationColorSpace.

Returns Gradient.ColorSpace

The current Gradient.InterpolationColorSpace value.

GetInterpolationModeGradient.InterpolationModeEnum
# GetInterpolationMode
C#
public Gradient.InterpolationModeEnum GetInterpolationMode();

Returns the value of Gradient.InterpolationMode.

Returns Gradient.InterpolationModeEnum

The current Gradient.InterpolationMode value.

GetOffsetfloat
# GetOffset
C#
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.

Parameters
NameTypeDefault
pointint—
point

An existing point index; sorting can change point order.

Returns float

The existing point position after sorting.

GetOffsetsfloat[]
# GetOffsets
C#
public float[] GetOffsets();

Returns the value of Gradient.Offsets.

Returns float[]

The current Gradient.Offsets value; array copies are not linked to the resource.

GetPointCountint
# GetPointCount
C#
public int GetPointCount();

Returns the current position/color pair count, including zero after assigning an empty array. Reading the count does not trigger sorting.

Returns int

The current point count; initially 2.

RemovePointvoid
# RemovePoint
C#
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.

Parameters
NameTypeDefault
pointint—
point

An existing point index; sorting can change point order.

Reversevoid
# Reverse
C#
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
# Sample
C#
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.

Parameters
NameTypeDefault
offsetfloat—
offset

A finite position, normally 0…1; it is not automatically clamped.

Returns Color

The sampled color; components are not guaranteed to stay in 0…1.

SetColorvoid
# SetColor
C#
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.

Parameters
NameTypeDefault
pointint—
colorColor—
point

An existing point index; sorting can change point order.

color

The point color. Account for the destination texture format when using extended-range interpolation.

SetColors2 overloads
# SetColors · 1/2
C#
public void SetColors(Color[] colors);

Assigns the value of Gradient.Colors.

Parameters
NameTypeDefault
colorsColor[]—
colors

The complete color array: its length becomes the point count. Prepare matching Offsets.

# SetColors · 2/2
C#
public void SetColors(ReadOnlySpan<Color> colors);

Assigns the value of Gradient.Colors.

Parameters
NameTypeDefault
colorsReadOnlySpan<Color>—
colors

The complete color array: its length becomes the point count. Prepare matching Offsets.

SetInterpolationColorSpacevoid
# SetInterpolationColorSpace
C#
public void SetInterpolationColorSpace(Gradient.ColorSpace interpolationColorSpace);

Assigns the value of Gradient.InterpolationColorSpace.

Parameters
NameTypeDefault
interpolationColorSpaceGradient.ColorSpace—
interpolationColorSpace

Srgb, LinearSrgb or Oklab; Constant does not use the conversion.

SetInterpolationModevoid
# SetInterpolationMode
C#
public void SetInterpolationMode(Gradient.InterpolationModeEnum interpolationMode);

Assigns the value of Gradient.InterpolationMode.

Parameters
NameTypeDefault
interpolationModeGradient.InterpolationModeEnum—
interpolationMode

Linear, Constant or Cubic; Cubic can exceed the 0…1 component range.

SetOffsetvoid
# SetOffset
C#
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.

Parameters
NameTypeDefault
pointint—
offsetfloat—
point

An existing point index; sorting can change point order.

offset

A finite position, normally 0…1; it is not automatically clamped.

SetOffsets2 overloads
# SetOffsets · 1/2
C#
public void SetOffsets(ReadOnlySpan<float> offsets);

Assigns the value of Gradient.Offsets.

Parameters
NameTypeDefault
offsetsReadOnlySpan<float>—
offsets

The complete array of finite, unique positions. Its length becomes the point count.

# SetOffsets · 2/2
C#
public void SetOffsets(float[] offsets);

Assigns the value of Gradient.Offsets.

Parameters
NameTypeDefault
offsetsfloat[]—
offsets

The complete array of finite, unique positions. Its length becomes the point count.

Gradient.ColorSpace

ValueDescription
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

ValueDescription
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.

Reckfell Engine documentationBack to top ↑
QUICK LINKSGetting startedEntity hierarchyC# & .NET 10Scenes and prefabs
Reckfell guides and full API K
reckfellENGINE
RECKFELL ACCOUNT

Sign in

Sign in to your Reckfell account.

One account for the entire Reckfell platform.