Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Reorganised shader programs

File size: 1.3 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;
12
13in vec4 vertex;
14in vec3 normal;
15in vec3 tangent;
16in vec4 uv0;
17
18out vec4 oUv0;
19out 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);
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.