// GL Shading Language version 1.0 Vertex Shader // Orion Sky Lawlor, olawlor@acm.org, 2006/08/31 (Public Domain) // C++/vertex shader interface uniform float texscale; uniform mat4 modelMat; // Object transform (world from model) uniform mat4 clipMat; // Overall clip-space transform (clip from model) uniform vec4 cameraLoc; // Location of camera // Vertex/fragment shader interface: varying vec4 color; // Material diffuse color varying vec3 position; // World-space coordinates of object varying vec3 normal; // Surface normal varying vec3 cameraDir; // Points toward camera varying vec2 texCoord; // Texture coordinates // Input: gl_Vertex. Output: gl_Position. void main(void) { // Output "varying" for fragment shader: color=gl_Color; // Transform position and normal to world coordinates position=vec3(modelMat*gl_Vertex); normal=normalize(vec3(modelMat*vec4(gl_Normal,0))); // Compute vector pointing toward camera cameraDir=normalize(vec3(cameraLoc)-position); texCoord=(vec2(position)*0.5+0.5)*texscale; /* shift from [-1,+1] to [0,texscale] */ // Compute clip coordinates straight from model coordinates gl_Position = clipMat*gl_Vertex; }