This repository was archived by the owner on Apr 25, 2023. It is now read-only.
forked from Cocobio/aBrainVis_WebGL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
253 lines (194 loc) · 6.82 KB
/
index.html
File metadata and controls
253 lines (194 loc) · 6.82 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
<!DOCTYPE HTML>
<html lang="en">
<meta charset="utf-8">
<div id="head">
<head>
<title>aBrainVis</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<!-- Listing different shaders. First is a webgl2 version, and the second a webgl1 -->
<script id="bundle" type="x-shader/x-vertex">#version 300 es
precision highp float;
precision highp int;
in vec3 aVertexPosition;
in vec3 aVertexNormal;
in int aVertexColorId;
out vec4 color;
uniform sampler2D uColorTable;
uniform mat4 uModel;
uniform mat4 uView;
uniform mat4 uProj;
struct LightInfo {
vec4 pos; // Posicion de la luz.
vec3 La; // Intensidad de luz ambiental.
vec3 Ld; // Intensidad de luz difusa.
vec3 Ls; // Intensidad de luz especular.
};
uniform LightInfo uLight;
struct MaterialInfo {
float Ka; // Reflectividad ambiental.
float Kd; // Reflectividad difusa.
float Ks; // Reflectividad especular.
float shininess; // Coeficiente de reflexion especular.
};
uniform MaterialInfo uMaterial;
void main() {
// lighting.
vec4 p = uView*uModel*vec4(aVertexPosition, 1.0);
vec3 n = normalize(mat3(uView*uModel)*aVertexNormal);
vec3 l = normalize(vec3(uLight.pos - p));
vec3 v = normalize(-p.xyz);
vec3 r = reflect(-l, n);
vec3 ambi = uLight.La*uMaterial.Ka;
vec3 diff = uLight.Ld*uMaterial.Kd*max( dot(l, n), 0.0);
vec3 spec = uLight.Ls*uMaterial.Ks*pow(max(dot(r,v), 0.0), uMaterial.shininess);
// outputs
color = vec4(ambi + diff + spec, 1.0) * texelFetch(uColorTable, ivec2(aVertexColorId, 0), 0);
gl_Position = uProj*uView*uModel*vec4(aVertexPosition, 1.0);
}
</script>
<script id="bundle-webgl1" type="x-shader/x-vertex">
precision highp float;
precision highp int;
attribute vec3 aVertexPosition;
attribute vec3 aVertexNormal;
attribute float aVertexColorId;
varying vec4 color;
uniform sampler2D uColorTable;
uniform mat4 uModel;
uniform mat4 uView;
uniform mat4 uProj;
uniform float uTextureLength;
struct LightInfo {
vec4 pos; // Posicion de la luz.
vec3 La; // Intensidad de luz ambiental.
vec3 Ld; // Intensidad de luz difusa.
vec3 Ls; // Intensidad de luz especular.
};
uniform LightInfo uLight;
struct MaterialInfo {
float Ka; // Reflectividad ambiental.
float Kd; // Reflectividad difusa.
float Ks; // Reflectividad especular.
float shininess; // Coeficiente de reflexion especular.
};
uniform MaterialInfo uMaterial;
void main() {
// lighting.
vec4 p = uView*uModel*vec4(aVertexPosition, 1.0);
vec3 n = normalize(mat3(uView*uModel)*aVertexNormal);
vec3 l = normalize(vec3(uLight.pos - p));
vec3 v = normalize(-p.xyz);
vec3 r = reflect(-l, n);
vec3 ambi = uLight.La*uMaterial.Ka;
vec3 diff = uLight.Ld*uMaterial.Kd*max( dot(l, n), 0.0);
vec3 spec = uLight.Ls*uMaterial.Ks*pow(max(dot(r,v), 0.0), uMaterial.shininess);
// outputs
color = vec4(ambi + diff + spec, 1.0) * texture2D(uColorTable, vec2((aVertexColorId+0.5)/uTextureLength,0.0));
gl_Position = uProj*uView*uModel*vec4(aVertexPosition, 1.0);
}
</script>
<script id="coordinate-system" type="x-shader/x-vertex">#version 300 es
in vec3 aVertexPosition;
out vec4 color;
uniform mat4 uModelArray[3];
uniform mat4 uView;
uniform mat4 uProj;
uniform vec4 uColorArray[3];
void main() {
color = uColorArray[gl_InstanceID];
gl_Position = uProj*uView*uModelArray[gl_InstanceID]*vec4(aVertexPosition, 1.0);
}
</script>
<script id="coordinate-system-webgl1" type="x-shader/x-vertex">
attribute vec3 aVertexPosition;
varying vec4 color;
uniform mat4 uModelArray[3];
uniform mat4 uView;
uniform mat4 uProj;
uniform int uAxisID;
uniform vec4 uColorArray[3];
void main() {
color = uColorArray[uAxisID];
gl_Position = uProj*uView*uModelArray[uAxisID]*vec4(aVertexPosition, 1.0);
}
</script>
<script id="boundingbox" type="x-shader/x-vertex">#version 300 es
in vec3 aVertexPosition;
out vec4 color;
uniform mat4 uModel;
uniform mat4 uBBModel;
uniform mat4 uView;
uniform mat4 uProj;
void main() {
color = vec4(1.0, 1.0, 1.0, 1.0);
gl_Position = uProj*uView*uModel*uBBModel*vec4(aVertexPosition, 1.0);
}
</script>
<script id="boundingbox-webgl1" type="x-shader/x-vertex">
attribute vec3 aVertexPosition;
varying vec4 color;
uniform mat4 uModel;
uniform mat4 uBBModel;
uniform mat4 uView;
uniform mat4 uProj;
void main() {
color = vec4(1.0, 1.0, 1.0, 1.0);
gl_Position = uProj*uView*uModel*uBBModel*vec4(aVertexPosition, 1.0);
}
</script>
<script id="standard-fragment" type="x-shader/x-fragment">#version 300 es
precision highp float;
in vec4 color;
out vec4 outColor;
void main() {
outColor = color;
}
</script>
<script id="standard-fragment-webgl1" type="x-shader/x-fragment">
precision highp float;
varying vec4 color;
void main() {
gl_FragColor = color;
}
</script>
<!-- Utilities -->
<script type="text/javascript" src="Utilities/gl-matrix.js"></script>
<script type="text/javascript" src="Utilities/spherical-camera.js"></script>
<script type="text/javascript" src="Utilities/abrain-utilities.js"></script>
<!-- Utilities on WebGL -->
<script type="text/javascript" src="Utilities/webgl-utils.js"></script>
<!-- Visualization classes -->
<script type="text/javascript" src="VisualizationClasses/base-visualization.js"></script>
<script type="text/javascript" src="VisualizationClasses/coordinate-system.js"></script>
<script type="text/javascript" src="VisualizationClasses/bundle.js"></script>
<script type="text/javascript" src="VisualizationClasses/boundingbox.js"></script>
<!-- Only for debugin ===> Comment on deploy -->
<script type="text/javascript" src="Utilities/webgl-debug.js"></script>
<!-- Main and setup -->
<script type="text/javascript" src="main-setup.js"></script>
<style >
html, body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
border: 0;
overflow: hidden;
}
</style>
<button id="toggleFS">Go fullscreen</button>
<input type="file" id="addFile" multiple name="file" style="display: none">
<input type="button" value="Browse..." onclick="document.getElementById('addFile').click();" />
<button id="deleteAll" value="Delete">Delete</button>
<button id="randomColors" >Shuffle colors</button>
<!-- Added onfocus on the select tag in order to avoid orbiting the camera when the combo box was selected -->
<select id="SampleFiles" onchange="loadSampleFile(value);" onfocus="aBrainGL.orbit=false">
<option value="" selected disabled hidden>Choose sample file</option>
</select>
<input type="checkbox" id="toggleBB" name="toogle BoundingBoxes" checked> toggle bb
</head>
</div>
<body onload="startup();">
<canvas id="myGLCanvas" style="touch-action:none" oncontextmenu="return false"></canvas>
</body>
</html>