# core/colorspace (vanilla-engine 0.4.0)

> https://vanillapunch.com/docs/vanilla-engine/0.4.0/api/core/colorspace/

Color space. (the setting that picks which space each game computes 3D light in, in the style of Color Space in Unity Player Settings, original core/graphic/colorspace.js)
- Gamma (default): the path so far. Color textures are uploaded as RGBA, the shader converts them to linear with the pow(color, 2.2) approximation to compute light, and pow(1 / 2.2) produces the screen color.
  Base color, tint and decal are multiplied and mixed as gamma-encoded colors (sRGB). The screens of games already released do not change.
- Linear: the standard 3D path. Color textures (base color, emission, decal, matcap, angel ring, ramp) are uploaded as SRGB8_ALPHA8 so the GPU decodes them to linear when reading
  (filtering and mipmaps in linear space), and passed colors (vertex color, tint, emissive color, decal color, outline color) are converted to linear with the standard sRGB curve (IEC 61966-2-1)
  before they are multiplied and mixed. The screen output uses the same curve back to sRGB. Data textures such as normals and masks stay linear. (is_color_data: false in ToonTextureOptions)
- A game picks it once with EngineConfiguration::color_space. The toon renderer, post process, screen outline and GLB readers follow the engine's value unless given one.
  (Gamma when no engine was created) The chosen value is fixed at creation and does not change afterwards. (programs and texture formats depend on it)
- 2D (Graphic's 2D batches, text, UI) is mixed and composited in gamma space (sRGB values as they are) either way, as before. This setting only splits the 3D (toon) path.
- Shaders: with Linear, #define VANILLA_COLOR_SPACE_LINEAR 1 is put on the line after #version of the 3D shaders the engine builds.
  Material chunks can branch with #ifdef VANILLA_COLOR_SPACE_LINEAR. (the same use as UNITY_COLORSPACE_GAMMA in Unity shaders)
- Desktop GL does not enable GL_FRAMEBUFFER_SRGB on the default framebuffer. (the shaders apply the curve themselves, so enabling it would apply it twice, the same as the web canvas)

Example: Engine configuration of a linear color space game and a toon renderer that engine builds

```rust
use vanilla::{ColorSpace, Engine, EngineConfiguration, ToonRenderer};

let mut engine_configuration = EngineConfiguration::new();
engine_configuration.color_space = ColorSpace::Linear;
let engine = Engine::new(engine_configuration);
if let Some(graphic) = engine.get_graphic() {
	let renderer = ToonRenderer::new(graphic.get_gl()).unwrap();
	assert_eq!(renderer.get_color_space(), ColorSpace::Linear);
}
```

## ColorSpace (enum) (Clone, Copy, Debug, Default, PartialEq, Eq, Hash)

Color space kind. (original ColorSpace)

Example: Build an engine configuration with the linear color space

```rust
use vanilla::{ColorSpace, EngineConfiguration};

let mut engine_configuration = EngineConfiguration::new();
assert_eq!(engine_configuration.color_space, ColorSpace::Gamma);
engine_configuration.color_space = ColorSpace::Linear;
assert_eq!(engine_configuration.color_space, ColorSpace::Linear);
```

- `Gamma`: Gamma space. (default, the screen so far, pow 2.2 approximation)
- `Linear`: Linear space. (sRGB textures, the standard sRGB curve, the standard for 3D)
