Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/Example/GLSLES/Example_BumpMappingVp.glsles @ 12091

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

Updated programs and adjusted Material to work with GLSL>150

File size: 1.4 KB
Line 
1#version 100
2precision mediump int;
3precision mediump float;
4
5/* Bump mapping vertex program
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// parameters
12uniform vec4 lightPosition; // object space
13uniform mat4 worldViewProj;
14
15attribute vec4 vertex;
16attribute vec3 normal;
17attribute vec3 tangent;
18attribute vec2 uv0;
19
20varying vec2 oUv0;
21varying vec3 oTSLightDir;
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);
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}
Note: See TracBrowser for help on using the repository browser.