Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/Example/GLSL150/OffsetMappingVp.glsl @ 12083

Last change on this file since 12083 was 12083, checked in by wiesep, 5 years ago

Reorganised shader programs

File size: 1.3 KB
Line 
1#version 150
2
3uniform vec4 lightPosition; // object space
4uniform vec3 eyePosition;   // object space
5uniform mat4 worldViewProj; // not actually used but here for compat with HLSL
6
7out vec3 oEyeDir;
8out vec3 oLightDir;
9out vec3 oHalfAngle;
10out vec4 oUv0;
11
12in vec3 normal;
13in vec3 tangent;
14in vec4 uv0;
15in 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(tangent, localbinormal, normal);
39   
40    // Transform the light vector according to this matrix
41        oLightDir = normalize(TBN * lightDir); 
42        oEyeDir = normalize(TBN * eyeDir); 
43    oHalfAngle = normalize(oEyeDir + oLightDir);
44}
45
Note: See TracBrowser for help on using the repository browser.