Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/archive/skybox/Media/materials/programs/OffsetMappingVp.glsl @ 11183

Last change on this file since 11183 was 390, checked in by landauf, 17 years ago

added materials

File size: 1.8 KB
Line 
1attribute vec3 tangent;
2
3uniform vec4 lightPosition; // object space
4uniform vec4 lightPosition1; // object space
5uniform vec4 eyePosition;   // object space
6uniform vec4 spotDirection; // object space
7uniform vec4 spotDirection1; // object space
8uniform mat4 worldViewProj; // not actually used but here for compat with HLSL
9uniform mat4 worldMatrix;
10uniform mat4 texViewProj1;
11uniform mat4 texViewProj2;
12
13
14varying vec3 tangentEyeDir;
15varying vec3 tangentLightDir[2];
16varying vec3 tangentSpotDir[2];
17varying vec4 shadowUV[2];
18
19void main()
20{
21        gl_Position = ftransform();
22
23        vec4 worldPos = worldMatrix * gl_Vertex;
24
25        shadowUV[0] = texViewProj1 * worldPos;
26        shadowUV[1] = texViewProj2 * worldPos;
27
28        // pass the main uvs straight through unchanged
29        gl_TexCoord[0] = gl_MultiTexCoord0;
30
31        // calculate tangent space light vector
32        // Get object space light direction
33    vec3 lightDir = normalize(lightPosition.xyz -  (gl_Vertex.xyz * lightPosition.w));
34        vec3 lightDir1 = normalize(lightPosition1.xyz -  (gl_Vertex.xyz * lightPosition1.w));
35       
36        vec3 eyeDir = (eyePosition - gl_Vertex).xyz; 
37
38        // Calculate the binormal (NB we assume both normal and tangent are
39        // already normalised)
40        vec3 binormal = cross(gl_Normal, tangent); 
41
42        // Form a rotation matrix out of the vectors
43        mat3 rotation = mat3(tangent, binormal, gl_Normal); 
44   
45        // Transform the light vector according to this matrix
46        tangentLightDir[0] = normalize(rotation * lightDir); 
47        tangentLightDir[1] = normalize(rotation * lightDir1); 
48        // Invert the Y on the eye dir since we'll be using this to alter UVs and
49        // GL has Y inverted
50        tangentEyeDir = normalize(rotation * eyeDir) * vec3(1, -1, 1); 
51
52        tangentSpotDir[0] = normalize(rotation * -spotDirection.xyz);
53        tangentSpotDir[1] = normalize(rotation * -spotDirection1.xyz); 
54}
Note: See TracBrowser for help on using the repository browser.