Indigo

Indigo

  • Blog
  • Guides
  • Docs
  • APIs
  • Tools
  • GitHub

›Shaders

Indigo

  • Indigo's Development Status

Getting started

  • Setup & Configuration
  • Hello, Indigo!
  • Examples
  • Mill & SBT Game Templates

Organising your game

  • Boot & Start Up
  • Game Entry Points
  • Scenes & Scene Management
  • SubSystems

The game loop

  • Events
  • Frame context
  • Outcome Type

Presentation

  • Animation
  • Audio
  • Boundaries
  • Cameras
  • Clones & Mutants
  • Depth
  • Layers
  • Lighting
  • Materials
  • Primitives & Building Blocks
  • SceneUpdateFragment
  • Shapes
  • Text & Fonts

UI Components

  • Overview
  • Buttons
  • Hit Area
  • Input Field
  • Radio Button

Shaders

  • Shaders Overview
  • Shader Constants, Variables, and Outputs
  • Blending
  • Premultiplied Alpha

Working with Time

  • Signals & Signal Functions
  • Time Varying Values

Platform & Publishing

  • Assets & Asset Loading
  • Cross Platform Publishing
  • File Format Importers
  • User Input Handling
  • Loading & Saving Data
  • Logging
  • Networking

Other information

  • Alternatives to Indigo
  • Glossary
  • Key Concepts
  • Model, ViewModel, & View
  • Anti-Patterns
  • Motivation & Constraints
  • Performance
  • Prior Art
  • Rendering Technology

Shader Constants, Variables, and Outputs

Below are tables of shader constants and variables that are available to you, provided by Indigo, when writing shaders for the WebGL 2.0 renderer.

To clarify terminology use on this page:

  1. "Constants" are fixed values that never change.
  2. "Variables" are values that you should treat as read only, and that will change between program runs.
  3. "Outputs" are values that you may be able to read, and may wish to write to in order to affect the final rendering.

Common

These values are available to all shader programs.

Constants

NameTypeDescription
PIfloat3.141592653589793 or 180 degrees.
PI_2floatPI / 2 or 90 degrees.
PI_4floatPI / 4 or 45 degrees.
TAUfloat2.0 * PI or 360 degrees.
TAU_2floatPI or 180 degrees.
TAU_4floatPI / 2 or 90 degrees.
TAU_8floatPI / 4 or 45 degrees.

Variables (read only)

NameTypeDescription
TIMEfloatRunning time in seconds.
VIEWPORT_SIZEvec2Size of the viewport in pixels.

Vertex Shader Programs

Note that SIZE and UV are treated differently between entity and blend shaders, this may be revised in the future.

Common

Outputs (read/write)

NameTypeDescription
VERTEXvec4The output position of the current vertex.

Entity Shader Specific

Variables (read only)

NameTypeDescription
ATLAS_SIZEvec2Size of the atlas this texture is on, in pixels.
CHANNEL_0_POSITIONvec2Top left position of this texture on the atlas in UV coords.
CHANNEL_0_SIZEvec2Size of this texture on the atlas in UV coords.
FRAME_SIZEvec2Size of sub-rectangle of the texture to be rendered, e.g. the crop (graphic) or animation frame (sprite).
INSTANCE_IDintThe ID of the current instance, it is a count starting at 0.
SIZEvec2The width and height in pixels of the space on the screen being drawn to, e.g. the width and height of a graphic.
TEXTURE_SIZEvec2Size of the texture in pixels.
UVvec2The interpolates UV coordinates that will be passed to the fragment shader. Ranges from (0,0) top left to (1,1) bottom right. (Equivalent to TEXTURE_COORDS, but read only.)

Outputs (read/write)

NameTypeDescription
CHANNEL_0_ATLAS_OFFSETvec2The position on the texture atlas for the texture assigned to channel 0.
CHANNEL_1_ATLAS_OFFSETvec2The position on the texture atlas for the texture assigned to channel 1.
CHANNEL_2_ATLAS_OFFSETvec2The position on the texture atlas for the texture assigned to channel 2.
CHANNEL_3_ATLAS_OFFSETvec2The position on the texture atlas for the texture assigned to channel 3.
CHANNEL_0_TEXTURE_COORDSvec2The scaled, interpolated texture coordinates for the texture in channel 0, uses CHANNEL_0_ATLAS_OFFSET.
CHANNEL_1_TEXTURE_COORDSvec2The scaled, interpolated texture coordinates for the texture in channel 1, uses CHANNEL_1_ATLAS_OFFSET.
CHANNEL_2_TEXTURE_COORDSvec2The scaled, interpolated texture coordinates for the texture in channel 2, uses CHANNEL_2_ATLAS_OFFSET.
CHANNEL_3_TEXTURE_COORDSvec2The scaled, interpolated texture coordinates for the texture in channel 3, uses CHANNEL_3_ATLAS_OFFSET.
POSITIONvec2The position of the entity in screen coords (pixels)
SCALEvec2The scale factor of the entity
REFvec2The offset reference position of the entity in screen coords (pixels)
FLIPvec2The horizontal and vertical flip of the entity. -1 is flipped, 1 is not.
ROTATIONfloatThe rotation amount in radians to be applied to the current vertex.
TEXTURE_COORDS (Redundant, use UV)vec2The interpolates UV coordinates that will be passed to the fragment shader. Ranges from (0,0) top left to (1,1) bottom right. (Equivalent to UV, but modifiable.)

Blend Shader Specific

Outputs (read/write)

NameTypeDescription
SIZEvec2The width and height in pixels of the space on the screen being drawn to, e.g. the width and height of a graphic.
UVvec2The interpolates UV coordinates. Ranges from (0,0) top left to (1,1) bottom right.

Fragment Shader Programs

Common

Variables (read only)

NameTypeDescription
SIZEvec2The width and height in pixels of the space on the screen being drawn to, e.g. the width and height of a graphic.
UVvec2The interpolates UV coordinates. Ranges from (0,0) top left to (1,1) bottom right.

Outputs (read/write)

NameTypeDescription
COLORvec4Final pixel color.

Entity Shader Specific

Variables (read only)

NameTypeDescription
ATLAS_SIZEvec2Size of the atlas this texture is on, in pixels.
CHANNEL_0vec4Pixel color value from texture channel 0.
CHANNEL_1vec4Pixel color value from texture channel 1.
CHANNEL_2vec4Pixel color value from texture channel 2.
CHANNEL_3vec4Pixel color value from texture channel 3.
CHANNEL_0_POSITIONvec2Top left position of this texture on the atlas in UV coords.
CHANNEL_0_SIZEvec2Size of this texture on the atlas in UV coords.
CHANNEL_0_TEXTURE_COORDSvec2Scaled texture coordinates.
CHANNEL_1_TEXTURE_COORDSvec2Scaled texture coordinates.
CHANNEL_2_TEXTURE_COORDSvec2Scaled texture coordinates.
CHANNEL_3_TEXTURE_COORDSvec2Scaled texture coordinates.
INSTANCE_IDintThe ID of the current instance, it is a count starting at 0.
LIGHT_COUNTintTotal number of lights in the scene.
LIGHT_INDEXintIndex of the current light starting at 0 with a range of 0 to 7.
ROTATIONfloatThe rotation amount in radians.
SCREEN_COORDSvec2The absolute position of this pixel on the screen.
SRC_CHANNELsampler2DThe texture channel for the source image data. Current we only bind one atlas at a time. The 4 channels otherwise mention are all textures on the same atlas. It's a limitation we may remove in the future.
TEXTURE_SIZEvec2Size of the texture in pixels.

Outputs (read/write)

Please note that LIGHT_ variables change during execution of the program to show the details of the current light affecting the element being drawn.

NameTypeDescription
LIGHT_ACTIVEintIs the light enabled?
LIGHT_ANGLEfloatUsed in spotlights to determine the angle of the light cone.
LIGHT_COLORvec4The color of the light.
LIGHT_FALLOFF_TYPEintThe type of falloff to be used: 0 = none, 1 = smooth linear, 2 = smooth quadtratic, 3 = linear, 4 = quadratic
LIGHT_FARfloatThe maximum distance from the light up to which it will affect the scene.
LIGHT_FAR_CUT_OFFintValues are 1 or 0, this is really a boolean that determines if the LIGHT_FAR value is used or not. If not the light will attenuate forever.
LIGHT_INTENSITYfloatThe intensity of the light.
LIGHT_NEARfloatThe minimum distance to the light where it will begin to affect the scene.
LIGHT_POSITIONvec2The light's position.
LIGHT_ROTATIONfloatThe light's rotation.
LIGHT_SPECULARvec4The specular color of the light.
LIGHT_TYPEintWhat type of light is it? (0 = ambient, 1 = direction, 2 = point, 3 = spot)

Blend Shader Specific

Variables (read only)

NameTypeDescription
DST_CHANNELsampler2DThe texture channel for the destination image data.
SRC_CHANNELsampler2DThe texture channel for the source image data.

Outputs (read/write)

NameTypeDescription
DSTvec4Pixel color value from DST texture.
SRCvec4Pixel color value from SRC texture.
← Shaders OverviewBlending →
  • Common
    • Constants
    • Variables (read only)
  • Vertex Shader Programs
    • Common
    • Entity Shader Specific
    • Blend Shader Specific
  • Fragment Shader Programs
    • Common
    • Entity Shader Specific
    • Blend Shader Specific
Indigo
Getting Started
Setup & Configuration Guide"Hello, Indigo!" TutorialLinks to examplesProject templates
Community
DiscordGitHub DiscussonsTwitter
Sponsor us!
GitHub SponsorsPatreon