Minimal Fragment Shader Setup

This example demonstrates how to set up a basic fragment shader. Please refer to the source code (linked below) to see how it is tied into the IndigoShader entry point, which is a cut down version of the other entry point types, and holds clues as to how you'll need to integrate your shader into a real game.

How to set up a minimal fragment shader

Inside a custom shader object, we define an ultraviolet shader using the entityFragment helper method, since we're not interested in using a vertex shader at this time. To do that, we need to supply a ShaderId, that we'll need to register in Indigo's boot data, and also the fragment shader itself.

We import the ultraviolet syntax inside the object in order to avoid import collisions.

The fragment shader is a simple function that takes a color and returns a new color. In this case, we're returning the colour red, by setting the red and alpha to 'full', i.e.:

vec4(red = 1.0f, green == 0.0f, blue = 0.0f, alpha = 1.0f)

object CustomShader:

  val shader: Shader =
    UltravioletShader.entityFragment(
      ShaderId("shader"),
      EntityShader.fragment[FragmentEnv](fragment, FragmentEnv.reference)
    )

  import ultraviolet.syntax.*

  inline def fragment: Shader[FragmentEnv, Unit] =
    Shader[FragmentEnv] { env =>
      def fragment(color: vec4): vec4 =
        vec4(1.0f, 0.0f, 0.0f, 1.0f)
    }