-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoonShading.html
More file actions
854 lines (723 loc) · 34 KB
/
Copy pathtoonShading.html
File metadata and controls
854 lines (723 loc) · 34 KB
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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
<html>
<head>
<title>ICG WebGL — HW1 - Toon Shading</title>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript" src="./js/glMatrix-0.9.5.min.js"></script>
<script type="text/javascript" src="./js/webgl-utils.js"></script>
<script id="fragmentShader" type="fragment">
precision mediump float;
uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
uniform float Ka;
uniform float Ks;
uniform float Kd;
uniform float Shininess;
uniform vec3 lightLoc1;
uniform vec3 lightLoc2;
uniform vec3 lightColor1;
uniform vec3 lightColor2;
varying vec4 fragcolor;
varying vec3 mvVertex;
varying vec3 mvNormal;
varying vec3 ndc;
void main(void) {
if (ndc.x < -0.9 || ndc.x > 0.9) discard;
float AIntensity = Ka;
vec3 V = -normalize(mvVertex);
vec3 N = normalize(mvNormal);
vec3 L1 = normalize(lightLoc1 - mvVertex);
vec3 R1 = reflect(-L1, N);
vec3 L2 = normalize(lightLoc2 - mvVertex);
vec3 R2 = reflect(-L2, N);
float NdotL1 = max(dot(N, L1), 0.0);
float NdotL2 = max(dot(N, L2), 0.0);
float DIntensity1 = Kd * NdotL1;
float DIntensity2 = Kd * NdotL2;
float CosN1 = pow(max(dot(R1, V), 0.0), Shininess);
float CosN2 = pow(max(dot(R2, V), 0.0), Shininess);
float SIntensity1 = Ks * CosN1;
float SIntensity2 = Ks * CosN2;
vec3 color = ceil(AIntensity * 12.0) / 12.0 * vec3(fragcolor) + (ceil((DIntensity1 + SIntensity1) * 12.0) / 12.0 * lightColor1 + ceil((DIntensity2 + SIntensity2) * 12.0) / 12.0 * lightColor2) * vec3(fragcolor);
gl_FragColor = vec4(color, 1.0);
}
</script>
<script id="vertexShader" type="vertex">
precision mediump float;
attribute vec3 aVertexPosition;
attribute vec3 aFrontColor;
attribute vec3 aVertexNormal;
uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
varying vec4 fragcolor;
varying vec3 mvVertex;
varying vec3 mvNormal;
varying vec3 ndc;
void main(void) {
gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
mvVertex = (uMVMatrix * vec4(aVertexPosition, 1.0)).xyz;
mvNormal = normalize(mat3(uMVMatrix) * aVertexNormal);
fragcolor = vec4(aFrontColor,1.0);
vec4 clipPos = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
gl_Position = clipPos;
ndc = clipPos.xyz / clipPos.w;
}
</script>
<script type="text/javascript">
// common variables
var gl;
var shaderProgram;
var mvMatrix = mat4.create();
var pMatrix = mat4.create();
var shearMatrix = mat4.create();
var teapotAngle = 180;
var lastTime = 0;
var ka = 0.2;
var kd = 0.5;
var ks = 0.6;
var shininess = 20.0;
var light_locations1 = new Float32Array([30., 20., -10.]);
var light_locations2 = new Float32Array([-20., -10., -30.]);
var light_color1 = new Float32Array([20., 5., 5.]);
var light_color2 = new Float32Array([5., 5., 30.]);
var clip = 1;
//*************************************************
// Initialization functions
//*************************************************
function initGL(canvas) {
try {
gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl");
gl.viewportWidth = canvas.width;
gl.viewportHeight = canvas.height;
}
catch (e) {
}
if (!gl) {
alert("Could not initialise WebGL");
}
}
function getShader(gl, id) {
var shaderScript = document.getElementById(id);
if (!shaderScript) {
return null;
}
var shaderSource = "";
var k = shaderScript.firstChild;
while (k) {
if (k.nodeType == 3) {
shaderSource += k.textContent;
}
k = k.nextSibling;
}
var shader;
if (shaderScript.type == "fragment") {
shader = gl.createShader(gl.FRAGMENT_SHADER);
}
else if (shaderScript.type == "vertex") {
shader = gl.createShader(gl.VERTEX_SHADER);
}
else {
return null;
}
gl.shaderSource(shader, shaderSource);
gl.compileShader(shader);
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
alert(gl.getShaderInfoLog(shader));
return null;
}
return shader;
}
function initShaders() {
var fragmentShader = getShader(gl, "fragmentShader");
var vertexShader = getShader(gl, "vertexShader");
shaderProgram = gl.createProgram();
gl.attachShader(shaderProgram, vertexShader);
gl.attachShader(shaderProgram, fragmentShader);
gl.linkProgram(shaderProgram);
if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS)) {
alert("Could not initialise shaders");
}
gl.useProgram(shaderProgram);
shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition");
gl.enableVertexAttribArray(shaderProgram.vertexPositionAttribute);
shaderProgram.vertexFrontColorAttribute = gl.getAttribLocation(shaderProgram, "aFrontColor");
gl.enableVertexAttribArray(shaderProgram.vertexFrontColorAttribute);
shaderProgram.vertexNormalAttribute = gl.getAttribLocation(shaderProgram, "aVertexNormal");
gl.enableVertexAttribArray(shaderProgram.vertexNormalAttribute);
shaderProgram.ka = gl.getUniformLocation(shaderProgram, "Ka");
shaderProgram.kd = gl.getUniformLocation(shaderProgram, "Kd");
shaderProgram.ks = gl.getUniformLocation(shaderProgram, "Ks");
shaderProgram.shininess = gl.getUniformLocation(shaderProgram, "Shininess");
gl.uniform1f(gl.getUniformLocation(shaderProgram, "Shininess"), shininess);
gl.uniform3fv(gl.getUniformLocation(shaderProgram, "lightLoc1"), light_locations1);
gl.uniform3fv(gl.getUniformLocation(shaderProgram, "lightLoc2"), light_locations2);
gl.uniform3fv(gl.getUniformLocation(shaderProgram, "lightColor1"), light_color1);
gl.uniform3fv(gl.getUniformLocation(shaderProgram, "lightColor2"), light_color2);
shaderProgram.pMatrixUniform = gl.getUniformLocation(shaderProgram, "uPMatrix");
shaderProgram.mvMatrixUniform = gl.getUniformLocation(shaderProgram, "uMVMatrix");
}
function setMatrixUniforms() {
gl.uniformMatrix4fv(shaderProgram.pMatrixUniform, false, pMatrix);
gl.uniformMatrix4fv(shaderProgram.mvMatrixUniform, false, mvMatrix);
}
function degToRad(degrees) {
return degrees * Math.PI / 180;
}
function Model(drawType){
this.drawType = drawType;
this.VertexNormalBuffer;
this.VertexPositionBuffer;
this.VertexFrontColorBuffer;
}
var model0 = new Model(0);
var model1 = new Model(0);
var model2 = new Model(0);
function handleLoadedTeapot(modelName, modelData) {
modelName.VertexPositionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, modelName.VertexPositionBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(modelData.vertexPositions), gl.STATIC_DRAW);
modelName.VertexPositionBuffer.itemSize = 3;
modelName.VertexPositionBuffer.numItems = modelData.vertexPositions.length / 3;
modelName.VertexNormalBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, modelName.VertexNormalBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(modelData.vertexNormals), gl.STATIC_DRAW);
modelName.VertexNormalBuffer.itemSize = 3;
modelName.VertexNormalBuffer.numItems = modelData.vertexNormals.length / 3;
modelName.VertexFrontColorBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, modelName.VertexFrontColorBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(modelData.vertexFrontcolors), gl.STATIC_DRAW);
modelName.VertexFrontColorBuffer.itemSize = 3;
modelName.VertexFrontColorBuffer.numItems = modelData.vertexFrontcolors.length / 3;
}
function loadModel(model, i) {
const modelObjects = [model0, model1, model2];
const targetModel = modelObjects[i];
var request = new XMLHttpRequest();
request.open("GET", "./model/" + model + ".json");
request.onreadystatechange = function () {
if (request.readyState == 4) {
handleLoadedTeapot(targetModel, JSON.parse(request.responseText));
}
}
request.send();
}
//*************************************************
// Rendering functions
//*************************************************
/*
TODO HERE:
add two or more objects showing on the canvas
(it needs at least three objects showing at the same time)
*/
function drawScene() {
gl.viewport(0, 0, gl.viewportWidth, gl.viewportHeight);
gl.clearColor(ka, ka, ka, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
if (model0.VertexPositionBuffer == null ||
model1.VertexPositionBuffer == null ||
model2.VertexPositionBuffer == null) {
return;
}
// Setup Projection Matrix
mat4.perspective(45, gl.viewportWidth / gl.viewportHeight, 0.1, 100.0, pMatrix);
let models = [model0, model1, model2];
for (let i = 0; i < models.length; i++) {
// Setup Model-View Matrix
mat4.identity(mvMatrix);
mat4.translate(mvMatrix, [0, 0, 0]);
// transform
var trans = update_trans(i);
mat4.translate(mvMatrix, trans);
// rotate
var rotateVec_init = [0,0,0];
mat4.rotate(mvMatrix, degToRad(rotateVec_init[0]), [1, 0, 0]);
mat4.rotate(mvMatrix, degToRad(rotateVec_init[1]), [0, 1, 0]);
mat4.rotate(mvMatrix, degToRad(rotateVec_init[2]), [0, 0, 1]);
var rotateVec = update_rotate(i);
mat4.rotate(mvMatrix, degToRad(rotateVec[0]), [1, 0, 0]);
mat4.rotate(mvMatrix, degToRad(rotateVec[1] + teapotAngle), [0, 1, 0]);
mat4.rotate(mvMatrix, degToRad(rotateVec[2]), [0, 0, 1]);
// scale
var scaleVec = update_scaling(i);
mat4.scale(mvMatrix, [1.0, 1.0, 1.0]);
mat4.scale(mvMatrix, scaleVec);
// Shear
var shearValue = update_shear(i);
mat4.identity(shearMatrix);
shearMatrix[4] = 1 / Math.tan(degToRad(shearValue));
mat4.multiply(mvMatrix, shearMatrix, mvMatrix);
// set shader uniform
setMatrixUniforms();
if (breathing) {
let now = new Date().getTime();
let elapsed = (now - breathingStartTime) / 1000;
let intensity = 0.1 + 0.9 * (0.5 + 0.5 * Math.sin(elapsed * 2.0));
light_color1[0] = 10 * intensity;
light_color1[1] = 6 * intensity;
light_color1[2] = 6 * intensity;
light_color2[0] = 10 * intensity;
light_color2[1] = 10 * intensity;
light_color2[2] = 10 * intensity;
}
gl.uniform1f(gl.getUniformLocation(shaderProgram, "Ka"), ka);
gl.uniform1f(gl.getUniformLocation(shaderProgram, "Kd"), kd);
gl.uniform1f(gl.getUniformLocation(shaderProgram, "Ks"), ks);
gl.uniform1f(gl.getUniformLocation(shaderProgram, "Shininess"), shininess);
gl.uniform3fv(gl.getUniformLocation(shaderProgram, "lightLoc1"), light_locations1);
gl.uniform3fv(gl.getUniformLocation(shaderProgram, "lightLoc2"), light_locations2);
gl.uniform3fv(gl.getUniformLocation(shaderProgram, "lightColor1"), light_color1);
gl.uniform3fv(gl.getUniformLocation(shaderProgram, "lightColor2"), light_color2);
// Position buffer
gl.bindBuffer(gl.ARRAY_BUFFER, models[i].VertexPositionBuffer);
gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute,
models[i].VertexPositionBuffer.itemSize,
gl.FLOAT,
false,
0,
0);
// Color buffer
gl.bindBuffer(gl.ARRAY_BUFFER, models[i].VertexFrontColorBuffer);
gl.vertexAttribPointer(shaderProgram.vertexFrontColorAttribute,
models[i].VertexFrontColorBuffer.itemSize,
gl.FLOAT,
false,
0,
0);
// Normal buffer
gl.bindBuffer(gl.ARRAY_BUFFER, models[i].VertexNormalBuffer);
gl.vertexAttribPointer(shaderProgram.vertexNormalAttribute,
models[i].VertexNormalBuffer.itemSize,
gl.FLOAT,
false,
0,
0);
// 畫圖
gl.drawArrays(gl.TRIANGLES, 0, models[i].VertexPositionBuffer.numItems);
}
}
function animate() {
var timeNow = new Date().getTime();
if (lastTime != 0) {
var elapsed = timeNow - lastTime;
teapotAngle += 0.03 * elapsed;
}
lastTime = timeNow;
}
function tick() {
requestAnimFrame(tick);
drawScene();
animate();
}
function webGLStart() {
var canvas = document.getElementById("ICG-canvas");
initGL(canvas);
initShaders();
loadModel("Csie", 0);
loadModel("Teapot", 1);
loadModel("Car_road", 2);
initiate();
gl.clearColor(ka, ka, ka, 1.0);
gl.enable(gl.DEPTH_TEST);
tick();
}
//*************************************************
// Parsing parameters
//*************************************************
function update_ambient_light(){
ka = document.getElementById("am_ka").value;
}
function update_diffuse_light(){
kd = document.getElementById("am_kd").value;
}
function update_specular_light(){
ks = document.getElementById("am_ks").value;
}
function update_shininess(){
shininess = document.getElementById("shininess").value;
}
function update_light_location(){
light_locations1[0] = document.getElementById("llocX1").value;
light_locations1[1] = document.getElementById("llocY1").value;
light_locations1[2] = document.getElementById("llocZ1").value;
light_locations2[0] = document.getElementById("llocX2").value;
light_locations2[1] = document.getElementById("llocY2").value;
light_locations2[2] = document.getElementById("llocZ2").value;
}
function update_light_color(){
light_color1[0] = document.getElementById("R1").value;
light_color1[1] = document.getElementById("G1").value;
light_color1[2] = document.getElementById("B1").value;
light_color2[0] = document.getElementById("R2").value;
light_color2[1] = document.getElementById("G2").value;
light_color2[2] = document.getElementById("B2").value;
}
function update_trans(i){
var tx = document.getElementById("transX" + i).value;
var ty = document.getElementById("transY" + i).value;
var tz = document.getElementById("transZ" + i).value;
return vec3.create([tx, ty, tz]);
}
function update_rotate(i){
var rx = document.getElementById("rotateX" + i).value;
var ry = document.getElementById("rotateY" + i).value;
var rz = document.getElementById("rotateZ" + i).value;
return vec3.create([rx, ry, rz]);
}
function update_scaling(i){
var s = document.getElementById("scaling" + i).value;
return vec3.create([s, s, s]);
}
function update_shear(i){
var sh = document.getElementById("shear" + i).value;
return sh;
}
function changeModel(i){
const modelName = document.getElementById("modelSelector" + i).value;
loadModel(modelName, i);
}
function initiate() {
for (let i = 0; i < 3; i++) {
document.getElementById("rotateX" + i).value = 0;
document.getElementById("rotateY" + i).value = 0;
document.getElementById("rotateZ" + i).value = 0;
document.getElementById("shear" + i).value = 90;
}
document.getElementById("scaling0").value = 10.0;
document.getElementById("scaling1").value = 1.0;
document.getElementById("scaling2").value = 10.0;
document.getElementById("transX0").value = -45.0;
document.getElementById("transY0").value = -4.;
document.getElementById("transZ0").value = -50.;
document.getElementById("transX1").value = 0.;
document.getElementById("transY1").value = 0.;
document.getElementById("transZ1").value = -50.;
document.getElementById("transX2").value = 45.;
document.getElementById("transY2").value = -6.;
document.getElementById("transZ2").value = -50.;
document.getElementById("am_ka").value = 0.2;
document.getElementById("am_kd").value = 0.1;
document.getElementById("am_ks").value = 0.1;
document.getElementById("shininess").value = 20.0;
document.getElementById("llocX1").value = 50;
document.getElementById("llocY1").value = 30;
document.getElementById("llocZ1").value = -25;
document.getElementById("llocX2").value = -50;
document.getElementById("llocY2").value = -30;
document.getElementById("llocZ2").value = -25;
document.getElementById("R1").value = 5.0;
document.getElementById("G1").value = 3.0;
document.getElementById("B1").value = 3.0;
document.getElementById("R2").value = 5.0;
document.getElementById("G2").value = 5.0;
document.getElementById("B2").value = 5.0;
document.getElementById("modelSelector0").value = "Csie";
document.getElementById("modelSelector1").value = "Teapot";
document.getElementById("modelSelector2").value = "Car_road";
loadModel("Csie", 0);
loadModel("Teapot", 1);
loadModel("Car_road", 2);
update_ambient_light();
update_diffuse_light();
update_specular_light();
update_light_location();
update_light_color();
}
function initWhite() {
document.getElementById("R1").value = 5.0;
document.getElementById("G1").value = 5.0;
document.getElementById("B1").value = 5.0;
document.getElementById("R2").value = 5.0;
document.getElementById("G2").value = 5.0;
document.getElementById("B2").value = 5.0;
update_light_color();
}
var flashInterval;
function randColor(min, max) {
return min + Math.random() * (max - min);
}
function toggleLightEffect(checked) {
if (!checked) {
clearInterval(flashInterval);
flashing = false;
initWhite();
return;
} else {
flashInterval = setInterval(() => {
light_color1[0] = randColor(5, 10);
light_color1[1] = randColor(3, 10);
light_color1[2] = randColor(0, 10);
light_color2[0] = randColor(3, 10);
light_color2[1] = randColor(5, 10);
light_color2[2] = randColor(0, 10);
}, 100);
}
}
var breathing = false;
var breathingStartTime = null;
function toggleBreathingEffect(checked) {
if (checked) {
breathing = true;
breathingStartTime = new Date().getTime();
} else {
breathing = false;
initWhite();
}
}
</script>
</head>
<body onload="webGLStart();">
<h1 style="font-weight: bold; margin-top: 20px;">
<label for="shading">Toon shading</label>
</h1>
<div style="text-align: center;">
<canvas id="ICG-canvas" style="border: none;" width="1800" height="500" style="border: 1px solid rgb(186, 104, 104);"></canvas>
</div>
<div style="margin: 0; padding-top: 8px;">
<p style="font-weight: bold; font-size: 20px; color: #fff; background: #333;
padding: 8px 12px; border-radius: 8px; box-shadow: 0 2px 6px rgba(0,0,0,0.2);">
<br>
<span>Tap the button to RESET: </span><button id="resetButton" onclick="initiate()">Reset</button>
<br>
<br>
</p>
<br>
<div style="display: flex; gap: 30px; padding: 10px 0;">
<label class="switch">
<input type="checkbox" id="flashCheckbox" onchange="toggleLightEffect(this.checked)">
<span class="slider"></span>
<span class="label-text">Special Light Effect</span>
</label>
<label class="switch">
<input type="checkbox" id="breathingCheckbox" onchange="toggleBreathingEffect(this.checked)">
<span class="slider"></span>
<span class="label-text">Breathing Light Effect</span>
</label>
</div>
<br>
<span><b>Ambient Light</b></span>
<table>
<tr>
<td>Ka: <input style="max-width: 70%; vertical-align: middle;" id="am_ka" type="range" autocomplete="off" value="0.1" max="1." min="0." step="0.05" oninput="update_ambient_light()"></td>
</tr>
</table>
<span><b>Diffuse Light</b></span>
<table>
<tr>
<td>Kd: <input style="max-width: 70%; vertical-align: middle;" id="am_kd" type="range" autocomplete="off" value="0.1" max="1." min="0." step="0.05" oninput="update_diffuse_light()"></td>
</tr>
</table>
<span><b>Specular Light</b></span>
<table>
<tr>
<td>Ks: <input style="max-width: 70%; vertical-align: middle;" id="am_ks" type="range" autocomplete="off" value="0.1" max="1." min="0." step="0.05" oninput="update_specular_light()"></td>
</tr>
</table>
<span><b>Shininess</b></span>
<table>
<tr>
<td>Shininess: <input style="max-width: 70%; vertical-align: middle;" id="shininess" type="range" autocomplete="off" value="5" max="300" min="1" oninput="update_shininess()"></td>
</tr>
</table>
<br>
<span><b>Light 1</b></span>
<table>
<tr>
<td>X: <input style="max-width: 70%; vertical-align: middle;" id="llocX1" type="range" autocomplete="off" value="30." max="40." min="-40." oninput="update_light_location()"></td>
<td>Y: <input style="max-width: 70%; vertical-align: middle;" id="llocY1" type="range" autocomplete="off" value="20." max="40." min="-40." oninput="update_light_location()"></td>
<td>Z: <input style="max-width: 70%; vertical-align: middle;" id="llocZ1" type="range" autocomplete="off" value="-25." max="0." min="-75." oninput="update_light_location()"></td>
</tr>
<tr>
<td>R: <input style="max-width: 70%; vertical-align: middle;" id="R1" type="range" autocomplete="off" value="50." max="255." min="0." oninput="update_light_color()"></td>
<td>G: <input style="max-width: 70%; vertical-align: middle;" id="G1" type="range" autocomplete="off" value="0." max="255." min="0." oninput="update_light_color()"></td>
<td>B: <input style="max-width: 70%; vertical-align: middle;" id="B1" type="range" autocomplete="off" value="0." max="255." min="0." oninput="update_light_color()"></td>
</tr>
</table>
<span><b>Light 2</b></span>
<table>
<tr>
<td>X: <input style="max-width: 70%; vertical-align: middle;" id="llocX2" type="range" autocomplete="off" value="30." max="40." min="-40." oninput="update_light_location()"></td>
<td>Y: <input style="max-width: 70%; vertical-align: middle;" id="llocY2" type="range" autocomplete="off" value="20." max="40." min="-40." oninput="update_light_location()"></td>
<td>Z: <input style="max-width: 70%; vertical-align: middle;" id="llocZ2" type="range" autocomplete="off" value="-25." max="0." min="-75." oninput="update_light_location()"></td>
</tr>
<tr>
<td>R: <input style="max-width: 70%; vertical-align: middle;" id="R2" type="range" autocomplete="off" value="0." max="255." min="0." oninput="update_light_color()"></td>
<td>G: <input style="max-width: 70%; vertical-align: middle;" id="G2" type="range" autocomplete="off" value="0." max="255." min="0." oninput="update_light_color()"></td>
<td>B: <input style="max-width: 70%; vertical-align: middle;" id="B2" type="range" autocomplete="off" value="50." max="255." min="0." oninput="update_light_color()"></td>
</tr>
</table>
<br>
<table>
<span>Set the light color to White: </span><button id="ColorButton" onclick="initWhite()">White</button>
</table>
</br>
<div class="row">
<div class="col-sm">
<span>Model</span>
<span>Choose a model:</span>
<select id="modelSelector0" onchange="changeModel(0)">
<option value="Teapot">Teapot</option>
<option value="Csie">Csie</option>
<option value="Car_road">Car_road</option>
<option value="Fighter">Fighter</option>
<option value="Longteap">Longteap</option>
<option value="Mig27">Mig27</option>
<option value="Plant">Plant</option>
<option value="Tomcat">Tomcat</option>
<option value="Church_s">Church_s</option>
<option value="Easter">Easter</option>
<option value="Kangaroo">Kangaroo</option>
<option value="Mercedes">Mercedes</option>
<option value="Patchair">Patchair</option>
</select>
<br>
<span><b>Scaling:</b></span>
<br>
<br>
<input type="range" id="scaling0" min="0.1" max="50" step="0.1" value="1" style="width: 500px;" oninput="update_scaling(0)">
<br>
<br>
<span><b>Shear:</b></span>
<br>
<br>
<input type="range" id="shear0" min="45" max="135" step="1" value="90" style="width: 500px;" oninput="update_shear(0)">
<br>
<br>
<span>Object</span>
<table>
<tr>
<th></th>
<th>X axis</th>
<th>Y axis</th>
<th>Z axis</th>
</tr>
<tr>
<td>Trans.</td>
<td><input id="transX0" type="range" autocomplete="off" value="-25." max="80." min="-80." oninput="update_trans(0)"></td>
<td><input id="transY0" type="range" autocomplete="off" value="0." max="50." min="-50." oninput="update_trans(0)"></td>
<td><input id="transZ0" type="range" autocomplete="off" value="-50." max="0." min="-120." oninput="update_trans(0)"></td>
</tr>
<tr>
<td>Rotate</td>
<td><input id="rotateX0" type="range" autocomplete="off" value="0." max="180." min="-180." oninput="update_rotate(0)"></td>
<td><input id="rotateY0" type="range" autocomplete="off" value="0." max="180." min="-180." oninput="update_rotate(0)"></td>
<td><input id="rotateZ0" type="range" autocomplete="off" value="0." max="180." min="-180." oninput="update_rotate(0)"></td>
</tr>
</table>
<br>
<br>
</div>
<div class="col-sm">
<span>Model</span>
<span>Choose a model:</span>
<select id="modelSelector1" onchange="changeModel(1)">
<option value="Teapot">Teapot</option>
<option value="Csie">Csie</option>
<option value="Car_road">Car_road</option>
<option value="Fighter">Fighter</option>
<option value="Longteap">Longteap</option>
<option value="Mig27">Mig27</option>
<option value="Plant">Plant</option>
<option value="Tomcat">Tomcat</option>
<option value="Church_s">Church_s</option>
<option value="Easter">Easter</option>
<option value="Kangaroo">Kangaroo</option>
<option value="Mercedes">Mercedes</option>
<option value="Patchair">Patchair</option>
</select>
<br>
<span><b>Scaling:</b></span>
<br>
<br>
<input type="range" id="scaling1" min="0.1" max="50" step="0.1" value="1" style="width: 500px;" oninput="update_scaling(1)">
<br>
<br>
<span><b>Shear:</b></span>
<br>
<br>
<input type="range" id="shear1" min="45" max="135" step="1" value="90" style="width: 500px;" oninput="update_shear(1)">
<br>
<br>
<span>Object</span>
<table>
<tr>
<th></th>
<th>X axis</th>
<th>Y axis</th>
<th>Z axis</th>
</tr>
<tr>
<td>Trans.</td>
<td><input id="transX1" type="range" autocomplete="off" value="0." max="80." min="-80." oninput="update_trans(1)"></td>
<td><input id="transY1" type="range" autocomplete="off" value="0." max="50." min="-50." oninput="update_trans(1)"></td>
<td><input id="transZ1" type="range" autocomplete="off" value="-50." max="0." min="-120." oninput="update_trans(1)"></td>
</tr>
<tr>
<td>Rotate</td>
<td><input id="rotateX1" type="range" autocomplete="off" value="0." max="180." min="-180." oninput="update_rotate(1)"></td>
<td><input id="rotateY1" type="range" autocomplete="off" value="0." max="180." min="-180." oninput="update_rotate(1)"></td>
<td><input id="rotateZ1" type="range" autocomplete="off" value="0." max="180." min="-180." oninput="update_rotate(1)"></td>
</tr>
</table>
<br>
<br>
</div>
<div class="col-sm">
<span>Model</span>
<span>Choose a model:</span>
<select id="modelSelector2" onchange="changeModel(2)">
<option value="Teapot">Teapot</option>
<option value="Csie">Csie</option>
<option value="Car_road">Car_road</option>
<option value="Fighter">Fighter</option>
<option value="Longteap">Longteap</option>
<option value="Mig27">Mig27</option>
<option value="Plant">Plant</option>
<option value="Tomcat">Tomcat</option>
<option value="Church_s">Church_s</option>
<option value="Easter">Easter</option>
<option value="Kangaroo">Kangaroo</option>
<option value="Mercedes">Mercedes</option>
<option value="Patchair">Patchair</option>
</select>
<br>
<span><b>Scaling:</b></span>
<br>
<br>
<input type="range" id="scaling2" min="0.1" max="50" step="0.1" value="1" style="width: 500px;" oninput="update_scaling(2)">
<br>
<br>
<span><b>Shear:</b></span>
<br>
<br>
<input type="range" id="shear2" min="45" max="135" step="1" value="90" style="width: 500px;" oninput="update_shear(2)">
<br>
<br>
<span>Object</span>
<table>
<tr>
<th></th>
<th>X axis</th>
<th>Y axis</th>
<th>Z axis</th>
</tr>
<tr>
<td>Trans.</td>
<td><input id="transX2" type="range" autocomplete="off" value="25." max="80." min="-80." oninput="update_trans(2)"></td>
<td><input id="transY2" type="range" autocomplete="off" value="0." max="50." min="-50." oninput="update_trans(2)"></td>
<td><input id="transZ2" type="range" autocomplete="off" value="-50." max="0." min="-120." oninput="update_trans(2)"></td>
</tr>
<tr>
<td>Rotate</td>
<td><input id="rotateX2" type="range" autocomplete="off" value="0." max="180." min="-180." oninput="update_rotate(2)"></td>
<td><input id="rotateY2" type="range" autocomplete="off" value="0." max="180." min="-180." oninput="update_rotate(2)"></td>
<td><input id="rotateZ2" type="range" autocomplete="off" value="0." max="180." min="-180." oninput="update_rotate(2)"></td>
</tr>
</table>
<br>
<br>
</div>
</div>
</div>
</body>
</html>