Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/Example/GLSLES/OffsetMappingVp.glsles @ 12091

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

Updated programs and adjusted Material to work with GLSL>150

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