#version 130 #define MAX_LIGHTS 2 precision highp float; uniform struct Light { vec4 Diffuse; vec4 Specular; vec4 Position; float InverseRadius; } Lights[MAX_LIGHTS]; uniform vec3 CameraPosition; #define LIGHT_COUNT 2 #define SHADOWS 1 in vec3 Position; in vec3 Normal; in vec3 Tangent; in vec2 TexCoord; out vec2 TextureCoordinates0; out vec3 eyeVec; out vec3 lightVec[LIGHT_COUNT]; #ifdef SHADOWS out vec3 shadowVec[LIGHT_COUNT]; #endif void main() { vec4 position = vec4(Position, 1.0); TextureCoordinates0 = TexCoord.xy; vec3 normal = normalize(gl_NormalMatrix * Normal); vec3 tangent = normalize(gl_NormalMatrix * Tangent); vec3 bitangent = cross(normal, tangent); vec4 vertex = (gl_ModelViewMatrix * position); for (int i = 0; i < LIGHT_COUNT; i++) { vec3 temp = Lights[i].InverseRadius * (Lights[i].Position - position).xyz; vec3 temp2 = Lights[i].InverseRadius * (gl_ModelViewMatrix * Lights[i].Position - vertex).xyz; #ifdef SHADOWS shadowVec[i] = -temp; #endif // Optimization, calculate dot products rather than building TBN matrix lightVec[i].x = dot(temp2, tangent); lightVec[i].y = dot(temp2, bitangent); lightVec[i].z = dot(temp2, normal); } vec3 temp = -vertex.xyz; eyeVec.x = dot(temp, tangent); eyeVec.y = dot(temp, bitangent); eyeVec.z = dot(temp, normal); gl_Position = gl_ModelViewProjectionMatrix * position; }