| 1 |
// -*- mode: C; -*- |
| 2 |
// Licence: GPL v2 |
| 3 |
// © Emilian Huminiuc and Vivian Meazza 2011 |
| 4 |
#version 120 |
| 5 |
|
| 6 |
varying vec3 rawpos; |
| 7 |
varying vec3 VNormal; |
| 8 |
varying vec3 VTangent; |
| 9 |
varying vec3 VBinormal; |
| 10 |
varying vec3 vViewVec; |
| 11 |
varying vec3 reflVec; |
| 12 |
varying vec3 vertVec; |
| 13 |
|
| 14 |
varying float alpha; |
| 15 |
|
| 16 |
attribute vec3 tangent; |
| 17 |
attribute vec3 binormal; |
| 18 |
|
| 19 |
uniform float pitch; |
| 20 |
uniform float roll; |
| 21 |
uniform float hdg; |
| 22 |
uniform int refl_dynamic; |
| 23 |
uniform int nmap_enabled; |
| 24 |
uniform int shader_qual; |
| 25 |
|
| 26 |
//////Fog Include/////////// |
| 27 |
// uniform int fogType; |
| 28 |
// void fog_Func(int type); |
| 29 |
//////////////////////////// |
| 30 |
|
| 31 |
void setupShadows(vec4 eyeSpacePos); |
| 32 |
|
| 33 |
void rotationMatrixPR(in float sinRx, in float cosRx, in float sinRy, in float cosRy, out mat4 rotmat) |
| 34 |
{ |
| 35 |
rotmat = mat4( cosRy , sinRx * sinRy , cosRx * sinRy, 0.0, |
| 36 |
0.0 , cosRx , -sinRx * cosRx, 0.0, |
| 37 |
-sinRy, sinRx * cosRy, cosRx * cosRy , 0.0, |
| 38 |
0.0 , 0.0 , 0.0 , 1.0 ); |
| 39 |
} |
| 40 |
|
| 41 |
void rotationMatrixH(in float sinRz, in float cosRz, out mat4 rotmat) |
| 42 |
{ |
| 43 |
rotmat = mat4( cosRz, -sinRz, 0.0, 0.0, |
| 44 |
sinRz, cosRz, 0.0, 0.0, |
| 45 |
0.0 , 0.0 , 1.0, 0.0, |
| 46 |
0.0 , 0.0 , 0.0, 1.0 ); |
| 47 |
} |
| 48 |
|
| 49 |
void main(void) |
| 50 |
{ |
| 51 |
rawpos = gl_Vertex.xyz; |
| 52 |
vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex; |
| 53 |
//fog_Func(fogType); |
| 54 |
|
| 55 |
VNormal = normalize(gl_NormalMatrix * gl_Normal); |
| 56 |
|
| 57 |
vec3 n = normalize(gl_Normal); |
| 58 |
vec3 tempTangent = cross(n, vec3(1.0,0.0,0.0)); |
| 59 |
vec3 tempBinormal = cross(n, tempTangent); |
| 60 |
|
| 61 |
if (nmap_enabled > 0){ |
| 62 |
tempTangent = tangent; |
| 63 |
tempBinormal = binormal; |
| 64 |
} |
| 65 |
|
| 66 |
VTangent = normalize(gl_NormalMatrix * tempTangent); |
| 67 |
VBinormal = normalize(gl_NormalMatrix * tempBinormal); |
| 68 |
vec3 t = tempTangent; |
| 69 |
vec3 b = tempBinormal; |
| 70 |
|
| 71 |
// Super hack: if diffuse material alpha is less than 1, assume a |
| 72 |
// transparency animation is at work |
| 73 |
if (gl_FrontMaterial.diffuse.a < 1.0) |
| 74 |
alpha = gl_FrontMaterial.diffuse.a; |
| 75 |
else |
| 76 |
alpha = gl_Color.a; |
| 77 |
|
| 78 |
// Vertex in eye coordinates |
| 79 |
vertVec = ecPosition.xyz; |
| 80 |
vViewVec.x = dot(t, vertVec); |
| 81 |
vViewVec.y = dot(b, vertVec); |
| 82 |
vViewVec.z = dot(n, vertVec); |
| 83 |
|
| 84 |
// calculate the reflection vector |
| 85 |
vec4 reflect_eye = vec4(reflect(vertVec, VNormal), 0.0); |
| 86 |
vec3 reflVec_stat = normalize(gl_ModelViewMatrixInverse * reflect_eye).xyz; |
| 87 |
if (refl_dynamic > 0){ |
| 88 |
//prepare rotation matrix |
| 89 |
mat4 RotMatPR; |
| 90 |
mat4 RotMatH; |
| 91 |
float _roll = roll; |
| 92 |
if (_roll>90.0 || _roll < -90.0) |
| 93 |
{ |
| 94 |
_roll = -_roll; |
| 95 |
} |
| 96 |
float cosRx = cos(radians(_roll)); |
| 97 |
float sinRx = sin(radians(_roll)); |
| 98 |
float cosRy = cos(radians(-pitch)); |
| 99 |
float sinRy = sin(radians(-pitch)); |
| 100 |
float cosRz = cos(radians(hdg)); |
| 101 |
float sinRz = sin(radians(hdg)); |
| 102 |
rotationMatrixPR(sinRx, cosRx, sinRy, cosRy, RotMatPR); |
| 103 |
rotationMatrixH(sinRz, cosRz, RotMatH); |
| 104 |
vec3 reflVec_dyn = (RotMatH * (RotMatPR * normalize(gl_ModelViewMatrixInverse * reflect_eye))).xyz; |
| 105 |
|
| 106 |
reflVec = reflVec_dyn; |
| 107 |
} else { |
| 108 |
reflVec = reflVec_stat; |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
gl_FrontColor = gl_FrontMaterial.emission + gl_Color |
| 113 |
* (gl_LightModel.ambient + gl_LightSource[0].ambient); |
| 114 |
|
| 115 |
gl_Position = ftransform(); |
| 116 |
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; |
| 117 |
|
| 118 |
setupShadows(ecPosition); |
| 119 |
} |