Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/GLSL120/BumpMapping/Example_BumpMappingShadowRcvVp.glsl @ 12115

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

Changed folder structure, deletet some unused files and cleaned up code

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