Debian Codegraph @

shaders/uc.geom

raw
1 #version 330
2 layout(points) in;
3 layout(line_strip, max_vertices = 128) out;
4
5 in vec3 vertex[];
6
7 out vec4 color;
8
9 uniform vec3 origin;
10 uniform mat4 pmv;
11 uniform mat3 cholesky;
12
13
14 vec3 frac2cart(vec3 x){
15 vec3 y = cholesky * x;
16 return y;
17 }
18
19 void main(void){
20 const vec3 strip0[] = vec3[9](vec3(0,1,1),vec3(0,1,0),vec3(1,1,0),vec3(1,0,0),vec3(1,0,1),vec3(0,0,1),vec3(0,1,1),vec3(1,1,1),vec3(1,0,1));
21 vec4 p;
22 for (int i = 0; i < strip0.length(); i++){
23 p = vec4(frac2cart(strip0[i]) - origin, 1);
24 gl_Position = pmv * p;
25 color = vec4(0.4,0.6,0.9,1.0);
26 EmitVertex();
27 }
28 EndPrimitive();
29 p = vec4(frac2cart(vec3(1,1,0)) - origin, 1);
30 gl_Position = pmv * p;
31 color = vec4(0.4,0.6,0.9,1.0);
32 EmitVertex();
33
34 p = vec4(frac2cart(vec3(1,1,1)) - origin, 1);
35 gl_Position = pmv * p;
36 color = vec4(0.4,0.6,0.9,1.0);
37 EmitVertex();
38 EndPrimitive();
39
40
41 p = vec4(frac2cart(vec3(0,0,0)) - origin, 1);
42 gl_Position = pmv * p;
43 color = vec4(1,0,0,1.0);//red
44 EmitVertex();
45
46 p = vec4(frac2cart(vec3(1,0,0)) - origin, 1);
47 gl_Position = pmv * p;
48 color = vec4(1,0,0,1.0);//red
49 EmitVertex();
50 EndPrimitive();
51
52
53 p = vec4(frac2cart(vec3(0,0,0)) - origin, 1);
54 gl_Position = pmv * p;
55 color = vec4(0,1,0,1.0);//green
56 EmitVertex();
57
58 p = vec4(frac2cart(vec3(0,1,0)) - origin, 1);
59 gl_Position = pmv * p;
60 color = vec4(0,1,0,1.0);//green
61 EmitVertex();
62 EndPrimitive();
63
64
65 p = vec4(frac2cart(vec3(0,0,0)) - origin, 1);
66 gl_Position = pmv * p;
67 color = vec4(0,0,1,1.0);//blue
68 EmitVertex();
69
70 p = vec4(frac2cart(vec3(0,0,1)) - origin, 1);
71 gl_Position = pmv * p;
72 color = vec4(0,0,1,1.0);//blue
73 EmitVertex();
74 EndPrimitive();
75
76 const float PI = 3.14159265359;
77 vec3 direction = vec3(1,0,0);
78 vec3 nd = normalize(frac2cart(direction));
79 vec3 lot = (dot(direction, vec3(1, 0, 0)) > 0.8)?
80 (dot(direction, vec3(0, 1, 0)) > 0.8)?
81 normalize(cross(direction, vec3(0, 0, 1))):
82 normalize(cross(direction, vec3(0, 1, 0))):
83 normalize(cross(direction, vec3(1, 0, 0)));
84 vec3 lot2 = normalize(cross(direction,lot));
85 vec3 r = vec3(0,0,0), vert;
86 int segments = 5;
87 float rad = 0.025;
88 vec3 start = frac2cart(direction);
89 vec3 end = start - 0.15 * nd;
90 vec4 col = vec4(direction,1);
91
92 for (int i = 0; i <= 2*segments; i++){
93 r = sin(PI * i / segments) * lot + cos(PI * i / segments) * lot2;
94 vert = (end + rad * r) - origin;
95 color = col;
96 gl_Position = pmv* vec4(vert, 1);
97 EmitVertex();
98 }
99
100 for (int i = 0; i <= 2*segments; i++){
101 r = sin(PI * i / segments) * lot + cos(PI * i / segments) * lot2;
102 vert = start - origin;
103 color = col;
104 gl_Position = pmv* vec4(vert, 1);
105 //Normal = normalMatrix * r;
106 EmitVertex();
107 vert = (end + rad * r) - origin;
108 color = col;
109 gl_Position = pmv* vec4(vert , 1);
110 //Normal = normalMatrix * r;
111 EmitVertex();
112 }
113 EndPrimitive();
114
115 direction = vec3(0,1,0);
116 lot = (dot(direction, vec3(1, 0, 0)) > 0.8)?
117 (dot(direction, vec3(0, 1, 0)) > 0.8)?
118 normalize(cross(direction, vec3(0, 0, 1))):
119 normalize(cross(direction, vec3(0, 1, 0))):
120 normalize(cross(direction, vec3(1, 0, 0)));
121 lot2 = normalize(cross(direction,lot));
122 start = frac2cart(direction);
123 nd = normalize(frac2cart(direction));
124 end = start - 0.1 * nd;
125 col = vec4(direction,1);
126
127 for (int i = 0; i <= 2*segments; i++){
128 r = sin(PI * i / segments) * lot + cos(PI * i / segments) * lot2;
129 vert = (end + rad * r) - origin;
130 color = col;
131 gl_Position = pmv* vec4(vert, 1);
132 EmitVertex();
133 }
134
135 for (int i = 0; i <= 2*segments; i++){
136 r = sin(PI * i / segments) * lot + cos(PI * i / segments) * lot2;
137 vert = start - origin;
138 color = col;
139 gl_Position = pmv* vec4(vert, 1);
140 //Normal = normalMatrix * r;
141 EmitVertex();
142 vert = (end + rad * r) - origin;
143 color = col;
144 gl_Position = pmv* vec4(vert , 1);
145 //Normal = normalMatrix * r;
146 EmitVertex();
147 }
148 EndPrimitive();
149
150 direction = vec3(0,0,1);
151 lot = (dot(direction, vec3(1, 0, 0)) > 0.8)?
152 (dot(direction, vec3(0, 1, 0)) > 0.8)?
153 normalize(cross(direction, vec3(0, 0, 1))):
154 normalize(cross(direction, vec3(0, 1, 0))):
155 normalize(cross(direction, vec3(1, 0, 0)));
156 lot2 = normalize(cross(direction,lot));
157 start = frac2cart(direction);
158 nd = normalize(frac2cart(direction));
159 end = start - 0.1 * nd;
160 col = vec4(direction,1);
161
162 for (int i = 0; i <= 2*segments; i++){
163 r = sin(PI * i / segments) * lot + cos(PI * i / segments) * lot2;
164 vert = (end + rad * r) - origin;
165 color = col;
166 gl_Position = pmv* vec4(vert, 1);
167 EmitVertex();
168 }
169
170 for (int i = 0; i <= 2*segments; i++){
171 r = sin(PI * i / segments) * lot + cos(PI * i / segments) * lot2;
172 vert = start - origin;
173 color = col;
174 gl_Position = pmv* vec4(vert, 1);
175 //Normal = normalMatrix * r;
176 EmitVertex();
177 vert = (end + rad * r) - origin;
178 color = col;
179 gl_Position = pmv* vec4(vert , 1);
180 //Normal = normalMatrix * r;
181 EmitVertex();
182 }
183 EndPrimitive();
184 }