Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/GLSL120/BumpMapVPTangentParity.glsl @ 12412

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

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

File size: 1.4 KB
Line 
1#version 120
2
3/* Bump mapping vertex program
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// parameters
10uniform vec4 lightPosition; // object space
11uniform mat4 worldViewProj;
12
13attribute vec4 vertex;
14attribute vec3 normal;
15attribute vec4 tangent;
16attribute vec2 uv0;
17
18varying vec2 oUv0;
19varying vec3 oTSLightDir;
20
21void main()
22{
23    // Calculate output position
24    gl_Position = worldViewProj * vertex;
25
26    // Pass the main uvs straight through unchanged
27    oUv0 = uv0;
28
29    // Calculate tangent space light vector
30    // Get object space light direction
31    // Non-normalised since we'll do that in the fragment program anyway
32    vec3 lightDir = lightPosition.xyz - (vertex * lightPosition.w).xyz;
33
34    // Calculate the binormal (NB we assume both normal and tangent are
35    // already normalised)
36
37    // Fixed handedness
38    vec3 binormal = cross(normal, tangent.xyz) * tangent.www;
39
40    // Form a rotation matrix out of the vectors, column major for glsl es
41    mat3 rotation = mat3(vec3(tangent[0], binormal[0], normal[0]),
42                          vec3(tangent[1], binormal[1], normal[1]),
43                          vec3(tangent[2], binormal[2], normal[2]));
44
45    // Transform the light vector according to this matrix
46    oTSLightDir = rotation * lightDir;
47}
Note: See TracBrowser for help on using the repository browser.