Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/GLSL120/BumpMapping/Example_BumpMappingSpecularVp.glsl @ 12115

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

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

File size: 1.3 KB
Line 
1#version 120
2
3// General functions
4// parameters
5uniform vec4 lightPosition; // object space
6uniform vec3 eyePosition;   // object space
7uniform mat4 worldViewProj;
8
9attribute vec4 vertex;
10attribute vec3 normal;
11attribute vec3 tangent;
12attribute vec4 uv0;
13
14varying vec4 oUv0;
15varying vec3 oTSLightDir;
16varying vec3 oTSHalfAngle;
17
18/* Vertex program which includes specular component */
19void main()
20{
21        // calculate output position
22        gl_Position = worldViewProj * vertex;
23
24        // pass the main uvs straight through unchanged
25        oUv0 = uv0;
26
27        // calculate tangent space light vector
28        // Get object space light direction
29        vec3 lightDir = normalize(lightPosition.xyz - (vertex * lightPosition.w).xyz);
30
31        // Calculate the binormal (NB we assume both normal and tangent are
32        // already normalised)
33        vec3 binormal = cross(normal, tangent);
34       
35        // Form a rotation matrix out of the vectors
36        mat3 rotation = mat3(vec3(tangent[0], binormal[0], normal[0]),
37                                                vec3(tangent[1], binormal[1], normal[1]),
38                                                vec3(tangent[2], binormal[2], normal[2]));
39       
40        // Transform the light vector according to this matrix
41        oTSLightDir = rotation * lightDir;
42
43        // Calculate half-angle in tangent space
44        vec3 eyeDir = normalize(eyePosition - vertex.xyz);
45        vec3 halfAngle = normalize(eyeDir + lightDir);
46        oTSHalfAngle = rotation * halfAngle;
47}
Note: See TracBrowser for help on using the repository browser.