# struct Color

A color value stored as 4 floats with values that are generally between 0 and 1! Note that there’s also a Color32 structure, and that 4 floats is generally a lot more than you need. So, use this for calculating individual colors at quality, but maybe store them en-masse with Color32!

Also note that RGB is often a terrible color format for picking colors, but it’s how our displays work and we’re stuck with it. If you want to create a color via code, try out the static Color.HSV method instead!

A note on gamma space vs. linear space colors! `Color` is not inherently one or the other, but most color values we work with tend to be gamma space colors, so most functions in StereoKit are gamma space. There are occasional functions that will ask for linear space colors instead, primarily in performance critical places, or places where a color may not always be a color! However, performing math on gamma space colors is bad, and will result in incorrect colors. We do our best to indicate what color space a function uses, but it’s not enforced through syntax!

## Instance Fields and Properties

float a Alpha, or opacity component, a value that is generally between 0-1, where 0 is completely transparent, and 1 is completely opaque.
float b Blue component, a value that is generally between 0-1
float g Green component, a value that is generally between 0-1
float r Red component, a value that is generally between 0-1

## Instance Methods

Color Try Color.HSV instead! But if you really need to create a color from RGB values, I suppose you’re in the right place. All parameter values are generally in the range of 0-1.
ToGamma Converts this from a linear space color, into a gamma space color! If this is not a linear space color, this will just make your color wacky!
ToHSV Converts the gamma space color to a Hue/Saturation/Value format! Does not consider transparency when calculating the result.
ToLAB Converts the gamma space RGB color to a CIE LAB color space value! Conversion back and forth from LAB space could be somewhat lossy.
ToLinear Converts this from a gamma space color, into a linear space color! If this is not a gamma space color, this will just make your color wacky!
ToString Mostly for debug purposes, this is a decent way to log or inspect the color in debug mode. Looks like “[r, g, b, a]”

## Static Fields and Properties

Color Black Pure opaque black! Same as (0,0,0,1).
Color BlackTransparent Pure transparent black! Same as (0,0,0,0).
Color White Pure opaque white! Same as (1,1,1,1).

## Static Methods

Hex Create a color from an integer based hex value! This can make it easier to copy over colors from the web. This isn’t a string function though, so you’ll need to fill it out the whole way. Ex: `Color.Hex(0x0000FFFF)` would be RGBA(0,0,1,1).
HSV Creates a Red/Green/Blue gamma space color from Hue/Saturation/Value information.
LAB Creates a gamma space RGB color from a CIE-Lab color space. CIE-Lab is a color space that models human perception, and has significantly more accurate to perception lightness values, so this is an excellent color space for color operations that wish to preserve color brightness properly. Traditionally, values are L [0,100], a,b [-200,+200] but here we normalize them all to the 0-1 range. If you hate it, let me know why!
Lerp This will linearly blend between two different colors! Best done on linear colors, rather than gamma corrected colors, but will work either way. This will not clamp the percentage to the 0-1 range.

## Operators

+ This will add a color component-wise with another color, including alpha. Best done on colors in linear space. No clamping is applied.
/ This will divide a color linearly, including alpha. Best done on a color in linear space. No clamping is applied.
Implicit Conversions This allows for implicit conversion to Color32. This does not convert from linear to gamma corrected, or clamp to 0-1 first.
* This will multiply a color linearly, including alpha. Best done on a color in linear space. No clamping is applied.
- This will subtract color `b` component-wise from color `a`, including alpha. Best done on colors in linear space. No clamping is applied.

## Examples

``````// You can create a color using Red, Green, Blue, Alpha values,
// but it's often a great recipe for making a bad color.
Color color = new Color(1,0,0,1); // Red

// Hue, Saturation, Value, Alpha is a more natural way of picking
// colors. The commentdocs have a list of important values for Hue,
// to make it a little easier to pick the hue you want.
color = Color.HSV(0, 1, 1, 1); // Red

// And there's a few static colors available if you need 'em.
color = Color.White;

// You can also implicitly convert Color to a Color32!
Color32 color32 = color;
``````

### Creating color from hex values

``````Color   hex128 = Color  .Hex(0xFF0000FF); // Opaque Red
Color32 hex32  = Color32.Hex(0x00FF00FF); // Opaque Green
``````

Found an issue with these docs, or have some additional questions? Create an Issue on Github!