Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/Example/GLSL150/BumpMapVPTangentParity.glsl @ 12083

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

Reorganised shader programs

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