#version 100 precision mediump int; precision mediump float; attribute vec3 tangent; attribute vec4 position; attribute vec3 normal; uniform mat4 world; uniform mat4 worldViewProj; uniform mat4 texViewProj; uniform vec4 lightPosition; // object space uniform vec4 shadowDepthRange; varying vec3 tangentLightDir; varying vec4 vUv0; varying vec4 vUv1; attribute vec4 uv0; attribute vec4 uv1; void main() { gl_Position = position * worldViewProj; vec4 worldPos = world * position; // Get object space light direction vec3 lightDir = normalize(lightPosition.xyz - (position.xyz * lightPosition.w)); // calculate shadow map coords vUv0 = texViewProj * worldPos; #if LINEAR_RANGE // adjust by fixed depth bias, rescale into range vUv0.z = (uv0.z - shadowDepthRange.x) * shadowDepthRange.w; #endif vUv1 = uv1; // Calculate the binormal (NB we assume both normal and tangent are // already normalised) vec3 binormal = cross(normal, tangent); // Form a rotation matrix out of the vectors mat3 rotation = mat3(tangent, binormal, normal); // Transform the light vector according to this matrix tangentLightDir = normalize(rotation * lightDir); }