-
Notifications
You must be signed in to change notification settings - Fork 1
/
shader1.gs
205 lines (171 loc) · 6.58 KB
/
shader1.gs
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#version 330 core
layout (points) in;
//layout (triangle_strip, max_vertices = 24) out; //cube
layout (triangle_strip, max_vertices = 60) out; //arrow
in vec3 pass_vel[];
in int pass_tag[];
out vec3 finalVel;
out vec3 finalColour;
flat out int finalTag;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
// change for cube size
const float size = 0.003;
// light
const vec3 lightDirection = normalize(vec3(0.4, -1.0, 0.8));
const float ambientLighting = 0.3;
mat3 Rx(const float radians){
return mat3(1.0, 0.0, 0.0,
0.0, cos(radians),sin(radians),
0.0,-sin(radians),cos(radians));
}
mat3 Ry(const float radians){
return mat3(cos(radians), 0.0, -sin(radians),
0.0, 1.0, 0.0,
sin(radians), 0.0, cos(radians));
}
mat3 Rz(const float radians){
return mat3(cos(radians), sin(radians), 0.0,
-sin(radians), cos(radians), 0.0,
0.0, 0.0, 1.0);
}
void createVertex(vec3 offset, vec3 colour) {
float yaw = atan(pass_vel[0].y, pass_vel[0].x);
float pitch = atan(pass_vel[0].z/sqrt(pass_vel[0].x*pass_vel[0].x+pass_vel[0].y*pass_vel[0].y));
float roll = 0.0;
offset = Rz(yaw)*Ry(-pitch)*Rx(roll)*offset;
vec4 actualOffset = vec4(offset * size, 0.0);
vec4 worldPosition = gl_in[0].gl_Position + actualOffset;
gl_Position = projection * view * model * worldPosition;
finalVel = pass_vel[0];
finalTag = pass_tag[0];
finalColour = colour;
EmitVertex();
}
vec3 calculateLighting(vec3 faceNormal){
float brightness = max(dot(-lightDirection, faceNormal), ambientLighting);
return abs(pass_vel[0]) * brightness;
}
// cube geometry
void cube();
void arrow();
void main() {
//cube();
arrow();
}
void cube(){
vec3 faceNormal = vec3(0.0, 0.0, 1.0);
vec3 colour = calculateLighting(faceNormal);
createVertex(vec3(-1.0, 1.0, 1.0), colour);
createVertex(vec3(-1.0, -1.0, 1.0), colour);
createVertex(vec3(1.0, 1.0, 1.0), colour);
createVertex(vec3(1.0, -1.0, 1.0), colour);
EndPrimitive();
faceNormal = vec3(1.0, 0.0, 0.0);
colour = calculateLighting(faceNormal);
createVertex(vec3(1.0, 1.0, 1.0), colour);
createVertex(vec3(1.0, -1.0, 1.0), colour);
createVertex(vec3(1.0, 1.0, -1.0), colour);
createVertex(vec3(1.0, -1.0, -1.0), colour);
EndPrimitive();
faceNormal = vec3(0.0, 0.0, -1.0);
colour = calculateLighting(faceNormal);
createVertex(vec3(1.0, 1.0, -1.0), colour);
createVertex(vec3(1.0, -1.0, -1.0), colour);
createVertex(vec3(-1.0, 1.0, -1.0), colour);
createVertex(vec3(-1.0, -1.0, -1.0), colour);
EndPrimitive();
faceNormal = vec3(-1.0, 0.0, 0.0);
colour = calculateLighting(faceNormal);
createVertex(vec3(-1.0, 1.0, -1.0), colour);
createVertex(vec3(-1.0, -1.0, -1.0), colour);
createVertex(vec3(-1.0, 1.0, 1.0), colour);
createVertex(vec3(-1.0, -1.0, 1.0), colour);
EndPrimitive();
faceNormal = vec3(0.0, 1.0, 0.0);
colour = calculateLighting(faceNormal);
createVertex(vec3(1.0, 1.0, 1.0), colour);
createVertex(vec3(1.0, 1.0, -1.0), colour);
createVertex(vec3(-1.0, 1.0, 1.0), colour);
createVertex(vec3(-1.0, 1.0, -1.0), colour);
EndPrimitive();
faceNormal = vec3(0.0, -1.0, 0.0);
colour = calculateLighting(faceNormal);
createVertex(vec3(-1.0, -1.0, 1.0), colour);
createVertex(vec3(-1.0, -1.0, -1.0), colour);
createVertex(vec3(1.0, -1.0, 1.0), colour);
createVertex(vec3(1.0, -1.0, -1.0), colour);
EndPrimitive();
}
void arrow(){
//NOTE: review faceNormal vectors
//Heat
vec3 faceNormal = vec3(-1.0, 0.0, 0.0);
vec3 colour = calculateLighting(faceNormal);
createVertex(vec3(0.0, -1.0, 1.0), colour);
createVertex(vec3(0.0, -1.0, -1.0), colour);
createVertex(vec3(0.0, 1.0, 1.0), colour);
createVertex(vec3(0.0, 1.0, -1.0), colour);
EndPrimitive();
faceNormal = normalize(cross(vec3(-2.0, 1.0, 1.0), vec3(-2.0, -1.0, 1.0)));
colour = calculateLighting(faceNormal);
createVertex(vec3(0.0, 1.0, 1.0), colour);
createVertex(vec3(0.0, -1.0, 1.0), colour);
createVertex(vec3(2.0, 0.0, 0.0), colour);
EndPrimitive();
faceNormal = normalize(cross(vec3(-2.0, 1.0, -1.0), vec3(-2.0, -1.0, -1.0)));
colour = calculateLighting(faceNormal);
createVertex(vec3(0.0, 1.0, -1.0), colour);
createVertex(vec3(0.0, -1.0, -1.0), colour);
createVertex(vec3(2.0, 0.0, 0.0), colour);
EndPrimitive();
faceNormal = normalize(cross(vec3(-2.0, 1.0, 1.0), vec3(-2.0, 1.0, -1.0)));
colour = calculateLighting(faceNormal);
createVertex(vec3(0.0, 1.0, 1.0), colour);
createVertex(vec3(0.0, 1.0, -1.0), colour);
createVertex(vec3(2.0, 0.0, 0.0), colour);
EndPrimitive();
faceNormal = normalize(cross(vec3(-2.0, -1.0, 1.0), vec3(-2.0, -1.0, -1.0)));
colour = calculateLighting(faceNormal);
createVertex(vec3(0.0, -1.0, 1.0), colour);
createVertex(vec3(0.0, -1.0, -1.0), colour);
createVertex(vec3(2.0, 0.0, 0.0), colour);
EndPrimitive();
//body
faceNormal = vec3(-1.0, 0.0, 0.0);
colour = calculateLighting(faceNormal);
createVertex(vec3(-4.0, -0.5, 0.5), colour);
createVertex(vec3(-4.0, -0.5, -0.5), colour);
createVertex(vec3(-4.0, 0.5, 0.5), colour);
createVertex(vec3(-4.0, 0.5, -0.5), colour);
EndPrimitive();
faceNormal = vec3(0.0, 1.0, 0.0);
colour = calculateLighting(faceNormal);
createVertex(vec3( 0.0, 0.5, -0.5), colour);
createVertex(vec3( 0.0, 0.5, 0.5), colour);
createVertex(vec3(-4.0, 0.5, -0.5), colour);
createVertex(vec3(-4.0, 0.5, 0.5), colour);
EndPrimitive();
faceNormal = vec3(0.0, 0.0, 1.0);
colour = calculateLighting(faceNormal);
createVertex(vec3( 0.0, 0.5, 0.5), colour);
createVertex(vec3( 0.0, -0.5, 0.5), colour);
createVertex(vec3(-4.0, 0.5, 0.5), colour);
createVertex(vec3(-4.0, -0.5, 0.5), colour);
EndPrimitive();
faceNormal = vec3(0.0, -1.0, 0.0);
colour = calculateLighting(faceNormal);
createVertex(vec3( 0.0, -0.5, 0.5), colour);
createVertex(vec3( 0.0, -0.5, -0.5), colour);
createVertex(vec3(-4.0, -0.5, 0.5), colour);
createVertex(vec3(-4.0, -0.5, -0.5), colour);
EndPrimitive();
faceNormal = vec3(0.0, 0.0, -1.0);
colour = calculateLighting(faceNormal);
createVertex(vec3( 0.0, 0.5, -0.5), colour);
createVertex(vec3( 0.0, -0.5, -0.5), colour);
createVertex(vec3(-4.0, 0.5, -0.5), colour);
createVertex(vec3(-4.0, -0.5, -0.5), colour);
EndPrimitive();
}