Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Updated programs and adjusted Material to work with GLSL>150

File size: 1.3 KB
Line 
1#version 100
2precision mediump int;
3precision mediump float;
4
5// General functions
6// parameters
7uniform vec4 lightPosition; // object space
8uniform vec3 eyePosition;   // object space
9uniform mat4 worldViewProj;
10
11attribute vec4 vertex;
12attribute vec3 normal;
13attribute vec3 tangent;
14attribute vec4 uv0;
15
16varying vec4 oUv0;
17varying vec3 oTSLightDir;
18varying vec3 oTSHalfAngle;
19
20/* Vertex program which includes specular component */
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        vec3 lightDir = normalize(lightPosition.xyz - (vertex * lightPosition.w).xyz);
32
33        // Calculate the binormal (NB we assume both normal and tangent are
34        // already normalised)
35        vec3 binormal = cross(normal, tangent);
36       
37        // Form a rotation matrix out of the vectors
38        mat3 rotation = mat3(vec3(tangent[0], binormal[0], normal[0]),
39                                                vec3(tangent[1], binormal[1], normal[1]),
40                                                vec3(tangent[2], binormal[2], normal[2]));
41       
42        // Transform the light vector according to this matrix
43        oTSLightDir = rotation * lightDir;
44
45        // Calculate half-angle in tangent space
46        vec3 eyeDir = normalize(eyePosition - vertex.xyz);
47        vec3 halfAngle = normalize(eyeDir + lightDir);
48        oTSHalfAngle = rotation * halfAngle;
49}
Note: See TracBrowser for help on using the repository browser.