Basic texture use
In this example we assign a texture to a channel and render it.
Example Links
How to directly use a texture
To use a texture, we need to assign it to a channel. The incantation to do this varies
slightly between this example, a simple IndigoShader
and using it in a full Indigo game
where the channel must be assigned to the ShaderData
referencing the AssetName
.
val channel0: Option[AssetPath] = Option(AssetPath("assets/fire-background.png"))
In the simplest use of an image/texture, you just need to use of the appropriate channel, in
this case env.CHANNEL_0
. This type of channel reference provides the color of the pixel at
the current UV coordinate.
Where did the UV coordinate come from? It is an interpolated value that is passed to the fragment shader from the vertex shader. UV Coordinates in Indigo are in the range 0.0 to 1.0 from top-left to bottom-right.
inline def fragment: Shader[FragmentEnv, Unit] =
Shader[FragmentEnv] { env =>
def fragment(color: vec4): vec4 =
env.CHANNEL_0
}