Table of Contents

Struct Color3

Namespace
Stride.Core.Mathematics
Assembly
Stride.Core.Mathematics.dll

Represents a color in the form of rgb.

[DataContract("Color3")]
[DataStyle(DataStyle.Compact)]
public struct Color3 : IEquatable<Color3>, IFormattable
Implements

Constructors

Color3(Vector3)

Initializes a new instance of the Color3 struct.

public Color3(Vector3 value)

Parameters

value Vector3

The red, green, and blue components of the color.

Color3(int)

Initializes a new instance of the Color3 struct.

public Color3(int rgb)

Parameters

rgb int

A packed integer containing all three color components. The alpha component is ignored.

Color3(float)

Initializes a new instance of the Color3 struct.

public Color3(float value)

Parameters

value float

The value that will be assigned to all components.

Color3(float, float, float)

Initializes a new instance of the Color3 struct.

public Color3(float red, float green, float blue)

Parameters

red float

The red component of the color.

green float

The green component of the color.

blue float

The blue component of the color.

Color3(float[])

Initializes a new instance of the Color3 struct.

public Color3(float[] values)

Parameters

values float[]

The values to assign to the red, green, and blue components of the color. This must be an array with three elements.

Exceptions

ArgumentNullException

Thrown when values is null.

ArgumentOutOfRangeException

Thrown when values contains more or less than four elements.

Color3(uint)

Initializes a new instance of the Color3 struct.

public Color3(uint rgb)

Parameters

rgb uint

A packed unsigned integer containing all three color components. The alpha component is ignored.

Fields

B

The blue component of the color.

[DataMember(2)]
public float B

Field Value

float

G

The green component of the color.

[DataMember(1)]
public float G

Field Value

float

R

The red component of the color.

[DataMember(0)]
public float R

Field Value

float

Properties

this[int]

Gets or sets the component at the specified index.

public float this[int index] { get; set; }

Parameters

index int

The index of the component to access. Use 0 for the red component, 1 for the green component, and 2 for the blue component.

Property Value

float

The value of the red, green, or blue component, depending on the index.

Exceptions

ArgumentOutOfRangeException

Thrown when the index is out of the range [0, 2].

Methods

Add(Color3, Color3)

Adds two colors.

public static Color3 Add(Color3 left, Color3 right)

Parameters

left Color3

The first color to add.

right Color3

The second color to add.

Returns

Color3

The sum of the two colors.

Add(ref readonly Color3, ref readonly Color3, out Color3)

Adds two colors.

public static void Add(ref readonly Color3 left, ref readonly Color3 right, out Color3 result)

Parameters

left Color3

The first color to add.

right Color3

The second color to add.

result Color3

When the method completes, completes the sum of the two colors.

AdjustContrast(Color3, float)

Adjusts the contrast of a color.

public static Color3 AdjustContrast(Color3 value, float contrast)

Parameters

value Color3

The color whose contrast is to be adjusted.

contrast float

The amount by which to adjust the contrast.

Returns

Color3

The adjusted color.

AdjustContrast(ref readonly Color3, float, out Color3)

Adjusts the contrast of a color.

public static void AdjustContrast(ref readonly Color3 value, float contrast, out Color3 result)

Parameters

value Color3

The color whose contrast is to be adjusted.

contrast float

The amount by which to adjust the contrast.

result Color3

When the method completes, contains the adjusted color.

AdjustSaturation(Color3, float)

Adjusts the saturation of a color.

public static Color3 AdjustSaturation(Color3 value, float saturation)

Parameters

value Color3

The color whose saturation is to be adjusted.

saturation float

The amount by which to adjust the saturation.

Returns

Color3

The adjusted color.

AdjustSaturation(ref readonly Color3, float, out Color3)

Adjusts the saturation of a color.

public static void AdjustSaturation(ref readonly Color3 value, float saturation, out Color3 result)

Parameters

value Color3

The color whose saturation is to be adjusted.

saturation float

The amount by which to adjust the saturation.

result Color3

When the method completes, contains the adjusted color.

Clamp(Color3, Color3, Color3)

Restricts a value to be within a specified range.

public static Color3 Clamp(Color3 value, Color3 min, Color3 max)

Parameters

value Color3

The value to clamp.

min Color3

The minimum value.

max Color3

The maximum value.

Returns

Color3

The clamped value.

Clamp(ref readonly Color3, ref readonly Color3, ref readonly Color3, out Color3)

Restricts a value to be within a specified range.

public static void Clamp(ref readonly Color3 value, ref readonly Color3 min, ref readonly Color3 max, out Color3 result)

Parameters

value Color3

The value to clamp.

min Color3

The minimum value.

max Color3

The maximum value.

result Color3

When the method completes, contains the clamped value.

Deconstruct(out float, out float, out float)

Deconstructs the vector's components into named variables.

public void Deconstruct(out float r, out float g, out float b)

Parameters

r float

The R component

g float

The G component

b float

The B component

Equals(Color3)

Determines whether the specified Color3 is equal to this instance.

public bool Equals(Color3 other)

Parameters

other Color3

The Color3 to compare with this instance.

Returns

bool

true if the specified Color3 is equal to this instance; otherwise, false.

Equals(object)

Determines whether the specified object is equal to this instance.

public override bool Equals(object value)

Parameters

value object

The object to compare with this instance.

Returns

bool

true if the specified object is equal to this instance; otherwise, false.

GetHashCode()

Returns a hash code for this instance.

public override int GetHashCode()

Returns

int

A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.

Lerp(Color3, Color3, float)

Performs a linear interpolation between two colors.

public static Color3 Lerp(Color3 start, Color3 end, float amount)

Parameters

start Color3

Start color.

end Color3

End color.

amount float

Value between 0 and 1 indicating the weight of end.

Returns

Color3

The linear interpolation of the two colors.

Remarks

This method performs the linear interpolation based on the following formula.

start + (end - start) * amount

Passing amount a value of 0 will cause start to be returned; a value of 1 will cause end to be returned.

Lerp(ref readonly Color3, ref readonly Color3, float, out Color3)

Performs a linear interpolation between two colors.

public static void Lerp(ref readonly Color3 start, ref readonly Color3 end, float amount, out Color3 result)

Parameters

start Color3

Start color.

end Color3

End color.

amount float

Value between 0 and 1 indicating the weight of end.

result Color3

When the method completes, contains the linear interpolation of the two colors.

Remarks

This method performs the linear interpolation based on the following formula.

start + (end - start) * amount

Passing amount a value of 0 will cause start to be returned; a value of 1 will cause end to be returned.

Max(Color3, Color3)

Returns a color containing the largest components of the specified colorss.

public static Color3 Max(Color3 left, Color3 right)

Parameters

left Color3

The first source color.

right Color3

The second source color.

Returns

Color3

A color containing the largest components of the source colors.

Max(ref readonly Color3, ref readonly Color3, out Color3)

Returns a color containing the smallest components of the specified colorss.

public static void Max(ref readonly Color3 left, ref readonly Color3 right, out Color3 result)

Parameters

left Color3

The first source color.

right Color3

The second source color.

result Color3

When the method completes, contains an new color composed of the largest components of the source colorss.

Min(Color3, Color3)

Returns a color containing the smallest components of the specified colors.

public static Color3 Min(Color3 left, Color3 right)

Parameters

left Color3

The first source color.

right Color3

The second source color.

Returns

Color3

A color containing the smallest components of the source colors.

Min(ref readonly Color3, ref readonly Color3, out Color3)

Returns a color containing the smallest components of the specified colors.

public static void Min(ref readonly Color3 left, ref readonly Color3 right, out Color3 result)

Parameters

left Color3

The first source color.

right Color3

The second source color.

result Color3

When the method completes, contains an new color composed of the smallest components of the source colors.

Modulate(Color3, Color3)

Modulates two colors.

public static Color3 Modulate(Color3 left, Color3 right)

Parameters

left Color3

The first color to modulate.

right Color3

The second color to modulate.

Returns

Color3

The modulated color.

Modulate(ref readonly Color3, ref readonly Color3, out Color3)

Modulates two colors.

public static void Modulate(ref readonly Color3 left, ref readonly Color3 right, out Color3 result)

Parameters

left Color3

The first color to modulate.

right Color3

The second color to modulate.

result Color3

When the method completes, contains the modulated color.

Negate(Color3)

Negates a color.

public static Color3 Negate(Color3 value)

Parameters

value Color3

The color to negate.

Returns

Color3

The negated color.

Negate(ref readonly Color3, out Color3)

Negates a color.

public static void Negate(ref readonly Color3 value, out Color3 result)

Parameters

value Color3

The color to negate.

result Color3

When the method completes, contains the negated color.

Pow(float)

Raises the exponent for each components.

public void Pow(float exponent)

Parameters

exponent float

The exponent.

Scale(Color3, float)

Scales a color.

public static Color3 Scale(Color3 value, float scale)

Parameters

value Color3

The color to scale.

scale float

The amount by which to scale.

Returns

Color3

The scaled color.

Scale(ref readonly Color3, float, out Color3)

Scales a color.

public static void Scale(ref readonly Color3 value, float scale, out Color3 result)

Parameters

value Color3

The color to scale.

scale float

The amount by which to scale.

result Color3

When the method completes, contains the scaled color.

SmoothStep(Color3, Color3, float)

Performs a cubic interpolation between two colors.

public static Color3 SmoothStep(Color3 start, Color3 end, float amount)

Parameters

start Color3

Start color.

end Color3

End color.

amount float

Value between 0 and 1 indicating the weight of end.

Returns

Color3

The cubic interpolation of the two colors.

SmoothStep(ref readonly Color3, ref readonly Color3, float, out Color3)

Performs a cubic interpolation between two colors.

public static void SmoothStep(ref readonly Color3 start, ref readonly Color3 end, float amount, out Color3 result)

Parameters

start Color3

Start color.

end Color3

End color.

amount float

Value between 0 and 1 indicating the weight of end.

result Color3

When the method completes, contains the cubic interpolation of the two colors.

Subtract(Color3, Color3)

Subtracts two colors.

public static Color3 Subtract(Color3 left, Color3 right)

Parameters

left Color3

The first color to subtract.

right Color3

The second color to subtract

Returns

Color3

The difference of the two colors.

Subtract(ref readonly Color3, ref readonly Color3, out Color3)

Subtracts two colors.

public static void Subtract(ref readonly Color3 left, ref readonly Color3 right, out Color3 result)

Parameters

left Color3

The first color to subtract.

right Color3

The second color to subtract.

result Color3

WHen the method completes, contains the difference of the two colors.

ToArray()

Creates an array containing the elements of the color.

public float[] ToArray()

Returns

float[]

A three-element array containing the components of the color.

ToColor4()

Convert this color to an equivalent Color4 with an opaque alpha.

public Color4 ToColor4()

Returns

Color4

An equivalent Color4 with an opaque alpha.

ToLinear()

Converts this color from sRGB space to linear space.

public Color3 ToLinear()

Returns

Color3

Color3.

ToRgb()

Converts the color into a packed integer.

public int ToRgb()

Returns

int

A packed integer containing all three color components. The alpha channel is set to 255.

ToSRgb()

Converts this color from linear space to sRGB space.

public Color3 ToSRgb()

Returns

Color3

A color3 in sRGB space.

ToString()

Returns a string that represents this instance.

public override string ToString()

Returns

string

A string that represents this instance.

ToString(IFormatProvider)

Returns a string that represents this instance.

public string ToString(IFormatProvider formatProvider)

Parameters

formatProvider IFormatProvider

The format provider.

Returns

string

A string that represents this instance.

ToString(string)

Returns a string that represents this instance.

public string ToString(string format)

Parameters

format string

The format.

Returns

string

A string that represents this instance.

ToString(string, IFormatProvider)

Returns a string that represents this instance.

public string ToString(string format, IFormatProvider formatProvider)

Parameters

format string

The format.

formatProvider IFormatProvider

The format provider.

Returns

string

A string that represents this instance.

ToVector3()

Converts the color into a three component vector.

public Vector3 ToVector3()

Returns

Vector3

A three component vector containing the red, green, and blue components of the color.

Operators

operator +(Color3, Color3)

Adds two colors.

public static Color3 operator +(Color3 left, Color3 right)

Parameters

left Color3

The first color to add.

right Color3

The second color to add.

Returns

Color3

The sum of the two colors.

operator ==(Color3, Color3)

Tests for equality between two objects.

public static bool operator ==(Color3 left, Color3 right)

Parameters

left Color3

The first value to compare.

right Color3

The second value to compare.

Returns

bool

true if left has the same value as right; otherwise, false.

explicit operator Color4(Color3)

Performs an explicit conversion from Color3 to Color4.

public static explicit operator Color4(Color3 value)

Parameters

value Color3

The value.

Returns

Color4

The result of the conversion.

explicit operator Vector3(Color3)

Performs an explicit conversion from Color3 to Vector3.

public static explicit operator Vector3(Color3 value)

Parameters

value Color3

The value.

Returns

Vector3

The result of the conversion.

explicit operator Color3(Vector3)

Performs an explicit conversion from Vector3 to Color3.

public static explicit operator Color3(Vector3 value)

Parameters

value Vector3

The value.

Returns

Color3

The result of the conversion.

explicit operator Color3(int)

Performs an explicit conversion from int to Color3.

public static explicit operator Color3(int value)

Parameters

value int

The value.

Returns

Color3

The result of the conversion.

operator !=(Color3, Color3)

Tests for inequality between two objects.

public static bool operator !=(Color3 left, Color3 right)

Parameters

left Color3

The first value to compare.

right Color3

The second value to compare.

Returns

bool

true if left has a different value than right; otherwise, false.

operator *(Color3, Color3)

Modulates two colors.

public static Color3 operator *(Color3 left, Color3 right)

Parameters

left Color3

The first color to modulate.

right Color3

The second color to modulate.

Returns

Color3

The modulated color.

operator *(Color3, float)

Scales a color.

public static Color3 operator *(Color3 value, float scale)

Parameters

value Color3

The factor by which to scale the color.

scale float

The color to scale.

Returns

Color3

The scaled color.

operator *(float, Color3)

Scales a color.

public static Color3 operator *(float scale, Color3 value)

Parameters

scale float

The factor by which to scale the color.

value Color3

The color to scale.

Returns

Color3

The scaled color.

operator -(Color3, Color3)

Subtracts two colors.

public static Color3 operator -(Color3 left, Color3 right)

Parameters

left Color3

The first color to subtract.

right Color3

The second color to subtract.

Returns

Color3

The difference of the two colors.

operator -(Color3)

Negates a color.

public static Color3 operator -(Color3 value)

Parameters

value Color3

The color to negate.

Returns

Color3

A negated color.

operator +(Color3)

Assert a color (return it unchanged).

public static Color3 operator +(Color3 value)

Parameters

value Color3

The color to assert (unchange).

Returns

Color3

The asserted (unchanged) color.