Debian Codegraph @

Shaders/space-ALS-ultra.vert

raw
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 rotationMatrixPR(in float sinRx, in float cosRx, in float sinRy, in float cosRy, out mat4 rotmat)
32 {
33 rotmat = mat4( cosRy , sinRx * sinRy , cosRx * sinRy, 0.0,
34 0.0 , cosRx , -sinRx * cosRx, 0.0,
35 -sinRy, sinRx * cosRy, cosRx * cosRy , 0.0,
36 0.0 , 0.0 , 0.0 , 1.0 );
37 }
38
39 void rotationMatrixH(in float sinRz, in float cosRz, out mat4 rotmat)
40 {
41 rotmat = mat4( cosRz, -sinRz, 0.0, 0.0,
42 sinRz, cosRz, 0.0, 0.0,
43 0.0 , 0.0 , 1.0, 0.0,
44 0.0 , 0.0 , 0.0, 1.0 );
45 }
46
47 void main(void)
48 {
49 rawpos = gl_Vertex.xyz;
50 vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;
51 //fog_Func(fogType);
52
53 VNormal = normalize(gl_NormalMatrix * gl_Normal);
54
55 vec3 n = normalize(gl_Normal);
56 vec3 tempTangent = cross(n, vec3(1.0,0.0,0.0));
57 vec3 tempBinormal = cross(n, tempTangent);
58
59 if (nmap_enabled > 0){
60 tempTangent = tangent;
61 tempBinormal = binormal;
62 }
63
64 VTangent = normalize(gl_NormalMatrix * tempTangent);
65 VBinormal = normalize(gl_NormalMatrix * tempBinormal);
66 vec3 t = tempTangent;
67 vec3 b = tempBinormal;
68
69 // Super hack: if diffuse material alpha is less than 1, assume a
70 // transparency animation is at work
71 if (gl_FrontMaterial.diffuse.a < 1.0)
72 alpha = gl_FrontMaterial.diffuse.a;
73 else
74 alpha = gl_Color.a;
75
76 // Vertex in eye coordinates
77 vertVec = ecPosition.xyz;
78 vViewVec.x = dot(t, vertVec);
79 vViewVec.y = dot(b, vertVec);
80 vViewVec.z = dot(n, vertVec);
81
82 // calculate the reflection vector
83 vec4 reflect_eye = vec4(reflect(vertVec, VNormal), 0.0);
84 vec3 reflVec_stat = normalize(gl_ModelViewMatrixInverse * reflect_eye).xyz;
85 if (refl_dynamic > 0){
86 //prepare rotation matrix
87 mat4 RotMatPR;
88 mat4 RotMatH;
89 float _roll = roll;
90 if (_roll>90.0 || _roll < -90.0)
91 {
92 _roll = -_roll;
93 }
94 float cosRx = cos(radians(_roll));
95 float sinRx = sin(radians(_roll));
96 float cosRy = cos(radians(-pitch));
97 float sinRy = sin(radians(-pitch));
98 float cosRz = cos(radians(hdg));
99 float sinRz = sin(radians(hdg));
100 rotationMatrixPR(sinRx, cosRx, sinRy, cosRy, RotMatPR);
101 rotationMatrixH(sinRz, cosRz, RotMatH);
102 vec3 reflVec_dyn = (RotMatH * (RotMatPR * normalize(gl_ModelViewMatrixInverse * reflect_eye))).xyz;
103
104 reflVec = reflVec_dyn;
105 } else {
106 reflVec = reflVec_stat;
107 }
108
109
110 gl_FrontColor = gl_Color;
111
112 gl_Position = ftransform();
113 gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
114 }