Vixen
02b45cc4
csharp
public readonly struct Color4

A colour with alpha, as four floats. **Linear**, unbounded above — an HDR light or an emissive material is a colour with components far past 1, and clamping here would throw that away before tonemapping ever sees it.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

A separate type from Vector4 on purpose. They have the same layout and convert freely, but a signature taking a Color4 says what it wants, and colour has operations — premultiplication, luminance, sRGB encoding — that are nonsense on a position.

Fields and properties (13)

  • public const int ComponentCount

    Number of components.

  • public readonly float R

    The red component.

  • public readonly float G

    The green component.

  • public readonly float B

    The blue component.

  • public readonly float A

    The alpha component: 0 fully transparent, 1 fully opaque.

  • public static Color4 Black

    Opaque black.

  • public static Color4 White

    Opaque white.

  • public static Color4 Transparent

    Fully transparent, and black rather than white so premultiplied blending behaves.

  • public static Color4 Red

    Opaque red.

  • public static Color4 Green

    Opaque green.

  • public static Color4 Blue

    Opaque blue.

  • public Color3 Rgb

    The colour without its alpha.

  • public float this[int index]

    The component at .

Methods (28)

  • public Color4(float r, float g, float b, float a)

    Builds a colour from its components.

  • public Color4(float r, float g, float b)

    Builds an opaque colour.

  • public Color4(Color3 rgb, float a)

    Builds a colour from an RGB triple and an alpha.

  • public Color4(float intensity)

    A grey with the given intensity, fully opaque.

  • public ReadOnlySpan<float> AsSpan()

    The components as a span. Valid as long as the colour it came from.

  • public float Luminance()

    The relative luminance, which is only meaningful because this is linear.

  • public static Color4 FromSrgb(Color4 srgb)

    Decodes an sRGB-encoded colour into this linear space.

  • public Color4 ToSrgb()

    Encodes this linear colour as sRGB.

  • public Color4 Premultiplied()

    Multiplies the colour by its own alpha, the form alpha blending actually wants.

  • public static Color4 Saturate(Color4 color)

    Constrains every component to [0, 1].

  • public static Color4 Lerp(Color4 from, Color4 to, float amount)

    Interpolates between two colours, component by component.

  • public static bool NearEqual(Color4 left, Color4 right, float tolerance = 1E-06)

    Whether two colours agree to within a tolerance.

  • public static Color4 operator +(Color4 left, Color4 right)

    Adds two colours — combining two lights.

  • public static Color4 operator -(Color4 left, Color4 right)

    Subtracts one colour from another.

  • public static Color4 operator *(Color4 left, Color4 right)

    Multiplies component by component — tinting, or a light meeting an albedo.

  • public static Color4 operator *(Color4 color, float scale)

    Scales a colour — changing an intensity.

  • public static Color4 operator *(float scale, Color4 color)

    Scales a colour.

  • public static bool operator ==(Color4 left, Color4 right)

    Exact component-wise equality, IEEE semantics. See NearEqual.

  • public static bool operator !=(Color4 left, Color4 right)

    The negation of op_Equality.

  • public static explicit operator Vector4(Color4 color)

    Reinterprets the colour as a vector, for the shader constants that take one.

  • public static explicit operator Color4(Vector4 vector)

    Reinterprets a vector as a colour.

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

    Splits the colour into its components.

  • public bool Equals(Color4 other)

    Indicates whether the current object is equal to another object of the same type.

  • public override bool Equals(object? obj)

    Indicates whether this instance and a specified object are equal.

  • public override int GetHashCode()

    Returns the hash code for this instance.

  • public override string ToString()

    Returns the fully qualified type name of this instance.

  • public string ToString(string? format, IFormatProvider? formatProvider)

    Formats the value of the current instance using the specified format.

  • public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default(ReadOnlySpan<char>), IFormatProvider? provider = null)

    Tries to format the value of the current instance into the provided span of characters.

Used by (170, showing 40)

  • UiHostHelloUi
  • AudioOverlayVixen.Audio
  • BatchTestsVixen.Ui.Tests
  • BoxStyleVixen.Ui
  • ClusteredShadingDeviceTestsVixen.Graphics.Golden.Tests
  • CodeEditorVixen.Ui.Controls.Advanced
  • ColorVixen.Core.Mathematics
  • ColorFieldVixen.Ui.Controls.Advanced
  • ColorInputVixen.Ui.Controls.Advanced
  • ColorInputTestsVixen.Ui.Controls.Advanced.Tests
  • ColorModelTestsVixen.Ui.Controls.Advanced.Tests
  • ColorPickerVixen.Ui.Controls.Advanced
  • ColorPickerTestsVixen.Ui.Controls.Advanced.Tests
  • ColorStripVixen.Ui.Controls.Advanced
  • ColorSwatchVixen.Ui.Controls.Advanced
  • ColorTestsVixen.Core.Mathematics.Tests
  • ColourAttachmentVixen.Graphics
  • ConsoleOverlayVixen.Engine
  • ConstraintGizmosVixen.Animation
  • CurveEditorVixen.Ui.Controls.Advanced
  • DebugDrawVixen.Engine
  • DebugDrawShapeTestsVixen.Engine.Tests
  • DebugDrawTestsVixen.Engine.Tests
  • DebugGeometryTestsVixen.Engine.Renderer.Tests
  • DebugLineVixen.Engine
  • DebugScreenLineVixen.Engine
  • DebugTextVixen.Engine
  • DrawCommandVixen.Ui
  • DrawContextVixen.Ui
  • DrawListBuilderVixen.Ui
  • DrawListTestsVixen.Ui.Tests
  • EditorGizmoFacingDeviceTestsVixen.Graphics.Golden.Tests
  • FrameGraphOverlayVixen.Engine
  • FrameStatsOverlayVixen.Engine
  • FullScreenRendererVixen.Rendering
  • GizmoTestsVixen.Animation.Tests
  • GlAttachmentVixen.Graphics.OpenGL
  • GlCommandListVixen.Graphics.OpenGL
  • GlDeviceVixen.Graphics.OpenGL
  • GradientVixen.Ui.Controls.Advanced