#version 100 precision mediump int; precision mediump float; // General functions // parameters uniform vec4 lightPosition; // object space uniform vec3 eyePosition; // object space uniform mat4 worldViewProj; attribute vec4 position; attribute vec3 normal; attribute vec3 tangent; attribute vec4 uv0; varying vec4 oUv0; varying vec3 oTSLightDir; varying vec3 oTSHalfAngle; /* Vertex program which includes specular component */ 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 vec3 lightDir = normalize(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, binormal, normal); // Transform the light vector according to this matrix oTSLightDir = rotation * lightDir; // Calculate half-angle in tangent space vec3 eyeDir = normalize(eyePosition - position.xyz); vec3 halfAngle = normalize(eyeDir + lightDir); oTSHalfAngle = rotation * halfAngle; }