List of GLSL Shader Inputs

In general, especially as of Panda3D version 1.9.0, the majority of GLSL shader input types can be specified from a Panda3D application using a call to set_shader_input(). However, it is often desirable to let Panda3D 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 Panda3D 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 p3d_Vertex;
in vec3 p3d_Normal;
in vec4 p3d_Color;

// The texture coordinates associated with the Nth texture.
in vec2 p3d_MultiTexCoord0;
in vec2 p3d_MultiTexCoord1;
in vec2 p3d_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 p3d_Binormal;
in vec3 p3d_Binormal0;
in vec3 p3d_Binormal1;
in vec3 p3d_Tangent;
in vec3 p3d_Tangent0;
in vec3 p3d_Tangent1;

// A vertex column named "anything".  The number of components should match up with
// that of the vertex array.  "uvec" and "ivec" variants are allowed in Panda3D 1.9.0
// and above 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 p3d_TransformTable array for the four
// most influential joints, and transform_weight the corresponding weights.
in vec4 transform_weight;
in uvec4 transform_index;

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 p3d_Vertex and store the
// result in gl_Position.
uniform mat4 p3d_ModelViewProjectionMatrix;

// These are parts of the above matrix.
uniform mat4 p3d_ModelViewMatrix;
uniform mat4 p3d_ProjectionMatrix;

// 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 p3d_NormalMatrix;

// These were added in Panda3D 1.9.0 and complement the existing matrices:
uniform mat4 p3d_ModelMatrix;
uniform mat4 p3d_ViewMatrix;
uniform mat4 p3d_ViewProjectionMatrix;

// 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 p3d_ProjectionMatrixInverse;
uniform mat4 p3d_ProjectionMatrixTranspose;
uniform mat4 p3d_ModelViewMatrixInverseTranspose;

// These access the Nth texture applied to the model.  The index matches up with
// the index used by p3d_MultiTexCoordN, p3d_TangentN, and p3d_BinormalN.
// The sampler type should be adjusted to match the type of the texture.
uniform sampler2D p3d_Texture0;
uniform sampler2DArray p3d_Texture1;
uniform sampler3D p3d_Texture2;
uniform samplerCube p3d_Texture3;

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

// New in 1.9.0.  Access the color scale applied to the node.
uniform vec4 p3d_ColorScale;

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

// New in 1.9.0.  The sum of all active ambient light colors.
uniform struct {
  vec4 ambient;
} p3d_LightModel;

// New in 1.9.0.  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 p3d_ClipPlane[...];

// New in 1.9.0.  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.9.1.  If hardware skinning is enabled, this contains the transform
// of each joint.  Superfluous array entries will contain the identity matrix.
uniform mat4 p3d_TransformTable[...];

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 p3d_ prefix.