#version 100 precision mediump int; precision mediump float; /* Bump mapping vertex program for shadow receiving In this program, we want to calculate the tangent space light vector on a per-vertex level which will get passed to the fragment program, or to the fixed function dot3 operation, to produce the per-pixel lighting effect. */ // parameters uniform vec4 lightPosition; // object space uniform mat4 worldViewProj; uniform mat4 worldMatrix; uniform mat4 texViewProj; attribute vec4 position; attribute vec3 normal; attribute vec3 tangent; attribute vec4 uv0; varying vec4 uvproj; varying vec4 oUv0; varying vec3 oTSLightDir; void main() { // calculate output position gl_Position = worldViewProj * position; // pass the main uvs straight through unchanged oUv0 = uv0; // calculate tangent space light vector // Get object space light direction // Non-normalised since we'll do that in the fragment program anyway vec3 lightDir = lightPosition.xyz - (position * lightPosition.w).xyz; // Calculate the binormal (NB we assume both normal and tangent are // already normalised) // NB looks like nvidia cross params are BACKWARDS to what you'd expect // this equates to NxT, not TxN vec3 binormal = cross(tangent, normal); // Form a rotation matrix out of the vectors mat3 rotation = mat3(tangent.xyz, binormal, normal); // Transform the light vector according to this matrix oTSLightDir = rotation * lightDir; // Projection uvproj = worldMatrix * position; uvproj = texViewProj * uvproj; }