Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/Example/GLSLES/Example_BumpMappingShadowRcvVp.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.5 KB
Line 
1#version 100
2precision mediump int;
3precision mediump float;
4
5/* Bump mapping vertex program for shadow receiving
6   In this program, we want to calculate the tangent space light vector
7   on a per-vertex level which will get passed to the fragment program,
8   or to the fixed function dot3 operation, to produce the per-pixel
9   lighting effect.
10*/
11
12// parameters
13uniform vec4 lightPosition; // object space
14uniform mat4 worldViewProj;
15uniform mat4 worldMatrix;
16uniform mat4 texViewProj;
17
18attribute vec4 vertex;
19attribute vec3 normal;
20attribute vec3 tangent;
21attribute vec4 uv0;
22
23varying vec4 uvproj;
24varying vec4 oUv0;
25varying vec3 oTSLightDir;
26
27void main()
28{
29        // Calculate output position
30        gl_Position = worldViewProj * vertex;
31
32        // Pass the main uvs straight through unchanged
33        oUv0 = uv0;
34
35        // Calculate tangent space light vector
36        // Get object space light direction
37        // Non-normalised since we'll do that in the fragment program anyway
38        vec3 lightDir = lightPosition.xyz - (vertex * lightPosition.w).xyz;
39
40        // Calculate the binormal (NB we assume both normal and tangent are
41        // already normalised)
42        vec3 binormal = cross(normal, tangent);
43       
44        // Form a rotation matrix out of the vectors, column major for glsl es
45        mat3 rotation = mat3(vec3(tangent[0], binormal[0], normal[0]),
46                                                vec3(tangent[1], binormal[1], normal[1]),
47                                                vec3(tangent[2], binormal[2], normal[2]));
48       
49        // Transform the light vector according to this matrix
50        oTSLightDir = rotation * lightDir;
51
52        // Projection
53        uvproj = texViewProj * (worldMatrix * vertex);
54}
Note: See TracBrowser for help on using the repository browser.