Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Updated programs and adjusted Material to work with GLSL>150

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