-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
70 lines (49 loc) · 1.92 KB
/
index.html
File metadata and controls
70 lines (49 loc) · 1.92 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
<html>
<head>
<title>WebGL</title>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript" src="gl-matrix-min.js"></script>
<script type="text/javascript" src="webgl-utils.js"></script>
<script type="text/javascript" src="keyregisterer.js"></script>
<script id="shader-fs" type="x-shader/x-fragment">
precision mediump float;
varying vec4 vColor;
void main(void) {
gl_FragColor = vColor;
}
</script>
<script id="shader-vs" type="x-shader/x-vertex">
attribute vec3 aVertexPosition;
attribute vec3 aNormal;
attribute vec4 aColor;
uniform mat4 rotMat;
uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
uniform mat3 uNMatrix;
uniform float uAmbient;
uniform vec3 lightDirection;
varying vec4 vColor;
void main(void) {
vec3 oNormal = (normalize(rotMat * vec4(aNormal, 1.0)).xyz);
gl_Position = uPMatrix * uMVMatrix * rotMat * vec4(aVertexPosition, 1.0);
float total = dot(lightDirection, oNormal)*(1.0-uAmbient);
float spec = pow(dot(oNormal, (normalize(gl_Position).xyz + lightDirection)/2.0), 5.0)*5.0;
if(spec < 0.0){
spec = 0.0;
}
if(total > 0.0){
vColor = aColor*vec4(total+uAmbient, total+uAmbient, total+uAmbient, 1.0) + vec4(spec, spec, spec, 0.0);
}else{
vColor = aColor*vec4(uAmbient, uAmbient, uAmbient, 1.0);
}
}
</script>
<script src="sphere.js"></script>
<script src="glFunctions.js"></script>
<script src="main.js"></script>
<link rel="stylesheet" href="styles.css">
</head>
<body onLoad="webGLStart();">
<canvas id="cc" style="border: none;" onClick="drawScene();"></canvas>
</body>
</html>