You are on page 1of 3

BUILT-IN FUNCTIONS

OpenGL® Shading Language (GLSL) Matrix Functions (8.5 p55)


Key: mat matrixCompMult( mat, mat )
Quick Reference Guide vec = vec2 | vec3 | vec4
mat = mat2 | mat3 | mat4 Vector Relational Functions (8.6 p55)
Describes GLSL version 1.10, as included in OpenGL v2.0, and specified by ivec = ivec2 | ivec3 | ivec4 bool all( bvec )
"The OpenGL® Shading Language", version 1.10.59. Section and page bvec = bvec2 | bvec3 | bvec4 bool any( bvec )
numbers refer to that version of the spec. genType = float | vec2 | vec3 | vec4 bvec equal( vec, vec )
bvec equal( ivec, ivec )
bvec equal( bvec, bvec )
bvec greaterThan( vec, vec )
DATA TYPES (4.1 p16) Angle and Trigonometry Functions (8.1 p51) bvec greaterThan( ivec, ivec )
genType sin( genType ) bvec greaterThanEqual( vec, vec )
float, vec2, vec3, vec4 genType cos( genType ) bvec greaterThanEqual( ivec, ivec )
int, ivec2, ivec3, ivec4 genType tan( genType ) bvec lessThan( vec, vec )
bool, bvec2, bvec3, bvec4 bvec lessThan( ivec, ivec )
mat2, mat3, mat4 genType asin( genType ) bvec lessThanEqual( vec, vec )
void genType acos( genType ) bvec lessThanEqual( ivec, ivec )
sampler1D, sampler2D, sampler3D genType atan( genType, genType ) bvec not( bvec )
samplerCube genType atan( genType ) bvec notEqual( vec, vec )
sampler1DShadow, sampler2DShadow bvec notEqual( ivec, ivec )
genType radians( genType ) bvec notEqual( bvec, bvec )
genType degrees( genType )
DATA TYPE QUALIFIERS (4.3 p22) Texture Lookup Functions (8.7 p56)
Exponential Functions (8.2 p52) Optional bias term is Fragment ONLY
global variable declarations: genType pow( genType, genType ) vec4 texture1D( sampler1D, float [,float bias] )
uniform input to Vertex and Fragment shader from OpenGL or genType exp( genType ) vec4 texture1DProj( sampler1D, vec2 [,float bias] )
application (READ-ONLY) genType log( genType ) vec4 texture1DProj( sampler1D, vec4 [,float bias] )
attribute input per-vertex to Vertex shader from OpenGL or genType exp2( genType )
application (READ-ONLY) genType log2( genType ) vec4 texture2D( sampler2D, vec2 [,float bias] )
varying output from Vertex shader (READ/WRITE), interpolated, genType sqrt( genType ) vec4 texture2DProj( sampler2D, vec3 [,float bias] )
then input to Fragment shader (READ-ONLY) genType inversesqrt( genType ) vec4 texture2DProj( sampler2D, vec4 [,float bias] )
const compile-time constant (READ-ONLY)
Common Functions (8.3 p52) vec4 texture3D( sampler3D, vec3 [,float bias] )
function parameters: genType abs( genType ) vec4 texture3DProj( sampler3D, vec4 [,float bias] )
in value initialized on entry, not copied on return (default) genType ceil( genType )
out copied out on return, but not initialized genType clamp( genType, genType, genType ) vec4 textureCube( samplerCube, vec3 [,float bias] )
inout value initialized on entry, and copied out on return genType clamp( genType, float, float )
const constant function input genType floor( genType ) vec4 shadow1D( sampler1DShadow, vec3 [,float bias] )
genType fract( genType ) vec4 shadow2D( sampler2DShadow, vec3 [,float bias] )
genType max( genType, genType ) vec4 shadow1DProj( sampler1DShadow, vec4 [,float bias] )
VECTOR COMPONENTS (5.5 p 30) genType max( genType, float ) vec4 shadow2DProj( sampler2DShadow, vec4 [,float bias] )
genType min( genType, genType )
component names may not be mixed across sets genType min( genType, float )
x, y, z, w genType mix( genType, genType, genType ) Texture Lookup Functions with LOD (8.7 p56)
r, g, b, a genType mix( genType, genType, float ) Vertex ONLY; ensure GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS > 0
s, t, p, q genType mod( genType, genType ) vec4 texture1DLod( sampler1D, float, float lod )
genType mod( genType, float ) vec4 texture1DProjLod( sampler1D, vec2, float lod )
genType sign( genType ) vec4 texture1DProjLod( sampler1D, vec4, float lod )
genType smoothstep( genType, genType, genType )
PREPROCESSOR (3.3 p9) genType smoothstep( float, float, genType ) vec4 texture2DLod( sampler2D, vec2, float lod )
# genType step( genType, genType ) vec4 texture2DProjLod( sampler2D, vec3, float lod )
#define __LINE__ genType step( float, genType ) vec4 texture2DProjLod( sampler2D, vec4, float lod )
#undef __FILE__ vec4 texture3DProjLod( sampler3D, vec4, float lod )
#if __VERSION__ Geometric Functions (8.4 p54)
#ifdef vec4 ftransform() Vertex ONLY vec4 textureCubeLod( samplerCube, vec3, float lod )
#ifndef vec3 cross( vec3, vec3 )
#else float distance( genType, genType ) vec4 shadow1DLod( sampler1DShadow, vec3, float lod )
#elif float dot( genType, genType ) vec4 shadow2DLod( sampler2DShadow, vec3, float lod )
#endif genType faceforward( genType V, genType I, genType N ) vec4 shadow1DProjLod( sampler1DShadow, vec4, float lod )
#error float length( genType ) vec4 shadow2DProjLod( sampler2DShadow, vec4, float lod )
#pragma genType normalize( genType )
#line genType reflect( genType I, genType N )
genType refract( genType I, genType N, float eta ) Noise Functions (8.9 p60)
float noise1( genType )
GLSL version declaration and extensions protocol: Fragment Processing Functions (8.8 p58) Fragment ONLY vec2 noise2( genType )
#version genType dFdx( genType ) vec3 noise3( genType )
default is "#version 110" (3.3 p11) genType dFdy( genType ) vec4 noise4( genType )
#extension {name | all} : {require | enable | warn | disable} genType fwidth( genType )
default is "#extension all : disable" (3.3 p11)
VERTEX SHADER VARIABLES BUILT-IN UNIFORMs (7.5 p45) access=RO
struct gl_LightModelParameters {
Special Output Variables (7.1 p42) access=RW uniform mat4 gl_ModelViewMatrix; vec4 ambient;
vec4 gl_Position; shader must write uniform mat4 gl_ModelViewProjectionMatrix; };
float gl_PointSize; enable GL_VERTEX_PROGRAM_POINT_SIZE uniform mat4 gl_ProjectionMatrix; uniform gl_LightModelParameters gl_LightModel;
vec4 gl_ClipVertex; uniform mat4 gl_TextureMatrix[gl_MaxTextureCoords];
struct gl_LightModelProducts {
uniform mat4 gl_ModelViewMatrixInverse; vec4 sceneColor;
Attribute Inputs (7.3 p44) access=RO uniform mat4 gl_ModelViewProjectionMatrixInverse; };
attribute vec4 gl_Vertex; uniform mat4 gl_ProjectionMatrixInverse; uniform gl_LightModelProducts gl_FrontLightModelProduct;
attribute vec3 gl_Normal; uniform mat4 gl_TextureMatrixInverse[gl_MaxTextureCoords]; uniform gl_LightModelProducts gl_BackLightModelProduct;
attribute vec4 gl_Color;
attribute vec4 gl_SecondaryColor; uniform mat4 gl_ModelViewMatrixTranspose; struct gl_LightProducts {
attribute vec4 gl_MultiTexCoord0; uniform mat4 gl_ModelViewProjectionMatrixTranspose; vec4 ambient;
attribute vec4 gl_MultiTexCoord1; uniform mat4 gl_ProjectionMatrixTranspose; vec4 diffuse;
attribute vec4 gl_MultiTexCoord2; uniform mat4 gl_TextureMatrixTranspose[gl_MaxTextureCoords]; vec4 specular;
attribute vec4 gl_MultiTexCoord3; };
attribute vec4 gl_MultiTexCoord4; uniform mat4 gl_ModelViewMatrixInverseTranspose; uniform gl_LightProducts gl_FrontLightProduct[gl_MaxLights];
attribute vec4 gl_MultiTexCoord5; uniform mat4 gl_ModelViewProjectionMatrixInverseTranspose; uniform gl_LightProducts gl_BackLightProduct[gl_MaxLights];
attribute vec4 gl_MultiTexCoord6; uniform mat4 gl_ProjectionMatrixInverseTranspose;
attribute vec4 gl_MultiTexCoord7; uniform mat4 gl_TextureMatrixInverseTranspose[gl_MaxTextureCoords]; struct gl_MaterialParameters {
attribute float gl_FogCoord; vec4 emission;
uniform mat3 gl_NormalMatrix; vec4 ambient;
Varying Outputs (7.6 p48) access=RW uniform float gl_NormalScale; vec4 diffuse;
varying vec4 gl_FrontColor; vec4 specular;
varying vec4 gl_BackColor; enable GL_VERTEX_PROGRAM_TWO_SIDE struct gl_DepthRangeParameters { float shininess;
varying vec4 gl_FrontSecondaryColor; float near; };
varying vec4 gl_BackSecondaryColor; float far; uniform gl_MaterialParameters gl_FrontMaterial;
varying vec4 gl_TexCoord[ ]; MAX=gl_MaxTextureCoords float diff; uniform gl_MaterialParameters gl_BackMaterial;
varying float gl_FogFragCoord; };
uniform gl_DepthRangeParameters gl_DepthRange; struct gl_PointParameters {
float size;
struct gl_FogParameters { float sizeMin;
FRAGMENT SHADER VARIABLES vec4 color; float sizeMax;
float density; float fadeThresholdSize;
float start; float distanceConstantAttenuation;
Special Output Variables (7.2 p43) access=RW
float end; float distanceLinearAttenuation;
vec4 gl_FragColor;
float scale; float distanceQuadraticAttenuation;
vec4 gl_FragData[gl_MaxDrawBuffers];
}; };
float gl_FragDepth; DEFAULT=glFragCoord.z
uniform gl_FogParameters gl_Fog; uniform gl_PointParameters gl_Point;

Varying Inputs (7.6 p48) access=RO struct gl_LightSourceParameters { uniform vec4 gl_TextureEnvColor[gl_MaxTextureUnits]; (1)
varying vec4 gl_Color; vec4 ambient;
varying vec4 gl_SecondaryColor; vec4 diffuse; uniform vec4 gl_ClipPlane[gl_MaxClipPlanes];
varying vec4 gl_TexCoord[ ]; MAX=gl_MaxTextureCoords vec4 specular;
varying float gl_FogFragCoord; vec4 position; uniform vec4 gl_EyePlaneS[gl_MaxTextureCoords];
vec4 halfVector; uniform vec4 gl_EyePlaneT[gl_MaxTextureCoords];
vec3 spotDirection; uniform vec4 gl_EyePlaneR[gl_MaxTextureCoords];
Special Input Variables (7.2 p43) access=RO float spotExponent; uniform vec4 gl_EyePlaneQ[gl_MaxTextureCoords];
vec4 gl_FragCoord; pixel coordinates float spotCutoff;
bool gl_FrontFacing; float spotCosCutoff; uniform vec4 gl_ObjectPlaneS[gl_MaxTextureCoords];
float constantAttenuation; uniform vec4 gl_ObjectPlaneT[gl_MaxTextureCoords];
float linearAttenuation; uniform vec4 gl_ObjectPlaneR[gl_MaxTextureCoords];
float quadraticAttenuation; uniform vec4 gl_ObjectPlaneQ[gl_MaxTextureCoords];
BUILT-IN CONSTANTS (7.4 p44)
};
uniform gl_LightSourceParameters gl_LightSource[gl_MaxLights];
const int gl_MaxVertexUniformComponents;
const int gl_MaxFragmentUniformComponents;
const int gl_MaxVertexAttribs;
const int gl_MaxVaryingFloats;
const int gl_MaxDrawBuffers; OpenSceneGraph Preset Uniforms Fine print / disclaimer
const int gl_MaxTextureCoords; Copyright 2005 Mike Weiblen http://mew.cx/
as of OSG 1.0 Please send feedback/corrections/comments to glsl@mew.cx
const int gl_MaxTextureUnits; int osg_FrameNumber; OpenGL is a registered trademark of Silicon Graphics Inc.
const int gl_MaxTextureImageUnits; float osg_FrameTime; Except as noted below, if discrepancies between this guide and the
const int gl_MaxVertexTextureImageUnits; float osg_DeltaFrameTime; GLSL specification, believe the spec!
const int gl_MaxCombinedTextureImageUnits; mat4 osg_ViewMatrix; Revised 2005-11-26
const int gl_MaxLights; mat4 osg_ViewMatrixInverse;
const int gl_MaxClipPlanes; Notes
1. Corrects a typo in the OpenGL 2.0 specification.
OpenGL Shading Language (GLSL) GEOMETRY SHADER VARIABLES
Quick Reference Guide Constant buit-in
Describes the GLSL version 1.2
int gl_VerticesIn number of vertices belonging to the primitive
Sébastien Barbier – January 2009.

Special Output Variables


DATA TYPES vec4 gl_Position; shader must write
float gl_PointSize;
unsigned int, uvec2, uvec3, uvec4
vec4 gl_ClipVertex;
sampler1DArray, sampler2DArray
int gl_PrimitiveID;
sampler1DArrayShadow, sampler2DArrayShadow, samplerCubeShadow
int gl_Layer;
isampler1D, isampler2D, isampler3D, isamplerCube, isampler2DRect
isampler1DArray, isampler2DArray
Varying Outputs
usampler1D, usampler2D, usampler3D, usamplerCube, usampler2DRect
varying out vec4 gl_FrontColor;
usampler1DArray, usampler2DArray
varying out vec4 gl_BackColor;
samplerBuffer, isamplerBuffer, usamplerBuffer
varying out vec4 gl_FrontSecondaryColor;
varying out vec4 gl_BackSecondaryColor;
DATA TYPE QUALIFIERS varying out vec4 gl_TexCoord[];
flat varying varying out vec4 gl_FogFragCoord;
noperspective varying
centroid varying Varying Inputs
varying in vec4 gl_FrontColorIn[gl_VerticesIn];
varying in vec4 gl_BackColorIn[gl_VerticesIn];
VERTEX/FRAGMENT SHADER VARIABLES varying in vec4 gl_FrontSecondaryColorIn[gl_VerticesIn];
varying in vec4 gl_BackSecondaryColorIn[gl_VerticesIn];
Attribute inputs access = RO
varying in vec4 gl_TexCoordIn[gl_VerticesIn][];
Vertex
varying in float gl_FogFragCoordIn[gl_VerticesIn];
int gl_VertexID
varying in vec4 gl_PositionIn[gl_VerticesIn];
int gl_InstanceID
varying in float gl_PointSizeIn[gl_VerticesIn];
Fragment
varying in vec4 gl_ClipVertexIn[gl_VerticesIn];
int gl_PrimitiveID
Functions
BUILT-IN FUNCTIONS void EmitVertex();
% : modulo void EndPrimitive();
&, |, ^, ~, << , >> : bit-wise operations
For texture access:
vec4 texture1D(sampler1D sampler, float coord [, float bias])
ivec4 texture1D(isampler1D sampler, float coord [, float bias])
uvec4 texture1D(usampler1D sampler, float coord [, float bias])

More ? cf. EXT_gpu_shader4, g80specs.pdf p117-124

You might also like