Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/GLSL120/OffsetMappingVp.glsl @ 12202

Last change on this file since 12202 was 12115, checked in by wiesep, 6 years ago

Changed folder structure, deletet some unused files and cleaned up code

File size: 1.4 KB
Line 
1#version 120
2
3uniform vec4 lightPosition; // object space
4uniform vec3 eyePosition;   // object space
5uniform mat4 worldViewProj; // not actually used but here for compat with HLSL
6
7varying vec3 oEyeDir;
8varying vec3 oLightDir;
9varying vec3 oHalfAngle;
10varying vec4 oUv0;
11
12attribute vec3 normal;
13attribute vec3 tangent;
14attribute vec4 uv0;
15attribute vec4 position;
16
17/* Vertex program that moves light and eye vectors into texture tangent space at vertex */
18
19void main()
20{
21    // Calculate output position
22    gl_Position = worldViewProj * position;
23
24    // Pass the main uvs straight through unchanged
25    oUv0 = uv0;
26
27    vec3 lightDir = lightPosition.xyz - (position.xyz * lightPosition.w);
28
29    vec3 eyeDir = eyePosition - position.xyz;
30
31    // Calculate the binormal (NB we assume both normal and tangent are
32    // already normalised)
33    // NB looks like nvidia cross params are BACKWARDS to what you'd expect
34    // this equates to NxT, not TxN
35    vec3 localbinormal = cross(tangent, normal);
36
37    // Form a rotation matrix out of the vectors, column major for glsl es
38        mat3 TBN = mat3(vec3(tangent[0], localbinormal[0], normal[0]),
39                                                vec3(tangent[1], localbinormal[1], normal[1]),
40                                                vec3(tangent[2], localbinormal[2], normal[2]));
41   
42
43    // Transform the light vector according to this matrix
44    oLightDir = normalize(TBN * lightDir);
45    oEyeDir = normalize(TBN * eyeDir);
46    oHalfAngle = normalize(oEyeDir + oLightDir);
47}
Note: See TracBrowser for help on using the repository browser.