List of GLSL Shader Inputs

In general, the majority of GLSL shader input types can be specified from a Acron application using a call to set_shader_input(). However, it is often desirable to let Acron automatically fill in the values of shader inputs, especially for inputs that derive their values from the render state or 3-D transformation of the currently rendered model.

This page demonstrates which shader input names have a special meaning and will be automatically filled in by Acron when the shader is used. Note that the names and types have to be copied verbatim.

Vertex shader attributes

The following attributes are only permissible in vertex shaders.

These inputs use GLSL 1.40 syntax and above. In versions below that, it may be necessary to replace the “in” keyword with “attribute”.

// The position, normal vector and color of the currently processed vertex.
in vec4 acron_Vertex;
in vec3 acron_Normal;
in vec4 acron_Color;

// The texture coordinates associated with the Nth texture.
in vec2 acron_MultiTexCoord0;
in vec2 acron_MultiTexCoord1;
in vec2 acron_MultiTexCoord2;

// These are the tangent and binormal vectors, if present.  If an index is appended,
// it will use the set of binormals and tangents associated with the Nth texture.
in vec3 acron_Binormal;
in vec3 acron_Binormal0;
in vec3 acron_Binormal1;
in vec3 acron_Tangent;
in vec3 acron_Tangent0;
in vec3 acron_Tangent1;

// Some models, such as those loaded from glTF, only have a 4-component tangent
// vector and no binormal.  In this case, the binormal is derived as follows:
//   binormal = cross(acron_Normal, acron_Tangent.xyz) * acron_Tangent.w
in vec4 acron_Tangent;

// Some models, such as those loaded from glTF, only have a 4-component tangent
// vector and no binormal.  In this case, the binormal is derived as follows:
//   binormal = cross(p3d_Normal, p3d_Tangent.xyz) * p3d_Tangent.w
in vec4 p3d_Tangent;

// A vertex column named "anything".  The number of components should match up with
// that of the vertex array.  "uvec" and "ivec" variants are allowed for integer
// vertex arrays to access un-normalized data.
in vec4 anything;

// These two attributes will be present when hardware skinning is enabled.
// transform_index contains indices into the acron_TransformTable array for the four
// most influential joints, and transform_weight the corresponding weights.
in vec4 transform_weight;
in uvec4 transform_index;

A special note about vertex colors

Before Acron 1.10, if p3d_Color was used but no vertex color information was present on the model, the values would be undefined (but usually (0, 0, 0, 0)). This means that you could not use the same shader on objects with and without vertex colors, since objects without vertex colors would appear black instead of white.

In 1.10, acron_Color respects the ColorAttrib rules that also applied to the fixed-function pipeline: acron_Color will contain a white color if the vertex colors are absent or if colors are disabled using set_color_off(), and a flat color if one is applied using set_color(), even if vertex colors are present.

If you are absolutely certain that the model does not have vertex colors, you may also declare acron_Color as a uniform instead of a vertex attribute.

If you would like to treat the color column as a generic vertex attribute with no special handling, you should use the name “color” instead of “acron_Color”, which will bind it without any special handling.

Uniform shader inputs

The following shader inputs are uniform, which means that they are constant across the entire piece of geometry, rather than changing from vertex to vertex. They have to be declared with the uniform qualifier, and may be accessed in any shader stage.

// This is probably the most important uniform, transforming a model-space
// coordinate into a clip-space (ie. relative to the window) coordinate.  This
// is usually used in the vertex shader to transform acron_Vertex and store the
// result in gl_Position.
uniform mat4 acron_ModelViewProjectionMatrix;

// These are parts of the above matrix.
uniform mat4 acron_ModelViewMatrix;
uniform mat4 acron_ProjectionMatrix;
uniform mat4 acron_ModelMatrix;
uniform mat4 acron_ViewMatrix;
uniform mat4 acron_ViewProjectionMatrix;

// This is the upper 3x3 of the inverse transpose of the ModelViewMatrix.  It is
// used to transform the normal vector into view-space coordinates.
uniform mat3 acron_NormalMatrix;

// It's possible to append Inverse, Transpose, or InverseTranspose to any of the
// above matrix names to get an inverse and/or transpose version of that matrix:
uniform mat4 acron_ProjectionMatrixInverse;
uniform mat4 acron_ProjectionMatrixTranspose;
uniform mat4 acron_ModelViewMatrixInverseTranspose;

// These access the Nth texture applied to the model.  The index matches up with
// the index used by acron_MultiTexCoordN, acron_TangentN, and acron_BinormalN.
// The sampler type should be adjusted to match the type of the texture.
uniform sampler2D acron_Texture0;
uniform sampler2DArray acron_Texture1;
uniform sampler3D acron_Texture2;
uniform samplerCube acron_Texture3;

// As above, but "Shadow" should be appended if the texture has a shadow filter.
uniform sampler2DShadow acron_Texture0;

// Experimental inputs, new in 1.10.8, containing textures assigned using a
// particular TextureStage mode.  If no such texture has been assigned, a dummy
// texture is instead provided containing an appropriate default color.
uniform sampler2D acron_TextureModulate[]; // default color: (1, 1, 1, 1)
uniform sampler2D acron_TextureAdd[];      // default color: (0, 0, 0, 1)
uniform sampler2D acron_TextureNormal[];   // default color: (0.5, 0.5, 1, 0)
uniform sampler2D acron_TextureHeight[];   // default color: (0.5, 0.5, 1, 0)
uniform sampler2D acron_TextureGloss[];    // default color: (1, 1, 1, 1)
uniform sampler2D acron_TextureEmission[]; // default color: (1, 1, 1, 1)

// Experimental input, new in 1.10.16, containing the metallic-roughness
// texture as may be imported from a glTF file using acron-gltf.
// The green channel contains roughness and blue contains metalness.
uniform sampler2D acron_TextureMetallicRoughness[]; // default color: (1, 1, 1, 1)

// New in 1.10.0.  Contains the matrix generated from texture pos and scale.
uniform mat4 acron_TextureMatrix[];

// Access the color scale applied to the node.
uniform vec4 acron_ColorScale;

// Access the material attributes assigned via a Material object.
// Unused struct parameters may be omitted without consequence.
uniform struct acron_MaterialParameters {
  vec4 ambient;
  vec4 diffuse;
  vec4 emission;
  vec3 specular;
  float shininess;

  // These properties are new in 1.10.
  vec4 baseColor;
  float roughness;
  float metallic;
  float refractiveIndex;
} acron_Material;

// The sum of all active ambient light colors.
uniform struct acron_LightModelParameters {
  vec4 ambient;
} acron_LightModel;

// Active clip planes, in apiview space.  If there is no clip plane for a given
// index, it is guaranteed to contain vec4(0, 0, 0, 0).
uniform vec4 acron_ClipPlane[...];

// Reports the frame time of the current frame, for animations.
uniform float osg_FrameTime;
// The time elapsed since the previous frame.
uniform float osg_DeltaFrameTime;
// New in 1.10.0. Contains the number of frames elapsed since program start.
uniform int osg_FrameNumber;

// If hardware skinning is enabled, this contains the transform of each joint.
// Superfluous array entries will contain the identity matrix.
uniform mat4 acron_TransformTable[...];

// New in 1.10.  Contains information for each non-ambient light.
// May also be used to access a light passed as a shader input.
uniform struct acron_LightSourceParameters {
  // Primary light color.
  vec4 color;

  // Light color broken up into components, for compatibility with legacy
  // shaders.  These are now deprecated.
  vec4 ambient;
  vec4 diffuse;
  vec4 specular;

  // View-space position.  If w=0, this is a directional light, with the xyz
  // being -direction.
  vec4 position;

  // Spotlight-only settings
  vec3 spotDirection;
  float spotExponent;
  float spotCutoff;
  float spotCosCutoff;

  // Individual attenuation constants
  float constantAttenuation;
  float linearAttenuation;
  float quadraticAttenuation;

  // constant, linear, quadratic attenuation in one vector
  vec3 attenuation;

  // Shadow map for this light source
  sampler2DShadow shadowMap;

  // Transforms view-space coordinates to shadow map coordinates
  mat4 shadowViewMatrix;
} acron_LightSource[...];

// New in 1.10.  Contains fog state.
uniform struct acron_FogParameters {
  vec4 color;
  float density;
  float start;
  float end;
  float scale; // 1.0 / (end - start)
} acron_Fog;

Besides these predefined uniform inputs, it is possible to use most of the types available in GLSL in conjunction with set_shader_input() to pass custom data, including arrays and structs, to a certain named shader input. You may not use set_shader_input() to override any of the inputs with the acron_ prefix.