Debian Codegraph @

Shaders/light-ALS.vert

raw
1 // -*-C++-*-
2
3 #version 120
4
5 // doing directionality is surprisingly complicated - with just the vector and the eye we can't
6 // do a spherical billboard, but the animation itself operates before the shader, so
7 // the model-coordinate to eye relationship is always the same
8 // thus we need to use pitch, yaw and roll to get the current model space coordinates
9
10 uniform float pitch;
11 uniform float roll;
12 uniform float hdg;
13
14
15 varying vec3 vertex;
16 varying vec3 relPos;
17 varying vec3 normal;
18
19
20
21 void main()
22 {
23
24 vec4 ep = gl_ModelViewMatrixInverse * vec4(0.0,0.0,0.0,1.0);
25
26 vec4 l = gl_ModelViewMatrixInverse * vec4(0.0,0.0,1.0,1.0);
27 vec3 u = normalize(ep.xyz - l.xyz);
28
29 vec3 absu = abs(u);
30 vec3 r = normalize(vec3(-u.y, u.x, 0.0));
31 vec3 w = cross(u, r);
32
33 vertex = gl_Vertex.xyz;
34 relPos = vertex - ep.xyz;
35 normal = gl_NormalMatrix * gl_Normal;
36
37 gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
38 gl_Position.xyz = gl_Vertex.x * u;
39 gl_Position.xyz += gl_Vertex.y * r;
40 gl_Position.xyz += gl_Vertex.z * w;
41 gl_Position = gl_ModelViewProjectionMatrix * gl_Position;
42
43 //gl_Position = ftransform();
44 gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
45
46 gl_FrontColor = vec4 (1.0,1.0,1.0,1.0);
47 gl_BackColor = gl_FrontColor;
48 }
49
50 /*
51
52 void rotationMatrixPR(in float sinRx, in float cosRx, in float sinRy, in float cosRy, out mat4 rotmat)
53 {
54 rotmat = mat4( cosRy , sinRx * sinRy , cosRx * sinRy, 0.0,
55 0.0 , cosRx , -sinRx * cosRx, 0.0,
56 -sinRy, sinRx * cosRy, cosRx * cosRy , 0.0,
57 0.0 , 0.0 , 0.0 , 1.0 );
58 }
59
60 void rotationMatrixH(in float sinRz, in float cosRz, out mat4 rotmat)
61 {
62 rotmat = mat4( cosRz, -sinRz, 0.0, 0.0,
63 sinRz, cosRz, 0.0, 0.0,
64 0.0 , 0.0 , 1.0, 0.0,
65 0.0 , 0.0 , 0.0, 1.0 );
66 }
67
68 //prepare rotation matrix
69 mat4 RotMatPR;
70 mat4 RotMatH;
71 float _roll = roll;
72 if (_roll>90.0 || _roll < -90.0) {_roll = -_roll;}
73 float cosRx = cos(radians(_roll));
74 float sinRx = sin(radians(_roll));
75 float cosRy = cos(radians(-pitch));
76 float sinRy = sin(radians(-pitch));
77 float cosRz = cos(radians(hdg));
78 float sinRz = sin(radians(hdg));
79 rotationMatrixPR(sinRx, cosRx, sinRy, cosRy, RotMatPR);
80 rotationMatrixH(sinRz, cosRz, RotMatH);
81
82 vec3 model_x = (RotMatH * RotMatPR * vec4 (1.0, 0.0, 0.0, 0.0)).xyz;
83 vec3 model_y = (RotMatH * RotMatPR * vec4 (0.0, 1.0, 0.0, 0.0)).xyz;
84 vec3 model_z = (RotMatH * RotMatPR * vec4 (0.0, 0.0, 1.0, 0.0)).xyz;
85
86 vec3 pointingVec = normalize(pointing_x * model_x + pointing_y * model_y + pointing_z * model_z);
87 pointing_angle = dot (viewDir, pointingVec);*/