-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
383 lines (331 loc) · 12.8 KB
/
index.html
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
<html>
<head>
<title>Voxels Project</title>
<meta name="description" content="HTML5">
<meta charset="UTF-8">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<link rel="stylesheet" href="style.css">
<link rel="shortcut icon" href="favicon.png" type="image/x-icon">
<link rel="icon" href="favicon.png" type="image/x-icon">
<script type="text/javascript" src="commons/webgl-utils.js"></script>
<script type="text/javascript" src="commons/initShaders.js"></script>
<script type="text/javascript" src="commons/MV.js"></script>
<script type="text/javascript" src="examples.js"></script>
<script type="text/javascript" src="helpers.js"></script>
<script type="text/javascript" src="main.js"></script>
<script type="text/javascript" src="shadow.js"></script>
<script type="text/javascript" src="cubeMethods.js"></script>
<script type="text/javascript" src="scene.js"></script>
<script type="text/javascript" src="colorpicker.js"></script>
<script type="text/javascript" src="interactions.js"></script>
<script id="vertex-shader-base" type="x-shader/x-vertex">
attribute vec4 vPosition;
attribute vec4 vColor;
uniform mat4 u_ProjectionMatrix;
uniform mat4 u_ViewMatrix;
uniform mat4 u_ModelMatrix;
varying vec4 fColor;
void main()
{
gl_Position = u_ProjectionMatrix * u_ViewMatrix * u_ModelMatrix * vPosition;
gl_PointSize = 20.0;
fColor = vColor;
}
</script>
<script id="fragment-shader-base" type="x-shader/x-fragment">
precision mediump float;
varying vec4 fColor;
void main()
{
gl_FragColor = fColor;
}
</script>
<script id="vertex-shader-shading" type="x-shader/x-vertex">
attribute vec4 vPosition;
attribute vec3 vNormal;
attribute vec4 vColor;
uniform mat4 u_ProjectionMatrix;
uniform mat4 u_ViewMatrix;
uniform mat4 u_ModelMatrix;
uniform mat3 u_NormalMatrix;
uniform vec4 light_position;
varying vec4 fColor;
varying vec3 N, L, E;
uniform mat4 u_MvpMatrixFromLight;
varying vec4 v_PositionFromLight;
void main()
{
gl_Position = u_ProjectionMatrix * u_ViewMatrix * u_ModelMatrix * vPosition;
vec3 pos = (u_ViewMatrix * u_ModelMatrix * vPosition).xyz;
N = normalize(u_NormalMatrix * vNormal);
vec3 light = (u_ViewMatrix * u_ModelMatrix * light_position).xyz;
L = light_position.w == 0.0 ? normalize(light) : normalize(light - pos); // directional or point light
E = normalize(-pos);
fColor = vColor;
v_PositionFromLight = u_MvpMatrixFromLight * vPosition;
}
</script>
<script id="fragment-shader-shading" type="x-shader/x-fragment">
precision mediump float;
varying vec4 fColor;
varying vec3 N, L, E;
uniform sampler2D u_ShadowMap;
varying vec4 v_PositionFromLight;
uniform float intensity;
uniform float kd;
uniform float ka;
uniform float ks;
uniform float alpha;
float unpackDepth(const in vec4 rgbaDepth)
{
const vec4 bitShift = vec4(1.0, 1.0/256.0, 1.0/(256.0 * 256.0), 1.0/(256.0 * 256.0 * 256.0));
float depth = dot(rgbaDepth, bitShift);
return depth;
}
void main()
{
vec3 Nfrag = normalize(N);
vec3 Efrag = normalize(E);
vec3 Lfrag = normalize(L);
vec3 H = normalize(Lfrag + Efrag);
float diffuse = kd * max(dot(Nfrag, Lfrag), 0.0) * intensity;
float ambient = ka;
float specular = ks * pow(max(dot(Nfrag, H), 0.0), alpha) * intensity;
// Shadow map
vec3 shadowCoord = (v_PositionFromLight.xyz/v_PositionFromLight.w) / 2.0 + 0.5;
vec2 texCoord = vec2(shadowCoord.x, shadowCoord.y);
vec4 rgbaDepth = texture2D(u_ShadowMap, texCoord);
float depth = unpackDepth(rgbaDepth);
float visibility = (shadowCoord.z > depth + 0.0015) ? 0.7 : 1.0;
gl_FragColor = fColor * (ambient + diffuse * visibility + specular * visibility);
gl_FragColor.a = 1.0;
}
</script>
<script id="vertex-shader-shadow" type="x-shader/x-vertex">
attribute vec4 vPosition;
uniform mat4 u_ProjectionMatrix;
uniform mat4 u_ViewMatrix;
uniform mat4 u_ModelMatrix;
void main()
{
gl_Position = u_ProjectionMatrix * u_ViewMatrix * u_ModelMatrix * vPosition;
}
</script>
<script id="fragment-shader-shadow" type="x-shader/x-fragment">
precision mediump float;
void main()
{
const vec4 bitShift = vec4(1.0, 256.0, 256.0 * 256.0, 256.0 * 256.0 * 256.0);
const vec4 bitMask = vec4(1.0/256.0, 1.0/256.0, 1.0/256.0, 0.0);
vec4 rgbaDepth = fract(gl_FragCoord.z * bitShift);
rgbaDepth -= rgbaDepth.gbaa * bitMask;
gl_FragColor = rgbaDepth;
}
</script>
<script id="vertex-shaderC" type="x-shader/x-vertex">
attribute vec4 vPositionC;
attribute vec4 vertexColorC;
varying vec4 fColor;
void main()
{
gl_Position = vPositionC;
gl_PointSize = 20.0;
fColor = vertexColorC;
}
</script>
<script id="fragment-shaderC" type="x-shader/x-fragment">
precision mediump float;
varying vec4 fColor;
void main()
{
gl_FragColor = fColor;
}
</script>
<script id="vertex-shaderSlider" type="x-shader/x-vertex">
attribute vec4 vPositionC;
attribute vec4 vertexColorC;
varying vec4 fColor;
void main()
{
gl_Position = vPositionC;
gl_PointSize = 20.0;
fColor = vertexColorC;
}
</script>
<script id="fragment-shaderSlider" type="x-shader/x-fragment">
precision mediump float;
varying vec4 fColor;
void main()
{
gl_FragColor = fColor;
}
</script>
</head>
<body>
<div class="container-full">
<div class="row" style="align-items: center;">
<h1 class="display-3">Voxels Project</h1>
<nav aria-label="Page navigation" style="margin-left: 20px">
<ul class="pagination" style="margin-bottom: 0">
<li class="page-item"><a class="page-link" href="../">Home</a></li>
<li class="page-item"><a class="page-link" href="report.html">
Report
</a></li>
</ul>
</nav>
</div>
<div class="row">
<div class="col-sm commands">
<div class="settings-menu">
<h3> Drawing </h3>
<div class="btn-group">
<button type="button" class="btn btn-info active" id="drawButton">Drawing</button>
<button type="button" class="btn btn-info" id="colorPickButton">Color Picker</button>
</div>
<div class="btn-group">
<button type="button" class="btn btn-info active" id="addCubeButton">Add cubes</button>
<button type="button" class="btn btn-info" id="removeCubeButton">Remove cubes</button>
</div>
</div>
<div>
<button type="button" class="btn btn-danger" id="clearButton">Clear all</button>
</div>
<div class="settings-menu">
<h3> Navigation </h3>
<div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-secondary" id="zoomInButton">+</button>
<button type="button" class="btn btn-secondary" id="zoomOutButton">-</button>
</div>
Zoom
</div>
<div class="settings-group">
<div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-secondary" id="thetaPlusButton">+</button>
<button type="button" class="btn btn-secondary" id="thetaMinusButton">-</button>
</div>
Theta
</div>
<div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-secondary" id="phiPlusButton">+</button>
<button type="button" class="btn btn-secondary" id="phiMinusButton">-</button>
</div>
Phi
</div>
</div>
<div class="settings-group">
<div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-secondary" id="truckXPlusButton">+</button>
<button type="button" class="btn btn-secondary" id="truckXMinusButton">-</button>
</div>
Truck
</div>
<div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-secondary" id="truckYPlusButton">+</button>
<button type="button" class="btn btn-secondary" id="truckYMinusButton">-</button>
</div>
Pedestal
</div>
</div>
</div>
<div class="settings-menu">
<h3> Lighting </h3>
<div class="btn-group">
<button type="button" class="btn btn-info active" id="shadowsOnButton">Shadows On</button>
<button type="button" class="btn btn-info" id="shadowsOffButton">Shadows Off</button>
</div>
<div class="btn-group">
<button type="button" class="btn btn-info active" id="hardNormalsButton">Flat Shading</button>
<button type="button" class="btn btn-info" id="softNormalsButton">Phong Shading</button>
</div>
<div id="currentLightParametersDisp"> </div>
<div class="settings-group">
<div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-secondary" id="LightX">+</button>
<button type="button" class="btn btn-secondary" id="LightXMinus">-</button>
</div>
X
</div>
<div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-secondary" id="LightY">+</button>
<button type="button" class="btn btn-secondary" id="LightYMinus">-</button>
</div>
Y
</div>
<div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-secondary" id="LightZ">+</button>
<button type="button" class="btn btn-secondary" id="LightZMinus">-</button>
</div>
Z
</div>
</div>
<div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-secondary" id="intensity">+</button>
<button type="button" class="btn btn-secondary" id="intensityMinus">-</button>
</div>
Intensity
</div>
<div class="settings-group">
<div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-secondary" id="kaButton">+</button>
<button type="button" class="btn btn-secondary" id="kaButtonMinus">-</button>
</div>
kA
</div>
<div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-secondary" id="kdButton">+</button>
<button type="button" class="btn btn-secondary" id="kdButtonMinus">-</button>
</div>
kD
</div>
</div>
<div class="settings-group">
<div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-secondary" id="ksButton">+</button>
<button type="button" class="btn btn-secondary" id="ksButtonMinus">-</button>
</div>
kS
</div>
<div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-secondary" id="alphaButton">+</button>
<button type="button" class="btn btn-secondary" id="alphaButtonMinus">-</button>
</div>
alpha
</div>
</div>
</div>
<div class="settings-menu">
<h3>Demos</h3>
Choose a model and some demo presets.
<div class="settings-group">
<button type="button" class="btn btn-secondary" id="chickenButton">Chicken</button>
<button type="button" class="btn btn-secondary" id="appleButton">Apple</button>
<button type="button" class="btn btn-secondary" id="guyButton">Person</button>
</div>
<div class="settings-group">
<button type="button" class="btn btn-secondary" id="phongDemoButton">Phong Demo</button>
</div>
</div>
</div>
<div class="col-md">
<canvas id="glCanvas" width="800" height="800"></canvas>
</div>
<div class="col-sm">
<canvas id= "colorsCanvas" width ="400" height="400"></canvas>
<canvas id= "sliderCanvas" width ="400" height="400"></canvas>
</div>
</div>
</body>
</html>