This repository has been archived by the owner on Jan 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
324 lines (267 loc) · 14.4 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
<!DOCTYPE html>
<html>
<head>
<title>Fractals 3D with WebGL— André Cardoso 65069 - Jorge Faustino 64441</title>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<!-- ***************************************
Class shaders
The vertex and fragment shaders.
The fragment shader is the same simple one.
***************************************** -->
<script id="shader-vs" type="x-shader/x-vertex">
attribute vec3 vPosition;
uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
varying vec4 fColor;
// For the Phong Illumination Model - NEW
attribute vec3 vNormal;
uniform vec4 lightPosition;
uniform vec4 viewerPosition;
// The light intensity multiplied by the material reflection coefficients
uniform vec3 ambientProduct;
uniform vec3 diffuseProduct;
uniform vec3 specularProduct;
uniform float shininess;
void main(void) {
// To allow seeing the points drawn
gl_PointSize = 5.0;
// Just converting the (x,y,z) vertices to Homogeneous Coord.
// And multiplying by the Projection and the Model-View matrix
gl_Position = uPMatrix * uMVMatrix * vec4(vPosition, 1.0);
// Phong Illumination Model
// pos is vertex position after applying the global transformation
vec3 pos = (uMVMatrix * vec4(vPosition, 1.0)).xyz;
// vector from vertex position to light source
vec3 L;
// check for directional light
if(lightPosition.w == 0.0)
L = normalize( lightPosition.xyz );
else
L = normalize( lightPosition.xyz - pos );
// Vector from the vertex position to the eye
vec3 E;
// The viewer is at the origin or at an indefinite distance
// on the ZZ axis
if(viewerPosition.w == 1.0)
// At the origin
E = -normalize( pos );
else
// On the ZZ axis
E = vec3(0,0,1);
// Halfway vector
vec3 H = normalize( L + E );
// Transform vertex normal into eye coordinates
vec4 N = normalize( uMVMatrix * vec4(vNormal, 0.0));
// Compute terms in the illumination equation
// Ambient component is constant
vec4 ambient = vec4( ambientProduct, 1.0 );
// Diffuse component
float dotProductLN = L[0] * N[0] + L[1] * N[1] + L[2] * N[2];
float cosNL = max( dotProductLN, 0.0 );
vec4 diffuse = vec4( diffuseProduct * cosNL, 1.0 );
// Specular component
float dotProductNH = N[0] * H[0] + N[1] * H[1] + N[2] * H[2];
float cosNH = pow( max( dotProductNH, 0.0 ), shininess );
vec4 specular = vec4( specularProduct * cosNH, 1.0 );
if( dotProductLN < 0.0 ) {
specular = vec4(0.0, 0.0, 0.0, 1.0);
}
// Adding the 3 components
fColor = ambient + diffuse + specular;
}
</script>
<script id="shader-fs" type="x-shader/x-fragment">
precision mediump float;
varying vec4 fColor;
void main(void) {
// Using the passed vertex color
gl_FragColor = fColor;
}
</script>
<!-- *********************************************
Class JS files
*********************************************** -->
<!-- Some useful functions for browser compatibility -->
<script type="text/javascript" src="classfiles/webgl-utils.js"></script>
<!-- Handling vectors and matrices -->
<script type="text/javascript" src="classfiles/maths.js"></script>
<!-- Processing triangle mesh models -->
<script type="text/javascript" src="classfiles/models.js"></script>
<!-- WebGL code -->
<script type="text/javascript" src="classfiles/initShaders.js"></script>
<!-- *******************************************
Custom implementation
********************************************* -->
<!-- Bootstrap -->
<script src="bootstrap/js/jquery-3.3.1.min.js"></script>
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.min.css">
<script src="bootstrap/js/bootstrap.min.js"></script>
<!-- Bootstrap Toggle Library -->
<!-- <link rel="stylesheet" href="bootstrap/css/bootstrap-toggle.min.css">
<script src="bootstrap/js/bootstrap-toggle.min.js"></script> -->
<!-- jsColor Library -->
<!-- <script src="js/jscolor.js"></script> -->
<!-- *******************************************
Our code here
********************************************* -->
<!-- Our implementation -->
<script type="text/javascript" src="myfractal.js"></script>
<!-- Custom CSS -->
<link rel="stylesheet" href="mystyle.css">
</head>
<body onload="runWebGL();">
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">3D Fractals</a>
<p class="navbar-text">CV 1º Project 2018/2019</p>
</div>
<p class="navbar-text navbar-right" style="padding-right: 10px;">André Cardoso & Jorge Faustino</p>
</div>
</nav>
<br /><br /> <br /><br />
<div class="container">
<div class="row">
<!-- painel de visualização -->
<div class="col-md-6">
<canvas id="my-canvas" style="border:1px solid #000000;" width="550" height="400"></canvas>
</div>
<!-- Paineis de opções -->
<div class="col-md-6">
<!-- Panel: X - Rotation -->
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">X - Rotation</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="col-sm-4">
<button id="x-on-button" class="btn btn-sm btn-info" type="button">On</button>
<button id="x-off-button" class="btn btn-sm btn-info" >Off</button>
</div>
<div class="col-sm-4">
<button id="x-direction-button" class="btn btn-sm btn-info">Change Direction</button>
</div>
<div class="col-sm-4">
<button id="x-slower-button" class="btn btn-sm btn-info">Slower</button>
<button id="x-faster-button" class="btn btn-sm btn-info">Faster</button>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Panel: Y - Rotation -->
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Y - Rotation</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="col-sm-4">
<button id="y-on-button" class="btn btn-sm btn-info" >On</button>
<button id="y-off-button" class="btn btn-sm btn-info" >Off</button>
</div>
<div class="col-sm-4">
<button id="y-direction-button" class="btn btn-sm btn-info">Change Direction</button>
</div>
<div class="col-sm-4">
<button id="y-slower-button" class="btn btn-sm btn-info">Slower</button>
<button id="y-faster-button" class="btn btn-sm btn-info">Faster</button>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Panel: Z - Rotation -->
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Z - Rotation</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="col-sm-4">
<button id="z-on-button" class="btn btn-sm btn-info" >On</button>
<button id="z-off-button" class="btn btn-sm btn-info" >Off</button>
</div>
<div class="col-sm-4">
<button id="z-direction-button" class="btn btn-sm btn-info">Change Direction</button>
</div>
<div class="col-sm-4">
<button id="z-slower-button" class="btn btn-sm btn-info">Slower</button>
<button id="z-faster-button" class="btn btn-sm btn-info">Faster</button>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- + / - -->
<div class="row">
<div class="col-sm-2">
<button id="decrease-button" class="btn btn-sm btn-info">-</button>
<button id="increase-button" class="btn btn-sm btn-info">+</button>
</div>
<div class="col-sm-10">
<p>Iteration number: <span id="num-iterations">0</span></p>
</div>
</div>
</div>
</div>
<br />
<!-- Panel de configurações -->
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Painel de Configurações</h3>
</div>
<div class="panel-body">
<div class="col-sm-4">
<p>Fractal:
<select id="fractal-selection">
<option value="0">Sierpinski Gasket</option>
<option value="1">Koch Snowflake</option>
<option value="2">Menger Sponge</option>
<option value="3">Mosely Snowflake</option>
<option value="4">My custom fractal</option>
</select>
</p>
<p>Color: </p>
</div>
<div class="col-sm-4">
<p>Projection type:
<select id="projection-selection">
<option value="0">Orthogonal Projection</option>
<option value="1">Perspective Projection</option>
</select>
</p>
<p>Rendering mode:
<select id="rendering-mode-selection">
<option value="0">Filled Triangles</option>
<option value="1">Wireframe</option>
<option value="2">Vertices</option>
</select>
</p>
</div>
<div class="col-sm-4">
<button class="btn btn-sm btn-info" id="reset-button">Reset</button>
</div>
</div>
</div>
</div>
</div>
</div>
<br />
<footer >
Trabalho desenvolvido no ambido da disciplicna Computação Visual do curso de Eng. Computadores e Telemática da Universidade de Aveiro, 2018-2019
</footer>
</body>
</html>