Stride

OPEN / CLOSE
  • Features
  • Blog
  • Documentation
  • Community
(icon) Download

  • Discord
  • Facebook
  • Twitter
  • YouTube

LANGUAGE

OPEN / CLOSE
  • English
  • 日本語
    Show / Hide Table of Contents

    Color3 Struct

    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
    Name Description
    Constructors
    Color3(Vector3)

    Initializes a new instance of the Color3 struct.

    Color3(Int32)

    Initializes a new instance of the Color3 struct.

    Color3(Single)

    Initializes a new instance of the Color3 struct.

    Color3(Single, Single, Single)

    Initializes a new instance of the Color3 struct.

    Color3(Single[])

    Initializes a new instance of the Color3 struct.

    Color3(UInt32)

    Initializes a new instance of the Color3 struct.

    Fields
    B

    The blue component of the color.

    G

    The green component of the color.

    R

    The red component of the color.

    Properties
    Item[Int32]

    Gets or sets the component at the specified index.

    Methods
    Add(Color3, Color3)

    Adds two colors.

    Add(ref Color3, ref Color3, out Color3)

    Adds two colors.

    AdjustContrast(Color3, Single)

    Adjusts the contrast of a color.

    AdjustContrast(ref Color3, Single, out Color3)

    Adjusts the contrast of a color.

    AdjustSaturation(Color3, Single)

    Adjusts the saturation of a color.

    AdjustSaturation(ref Color3, Single, out Color3)

    Adjusts the saturation of a color.

    Clamp(Color3, Color3, Color3)

    Restricts a value to be within a specified range.

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

    Restricts a value to be within a specified range.

    Equals(Color3)

    Determines whether the specified Color3 is equal to this instance.

    Equals(Object)

    Determines whether the specified System.Object is equal to this instance.

    GetHashCode()

    Returns a hash code for this instance.

    Lerp(Color3, Color3, Single)

    Performs a linear interpolation between two colors.

    Lerp(ref Color3, ref Color3, Single, out Color3)

    Performs a linear interpolation between two colors.

    Max(Color3, Color3)

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

    Max(ref Color3, ref Color3, out Color3)

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

    Min(Color3, Color3)

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

    Min(ref Color3, ref Color3, out Color3)

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

    Modulate(Color3, Color3)

    Modulates two colors.

    Modulate(ref Color3, ref Color3, out Color3)

    Modulates two colors.

    Negate(Color3)

    Negates a color.

    Negate(ref Color3, out Color3)

    Negates a color.

    Pow(Single)

    Raises the exponent for each components.

    Scale(Color3, Single)

    Scales a color.

    Scale(ref Color3, Single, out Color3)

    Scales a color.

    SmoothStep(Color3, Color3, Single)

    Performs a cubic interpolation between two colors.

    SmoothStep(ref Color3, ref Color3, Single, out Color3)

    Performs a cubic interpolation between two colors.

    Subtract(Color3, Color3)

    Subtracts two colors.

    Subtract(ref Color3, ref Color3, out Color3)

    Subtracts two colors.

    ToArray()

    Creates an array containing the elements of the color.

    ToColor4()

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

    ToLinear()

    Converts this color from sRGB space to linear space.

    ToRgb()

    Converts the color into a packed integer.

    ToSRgb()

    Converts this color from linear space to sRGB space.

    ToString()

    Returns a System.String that represents this instance.

    ToString(IFormatProvider)

    Returns a System.String that represents this instance.

    ToString(String)

    Returns a System.String that represents this instance.

    ToString(String, IFormatProvider)

    Returns a System.String that represents this instance.

    ToVector3()

    Converts the color into a three component vector.

    Operators
    Addition(Color3, Color3)

    Adds two colors.

    Equality(Color3, Color3)

    Tests for equality between two objects.

    Explicit(Color3 to Color4)

    Performs an explicit conversion from Color3 to Color4.

    Explicit(Color3 to Vector3)

    Performs an explicit conversion from Color3 to Vector3.

    Explicit(Vector3 to Color3)

    Performs an explicit conversion from Vector3 to Color3.

    Explicit(Int32 to Color3)

    Performs an explicit conversion from System.Int32 to Color3.

    Inequality(Color3, Color3)

    Tests for inequality between two objects.

    Multiply(Color3, Color3)

    Modulates two colors.

    Multiply(Color3, Single)

    Scales a color.

    Multiply(Single, Color3)

    Scales a color.

    Subtraction(Color3, Color3)

    Subtracts two colors.

    UnaryNegation(Color3)

    Negates a color.

    UnaryPlus(Color3)

    Assert a color (return it unchanged).

    | Improve this Doc View Source

    Constructors


    Color3(Vector3)

    Initializes a new instance of the Color3 struct.

    public Color3(Vector3 value)
    Parameters
    Type Name Description
    Vector3 value

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


    Color3(Int32)

    Initializes a new instance of the Color3 struct.

    public Color3(int rgb)
    Parameters
    Type Name Description
    System.Int32 rgb

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


    Color3(Single)

    Initializes a new instance of the Color3 struct.

    public Color3(float value)
    Parameters
    Type Name Description
    System.Single value

    The value that will be assigned to all components.


    Color3(Single, Single, Single)

    Initializes a new instance of the Color3 struct.

    public Color3(float red, float green, float blue)
    Parameters
    Type Name Description
    System.Single red

    The red component of the color.

    System.Single green

    The green component of the color.

    System.Single blue

    The blue component of the color.


    Color3(Single[])

    Initializes a new instance of the Color3 struct.

    public Color3(float[] values)
    Parameters
    Type Name Description
    System.Single[] values

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

    Exceptions
    Type Condition
    System.ArgumentNullException

    Thrown when values is null.

    System.ArgumentOutOfRangeException

    Thrown when values contains more or less than four elements.


    Color3(UInt32)

    Initializes a new instance of the Color3 struct.

    public Color3(uint rgb)
    Parameters
    Type Name Description
    System.UInt32 rgb

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

    | Improve this Doc View Source

    Fields


    B

    The blue component of the color.

    [DataMember(2)]
    public float B
    Field Value
    Type Description
    System.Single

    G

    The green component of the color.

    [DataMember(1)]
    public float G
    Field Value
    Type Description
    System.Single

    R

    The red component of the color.

    [DataMember(0)]
    public float R
    Field Value
    Type Description
    System.Single
    | Improve this Doc View Source

    Properties


    Item[Int32]

    Gets or sets the component at the specified index.

    public float this[int index] { get; set; }
    Parameters
    Type Name Description
    System.Int32 index

    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
    Type Description
    System.Single

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

    Exceptions
    Type Condition
    System.ArgumentOutOfRangeException

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

    | Improve this Doc View Source

    Methods


    Add(Color3, Color3)

    Adds two colors.

    public static Color3 Add(Color3 left, Color3 right)
    Parameters
    Type Name Description
    Color3 left

    The first color to add.

    Color3 right

    The second color to add.

    Returns
    Type Description
    Color3

    The sum of the two colors.


    Add(ref Color3, ref Color3, out Color3)

    Adds two colors.

    public static void Add(ref Color3 left, ref Color3 right, out Color3 result)
    Parameters
    Type Name Description
    Color3 left

    The first color to add.

    Color3 right

    The second color to add.

    Color3 result

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


    AdjustContrast(Color3, Single)

    Adjusts the contrast of a color.

    public static Color3 AdjustContrast(Color3 value, float contrast)
    Parameters
    Type Name Description
    Color3 value

    The color whose contrast is to be adjusted.

    System.Single contrast

    The amount by which to adjust the contrast.

    Returns
    Type Description
    Color3

    The adjusted color.


    AdjustContrast(ref Color3, Single, out Color3)

    Adjusts the contrast of a color.

    public static void AdjustContrast(ref Color3 value, float contrast, out Color3 result)
    Parameters
    Type Name Description
    Color3 value

    The color whose contrast is to be adjusted.

    System.Single contrast

    The amount by which to adjust the contrast.

    Color3 result

    When the method completes, contains the adjusted color.


    AdjustSaturation(Color3, Single)

    Adjusts the saturation of a color.

    public static Color3 AdjustSaturation(Color3 value, float saturation)
    Parameters
    Type Name Description
    Color3 value

    The color whose saturation is to be adjusted.

    System.Single saturation

    The amount by which to adjust the saturation.

    Returns
    Type Description
    Color3

    The adjusted color.


    AdjustSaturation(ref Color3, Single, out Color3)

    Adjusts the saturation of a color.

    public static void AdjustSaturation(ref Color3 value, float saturation, out Color3 result)
    Parameters
    Type Name Description
    Color3 value

    The color whose saturation is to be adjusted.

    System.Single saturation

    The amount by which to adjust the saturation.

    Color3 result

    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
    Type Name Description
    Color3 value

    The value to clamp.

    Color3 min

    The minimum value.

    Color3 max

    The maximum value.

    Returns
    Type Description
    Color3

    The clamped value.


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

    Restricts a value to be within a specified range.

    public static void Clamp(ref Color3 value, ref Color3 min, ref Color3 max, out Color3 result)
    Parameters
    Type Name Description
    Color3 value

    The value to clamp.

    Color3 min

    The minimum value.

    Color3 max

    The maximum value.

    Color3 result

    When the method completes, contains the clamped value.


    Equals(Color3)

    Determines whether the specified Color3 is equal to this instance.

    public bool Equals(Color3 other)
    Parameters
    Type Name Description
    Color3 other

    The Color3 to compare with this instance.

    Returns
    Type Description
    System.Boolean

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


    Equals(Object)

    Determines whether the specified System.Object is equal to this instance.

    public override bool Equals(object value)
    Parameters
    Type Name Description
    System.Object value

    The System.Object to compare with this instance.

    Returns
    Type Description
    System.Boolean

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

    Overrides
    System.ValueType.Equals(System.Object)

    GetHashCode()

    Returns a hash code for this instance.

    public override int GetHashCode()
    Returns
    Type Description
    System.Int32

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

    Overrides
    System.ValueType.GetHashCode()

    Lerp(Color3, Color3, Single)

    Performs a linear interpolation between two colors.

    public static Color3 Lerp(Color3 start, Color3 end, float amount)
    Parameters
    Type Name Description
    Color3 start

    Start color.

    Color3 end

    End color.

    System.Single amount

    Value between 0 and 1 indicating the weight of end.

    Returns
    Type Description
    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 Color3, ref Color3, Single, out Color3)

    Performs a linear interpolation between two colors.

    public static void Lerp(ref Color3 start, ref Color3 end, float amount, out Color3 result)
    Parameters
    Type Name Description
    Color3 start

    Start color.

    Color3 end

    End color.

    System.Single amount

    Value between 0 and 1 indicating the weight of end.

    Color3 result

    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
    Type Name Description
    Color3 left

    The first source color.

    Color3 right

    The second source color.

    Returns
    Type Description
    Color3

    A color containing the largest components of the source colors.


    Max(ref Color3, ref Color3, out Color3)

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

    public static void Max(ref Color3 left, ref Color3 right, out Color3 result)
    Parameters
    Type Name Description
    Color3 left

    The first source color.

    Color3 right

    The second source color.

    Color3 result

    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
    Type Name Description
    Color3 left

    The first source color.

    Color3 right

    The second source color.

    Returns
    Type Description
    Color3

    A color containing the smallest components of the source colors.


    Min(ref Color3, ref Color3, out Color3)

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

    public static void Min(ref Color3 left, ref Color3 right, out Color3 result)
    Parameters
    Type Name Description
    Color3 left

    The first source color.

    Color3 right

    The second source color.

    Color3 result

    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
    Type Name Description
    Color3 left

    The first color to modulate.

    Color3 right

    The second color to modulate.

    Returns
    Type Description
    Color3

    The modulated color.


    Modulate(ref Color3, ref Color3, out Color3)

    Modulates two colors.

    public static void Modulate(ref Color3 left, ref Color3 right, out Color3 result)
    Parameters
    Type Name Description
    Color3 left

    The first color to modulate.

    Color3 right

    The second color to modulate.

    Color3 result

    When the method completes, contains the modulated color.


    Negate(Color3)

    Negates a color.

    public static Color3 Negate(Color3 value)
    Parameters
    Type Name Description
    Color3 value

    The color to negate.

    Returns
    Type Description
    Color3

    The negated color.


    Negate(ref Color3, out Color3)

    Negates a color.

    public static void Negate(ref Color3 value, out Color3 result)
    Parameters
    Type Name Description
    Color3 value

    The color to negate.

    Color3 result

    When the method completes, contains the negated color.


    Pow(Single)

    Raises the exponent for each components.

    public void Pow(float exponent)
    Parameters
    Type Name Description
    System.Single exponent

    The exponent.


    Scale(Color3, Single)

    Scales a color.

    public static Color3 Scale(Color3 value, float scale)
    Parameters
    Type Name Description
    Color3 value

    The color to scale.

    System.Single scale

    The amount by which to scale.

    Returns
    Type Description
    Color3

    The scaled color.


    Scale(ref Color3, Single, out Color3)

    Scales a color.

    public static void Scale(ref Color3 value, float scale, out Color3 result)
    Parameters
    Type Name Description
    Color3 value

    The color to scale.

    System.Single scale

    The amount by which to scale.

    Color3 result

    When the method completes, contains the scaled color.


    SmoothStep(Color3, Color3, Single)

    Performs a cubic interpolation between two colors.

    public static Color3 SmoothStep(Color3 start, Color3 end, float amount)
    Parameters
    Type Name Description
    Color3 start

    Start color.

    Color3 end

    End color.

    System.Single amount

    Value between 0 and 1 indicating the weight of end.

    Returns
    Type Description
    Color3

    The cubic interpolation of the two colors.


    SmoothStep(ref Color3, ref Color3, Single, out Color3)

    Performs a cubic interpolation between two colors.

    public static void SmoothStep(ref Color3 start, ref Color3 end, float amount, out Color3 result)
    Parameters
    Type Name Description
    Color3 start

    Start color.

    Color3 end

    End color.

    System.Single amount

    Value between 0 and 1 indicating the weight of end.

    Color3 result

    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
    Type Name Description
    Color3 left

    The first color to subtract.

    Color3 right

    The second color to subtract

    Returns
    Type Description
    Color3

    The difference of the two colors.


    Subtract(ref Color3, ref Color3, out Color3)

    Subtracts two colors.

    public static void Subtract(ref Color3 left, ref Color3 right, out Color3 result)
    Parameters
    Type Name Description
    Color3 left

    The first color to subtract.

    Color3 right

    The second color to subtract.

    Color3 result

    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
    Type Description
    System.Single[]

    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
    Type Description
    Color4

    An equivalent Color4 with an opaque alpha.


    ToLinear()

    Converts this color from sRGB space to linear space.

    public Color3 ToLinear()
    Returns
    Type Description
    Color3

    Color3.


    ToRgb()

    Converts the color into a packed integer.

    public int ToRgb()
    Returns
    Type Description
    System.Int32

    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
    Type Description
    Color3

    A color3 in sRGB space.


    ToString()

    Returns a System.String that represents this instance.

    public override string ToString()
    Returns
    Type Description
    System.String

    A System.String that represents this instance.

    Overrides
    System.ValueType.ToString()

    ToString(IFormatProvider)

    Returns a System.String that represents this instance.

    public string ToString(IFormatProvider formatProvider)
    Parameters
    Type Name Description
    System.IFormatProvider formatProvider

    The format provider.

    Returns
    Type Description
    System.String

    A System.String that represents this instance.


    ToString(String)

    Returns a System.String that represents this instance.

    public string ToString(string format)
    Parameters
    Type Name Description
    System.String format

    The format.

    Returns
    Type Description
    System.String

    A System.String that represents this instance.


    ToString(String, IFormatProvider)

    Returns a System.String that represents this instance.

    public string ToString(string format, IFormatProvider formatProvider)
    Parameters
    Type Name Description
    System.String format

    The format.

    System.IFormatProvider formatProvider

    The format provider.

    Returns
    Type Description
    System.String

    A System.String that represents this instance.


    ToVector3()

    Converts the color into a three component vector.

    public Vector3 ToVector3()
    Returns
    Type Description
    Vector3

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

    | Improve this Doc View Source

    Operators


    Addition(Color3, Color3)

    Adds two colors.

    public static Color3 operator +(Color3 left, Color3 right)
    Parameters
    Type Name Description
    Color3 left

    The first color to add.

    Color3 right

    The second color to add.

    Returns
    Type Description
    Color3

    The sum of the two colors.


    Equality(Color3, Color3)

    Tests for equality between two objects.

    public static bool operator ==(Color3 left, Color3 right)
    Parameters
    Type Name Description
    Color3 left

    The first value to compare.

    Color3 right

    The second value to compare.

    Returns
    Type Description
    System.Boolean

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


    Explicit(Color3 to Color4)

    Performs an explicit conversion from Color3 to Color4.

    public static explicit operator Color4(Color3 value)
    Parameters
    Type Name Description
    Color3 value

    The value.

    Returns
    Type Description
    Color4

    The result of the conversion.


    Explicit(Color3 to Vector3)

    Performs an explicit conversion from Color3 to Vector3.

    public static explicit operator Vector3(Color3 value)
    Parameters
    Type Name Description
    Color3 value

    The value.

    Returns
    Type Description
    Vector3

    The result of the conversion.


    Explicit(Vector3 to Color3)

    Performs an explicit conversion from Vector3 to Color3.

    public static explicit operator Color3(Vector3 value)
    Parameters
    Type Name Description
    Vector3 value

    The value.

    Returns
    Type Description
    Color3

    The result of the conversion.


    Explicit(Int32 to Color3)

    Performs an explicit conversion from System.Int32 to Color3.

    public static explicit operator Color3(int value)
    Parameters
    Type Name Description
    System.Int32 value

    The value.

    Returns
    Type Description
    Color3

    The result of the conversion.


    Inequality(Color3, Color3)

    Tests for inequality between two objects.

    public static bool operator !=(Color3 left, Color3 right)
    Parameters
    Type Name Description
    Color3 left

    The first value to compare.

    Color3 right

    The second value to compare.

    Returns
    Type Description
    System.Boolean

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


    Multiply(Color3, Color3)

    Modulates two colors.

    public static Color3 operator *(Color3 left, Color3 right)
    Parameters
    Type Name Description
    Color3 left

    The first color to modulate.

    Color3 right

    The second color to modulate.

    Returns
    Type Description
    Color3

    The modulated color.


    Multiply(Color3, Single)

    Scales a color.

    public static Color3 operator *(Color3 value, float scale)
    Parameters
    Type Name Description
    Color3 value

    The factor by which to scale the color.

    System.Single scale

    The color to scale.

    Returns
    Type Description
    Color3

    The scaled color.


    Multiply(Single, Color3)

    Scales a color.

    public static Color3 operator *(float scale, Color3 value)
    Parameters
    Type Name Description
    System.Single scale

    The factor by which to scale the color.

    Color3 value

    The color to scale.

    Returns
    Type Description
    Color3

    The scaled color.


    Subtraction(Color3, Color3)

    Subtracts two colors.

    public static Color3 operator -(Color3 left, Color3 right)
    Parameters
    Type Name Description
    Color3 left

    The first color to subtract.

    Color3 right

    The second color to subtract.

    Returns
    Type Description
    Color3

    The difference of the two colors.


    UnaryNegation(Color3)

    Negates a color.

    public static Color3 operator -(Color3 value)
    Parameters
    Type Name Description
    Color3 value

    The color to negate.

    Returns
    Type Description
    Color3

    A negated color.


    UnaryPlus(Color3)

    Assert a color (return it unchanged).

    public static Color3 operator +(Color3 value)
    Parameters
    Type Name Description
    Color3 value

    The color to assert (unchange).

    Returns
    Type Description
    Color3

    The asserted (unchanged) color.


    Extension Methods

    ComponentBaseExtensions.DisposeBy<T>(T, ICollectorHolder)
    ComponentBaseExtensions.RemoveDisposeBy<T>(T, ICollectorHolder)
    ColorExtensions.ToColorSpace(Color3, ColorSpace)
    ColorExtensions.ToColorSpace(Color3, ColorSpace, ColorSpace)
    • Improve this Doc
    • View Source
    In This Article

    Back to top

    Copyright © 2019-2021 .NET Foundation and Contributors
    Supported by the .NET Foundation