Colour Constants

This example shows how to make use of the pre-defined colour constant values.

Demo

▶ Click to play

In this example, we extract a vec3 of red (1, 0, 0) and blue (0, 0, 1) using a 'swizzle' (the .xyz) and add them together to create magenta (1, 0, 1).

inline def fragment: Shader[FragmentEnv, Unit] =
  Shader[FragmentEnv] { env =>
    import ultraviolet.colors.*

    def fragment(color: vec4): vec4 =
      val magenta = Red.xyz + Blue.xyz
      vec4(magenta, 1.0f)
  }