File: Parallax_VS.glsl

package info (click to toggle)
opentk 1.0.20101006%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 38,896 kB
  • ctags: 68,704
  • sloc: cs: 424,330; xml: 96,546; ansic: 3,597; makefile: 24
file content (35 lines) | stat: -rw-r--r-- 1,073 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright (c) 2008 the OpenTK Team. See license.txt for legal bla

// custom vertex attribute
attribute vec3 AttributeTangent; 

// world uniforms
uniform vec3 Light_Position;
uniform vec3 Camera_Position;

// MUST be written to for FS
varying vec3 VaryingLightVector; 
varying vec3 VaryingEyeVector;

void main()
{
  gl_Position = ftransform();
  gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;

  vec3 nor = normalize( gl_NormalMatrix * gl_Normal );
  vec3 tan = normalize( gl_NormalMatrix * AttributeTangent );
  vec3 bi = cross(nor, tan);
  
  // need positions in tangent space
  vec3 vertex = vec3( gl_ModelViewMatrix * gl_Vertex );

  vec3 temp = Light_Position - vertex;
  VaryingLightVector.x = dot(temp, tan); // optimization, calculate dot products rather than building TBN matrix
  VaryingLightVector.y = dot(temp, bi);
  VaryingLightVector.z = dot(temp, nor);

  temp = Camera_Position - vertex;
  VaryingEyeVector.x = dot(temp, tan);
  VaryingEyeVector.y = dot(temp, bi);
  VaryingEyeVector.z = dot(temp, nor);
}