Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/Example/GLSL120/OffsetMappingShadowsVp.glsl @ 12096

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

Updated programs and adjusted Material to work with GLSL>150

File size: 1.9 KB
Line 
1#version 120
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
13varying vec3 tangentEyeDir;
14varying vec3 tangentLightDir[2];
15varying vec3 tangentSpotDir[2];
16varying vec4 shadowUV[2];
17varying vec4 oUv0;
18
19attribute vec3 tangent;
20attribute vec4 position;
21attribute vec3 normal;
22attribute vec4 uv0;
23
24void main()
25{
26        gl_Position = worldViewProj * position;
27
28        vec4 worldPos = worldMatrix * position;
29
30    oUv0 = uv0;
31
32        shadowUV[0] = texViewProj1 * worldPos;
33        shadowUV[1] = texViewProj2 * worldPos;
34
35        // calculate tangent space light vector
36        // Get object space light direction
37    vec3 lightDir = normalize(lightPosition.xyz -  (position.xyz * lightPosition.w));
38        vec3 lightDir1 = normalize(lightPosition1.xyz -  (position.xyz * lightPosition1.w));
39       
40        vec3 eyeDir = (eyePosition - position).xyz; 
41
42        // Calculate the binormal (NB we assume both normal and tangent are
43        // already normalised)
44        vec3 binormal = cross(normal, tangent); 
45
46        // Form a rotation matrix out of the vectors, column major for glsl es
47        mat3 rotation = mat3(vec3(tangent[0], binormal[0], normal[0]),
48                                                vec3(tangent[1], binormal[1], normal[1]),
49                                                vec3(tangent[2], binormal[2], normal[2]));
50   
51        // Transform the light vector according to this matrix
52        tangentLightDir[0] = normalize(rotation * lightDir); 
53        tangentLightDir[1] = normalize(rotation * lightDir1); 
54        // Invert the Y on the eye dir since we'll be using this to alter UVs and
55        // GL has Y inverted
56        tangentEyeDir = normalize(rotation * eyeDir) * vec3(1.0, -1.0, 1.0); 
57
58        tangentSpotDir[0] = normalize(rotation * -spotDirection.xyz);
59        tangentSpotDir[1] = normalize(rotation * -spotDirection1.xyz); 
60}
Note: See TracBrowser for help on using the repository browser.