Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/Example/GLSL150/Example_BumpMappingSpecularVp.glsl @ 12091

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

Reorganised shader programs

File size: 1.3 KB
Line 
1#version 150
2
3// General functions
4// parameters
5uniform vec4 lightPosition; // object space
6uniform vec3 eyePosition;   // object space
7uniform mat4 worldViewProj;
8
9in vec4 vertex;
10in vec3 normal;
11in vec3 tangent;
12in vec4 uv0;
13
14out vec4 oUv0;
15out vec3 oTSLightDir;
16out 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.