-
Notifications
You must be signed in to change notification settings - Fork 0
/
assignment5.html
245 lines (205 loc) · 7.82 KB
/
assignment5.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
<!DOCTYPE html>
<html>
<head>
<script id="vertex-shader" type="x-shader/x-vertex">
precision mediump float;
attribute vec4 vPosition;
attribute vec2 vTextureCoord;
attribute vec3 vNormal;
uniform mat4 modelMatrix;
uniform mat4 viewMatrix;
uniform mat4 projectionMatrix;
varying vec2 fTextureCoord;
varying vec3 fNormal;
varying vec3 fVertex;
void main() {
vec4 vertex = modelMatrix * vPosition;
fNormal = vNormal;
fVertex = vertex.xyz;
fTextureCoord = vTextureCoord;
gl_Position = projectionMatrix * viewMatrix * vertex;
}
</script>
<script id="fragment-shader" type="x-shader/x-fragment">
precision mediump float;
uniform sampler2D uSampler;
uniform samplerCube uSamplerCube;
uniform int useCube;
uniform vec3 lightPosition;
uniform mat3 normalMatrix;
varying vec2 fTextureCoord;
varying vec3 fNormal;
varying vec3 fVertex;
void main() {
vec3 fLightDirection = fVertex.xyz - lightPosition.xyz;
float d = length(fLightDirection);
float attenuation = 1.0 / (0.01 + 0.01 * d + 0.03 * d * d);
vec4 ambientColor = vec4(0.8, 0.8, 0.8, 1.0); // No distance attenuation.
vec4 diffuseColor = vec4(1.0, 1.0, 1.0, 1.0) * attenuation;
vec4 specularColor = vec4(1.0, 1.0, 1.0, 1.0) * attenuation;
float ambientIntensity = 0.7;
float specularIntensity = 0.8;
float diffuseIntensity = 0.9;
float materialShininess = 30.0;
vec4 ambientTerm = vec4(ambientColor * ambientIntensity);
vec4 diffuseTerm = vec4(0.0, 0.0, 0.0, 1.0);
vec4 specularTerm = vec4(0.0, 0.0, 0.0, 1.0);
vec3 L = normalize(fLightDirection);
vec3 N = normalize(normalMatrix * fNormal);
float lambertTerm = dot(N, -L);
if (lambertTerm > 0.0) {
diffuseTerm = lambertTerm * diffuseColor * attenuation * diffuseIntensity;
if (lambertTerm > 0.0) {
vec3 E = normalize(- fVertex);
vec3 R = reflect(L, N);
float specular = pow(max(dot(R, E), 0.0), materialShininess);
specularTerm = specularColor * attenuation * specular * specularIntensity;
}
}
vec4 lightColor = ambientTerm + diffuseTerm + specularTerm;
vec4 textureColor;
if (useCube == 1) {
textureColor = textureCube(uSamplerCube, reflect(normalize(fVertex.xyz), N));
} else {
textureColor = texture2D(uSampler, vec2(fTextureCoord.st));
}
vec4 materialColor = vec4(textureColor.rgb * lightColor.rgb, textureColor.a);
gl_FragColor = materialColor;
}
</script>
<script type="text/javascript" src="common/webgl-utils.js"></script>
<script type="text/javascript" src="common/initShaders.js"></script>
<script type="text/javascript" src="common/MV.js"></script>
<script type="text/javascript" src="assignment5-shapes.js"></script>
<script type="text/javascript" src="assignment5.js"></script>
<script type="text/javascript" src="common/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="common/spectrum.js"></script>
<link rel="stylesheet" href="common/spectrum.css" />
<style type="text/css">
html, body { margin: 0; padding: 0; background-color: rgb(90, 90, 90); color: white;
font-family: Arial, sans-serif; font-size: 12px; }
.form-group { border: 1px solid white; padding: 3px; margin: 2px 0; }
.form-group h3 { margin: 0; font-size: 14px; }
.form-element { }
label { display: inline-block; width: 120px; vertical-align: middle; line-height: 2.3em; }
input, select { display: inline-block; vertical-align: middle; line-height: 2.3em; }
input, select, button { font-size: 12px; }
.slider { width: 250px; }
.left-form { float: left; padding: 10px; min-width: 420px; max-width: 420px; }
canvas { float: left; margin: 0; padding: 0; cursor: crosshair; }
a { color: white; }
img { display: none; }
</style>
</head>
<body>
<div class="left-form">
<h2>Objects</h2>
<div class="form-element">
<label for="texture">Texture</label>
<select id="texture">
<option value="0" selected="selected">Earth</option>
<option value="1">Checkerboard pattern</option>
<option value="2">Cube map</option>
</select>
</div>
<div class="form-element">
<label for="textureMapping">Type of mapping</label>
<select id="textureMapping">
<option value="0" selected="selected">Regular</option>
<option value="1">Variant 1</option>
<option value="2">Variant 2</option>
<option value="3">Randomize</option>
</select>
</div>
<div class="form-element">
<label for="numChecks">Number of checks</label>
<input type="range" class="slider" id="numChecks" min="2" max="64" step="2" value="16">
</div>
<div class="form-element">
<label for="checkColor">Color of checks</label>
<input type="text" id="checkColor">
</div>
<div class="form-element">
<label for="moonVisible">Show moon</label>
<input type="checkbox" id="moonVisible" checked>
</div>
<div class="form-group">
<h3>Rotation</h3>
<div class="form-element">
<label for="autorotateY">Animate y-axis</label>
<input type="checkbox" id="autorotateY" checked>
</div>
<div class="form-element">
<label for="rotateX">Rotate x</label>
<input type="range" class="slider" id="rotateX" min="0" max="360" step="1" value="0">
</div>
<div class="form-element">
<label for="rotateY">Rotate y</label>
<input type="range" class="slider" id="rotateY" min="0" max="360" step="1" value="0">
</div>
<div class="form-element">
<label for="rotateZ">Rotate z</label>
<input type="range" class="slider" id="rotateZ" min="0" max="360" step="1" value="0">
</div>
</div>
<div class="form-group">
<h3>Light position</h3>
<!--
<div class="form-element">
<label for="autorotateY">Animate y-axis</label>
<input type="checkbox" id="autorotateY" checked>
</div>
-->
<div class="form-element">
<label for="lightX">Light x</label>
<input type="range" class="slider" id="lightX" min="-10" max="10" step="0.1" value="0">
</div>
<div class="form-element">
<label for="lightY">Light y</label>
<input type="range" class="slider" id="lightY" min="-10" max="10" step="0.1" value="0">
</div>
<div class="form-element">
<label for="lightZ">Light z</label>
<input type="range" class="slider" id="lightZ" min="-10" max="10" step="0.1" value="0">
</div>
</div>
<div class="form-group">
<h3>Camera position</h3>
<div class="form-element">
<label for="cameraAnimated">Animate</label>
<input type="checkbox" id="cameraAnimated" checked>
</div>
<div class="form-element">
<label for="cameraPhi">Phi</label>
<input type="range" class="slider" id="cameraPhi" min="0" max="360" step="0.1" value="0">
</div>
<div class="form-element">
<label for="cameraTheta">Theta</label>
<input type="range" class="slider" id="cameraTheta" min="0" max="360" step="0.1" value="0">
</div>
<div class="form-element">
<label for="cameraRadius">Radius</label>
<input type="range" class="slider" id="cameraRadius" min="2" max="10" step="0.1" value="0">
</div>
</div>
</div>
<canvas id="gl-canvas" width="800" height="800">
Oops ... your browser doesn"t support the HTML5 canvas element
</canvas>
<img id="earth" src="images/earth-highres.jpg">
<img id="cubemap-negx" src="images/ame_shadow/shadowpeak_rt.jpg">
<img id="cubemap-negy" src="images/ame_shadow/shadowpeak_dn.jpg">
<img id="cubemap-negz" src="images/ame_shadow/shadowpeak_bk.jpg">
<img id="cubemap-posx" src="images/ame_shadow/shadowpeak_lf.jpg">
<img id="cubemap-posy" src="images/ame_shadow/shadowpeak_up.jpg">
<img id="cubemap-posz" src="images/ame_shadow/shadowpeak_ft.jpg">
<!--
<img id="cubemap-negx" src="images/negx.jpg">
<img id="cubemap-negy" src="images/negy.jpg">
<img id="cubemap-negz" src="images/negz.jpg">
<img id="cubemap-posx" src="images/posx.jpg">
<img id="cubemap-posy" src="images/posy.jpg">
<img id="cubemap-posz" src="images/posz.jpg">
-->
</body>
</html>