-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplotter.html
478 lines (411 loc) · 15 KB
/
plotter.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
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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>VR Plotter</title>
<!--<link rel="stylesheet" type="text/css" href="style.css">-->
<script id="vertexsphere" type="x-shader">
precision mediump float;
attribute vec3 aVert;
attribute vec3 aNormal;
uniform mat4 uMMatrix;
uniform mat4 uVMatrix;
uniform mat4 uPMatrix;
uniform vec3 uPos;
uniform float uRadius;
uniform vec3 uColor;
varying vec4 vCol;
varying vec4 aNormalInterp;
varying vec3 vertPos;
varying vec3 lightPos;
void main() {
// apply transformations
mat4 scale = mat4(
vec4(uRadius, 0.0,0.0, 0.0),
vec4(0.0, uRadius,0.0, 0.0),
vec4(0.0, 0.0, uRadius, 0.0),
vec4(0.0, 0.0, 0.0, 1.0)
);
gl_Position = uPMatrix * uVMatrix*uMMatrix * (scale*vec4(aVert, 1.0)+vec4(uPos,0.0));
vertPos = (uVMatrix*uMMatrix * (scale*vec4(aVert, 1.0)+vec4(uPos,0.0))).xyz;
// set color
aNormalInterp = uVMatrix*uMMatrix * vec4(aNormal,0.0);
vCol = vec4(uColor.x, uColor.y, uColor.z, 1.0);
lightPos = ( uVMatrix*uMMatrix *vec4(2.0,1.0,-2.0,0.0)).xyz;
}
</script>
<script id="fragmentsphere" type="x-shader">
precision mediump float;
varying vec4 vCol;
varying vec4 aNormalInterp;
varying vec3 vertPos;
varying vec3 lightPos;
//out vec4 fragColor;
const float shininess = 32.0;
const float screenGamma =2.2;
void main() {
vec3 ambientColor = vCol.xyz/4.0;
vec3 diffuseColor = vCol.xyz;
vec3 specColor = vec3(1.0,1.0,1.0);
vec3 normal = normalize(aNormalInterp.xyz);
vec3 lightDir = normalize(lightPos );
float lambertian = max(dot(lightDir,normal), 0.0);
float specular = 0.0;
if(lambertian > 0.0) {
vec3 viewDir = normalize(-vertPos);
// this is blinn phong
vec3 halfDir = normalize(lightDir + viewDir);
float specAngle = max(dot(halfDir, normal), 0.0);
specular = pow(specAngle, shininess);
vec3 reflectDir = reflect(-lightDir, normal);
specAngle = max(dot(reflectDir, viewDir), 0.0);
// note that the exponent is different here
specular = pow(specAngle, shininess/4.0);
}
vec3 colorLinear = ambientColor +
lambertian * diffuseColor +
specular * specColor;
// apply gamma correction (assume ambientColor, diffuseColor and specColor
// have been linearized, i.e. have no gamma correction in them)
vec3 colorGammaCorrected = pow(colorLinear, vec3(1.0/screenGamma));
// use the gamma corrected color in the fragment
gl_FragColor = vec4(colorGammaCorrected, 1.0);
// use vertex color
//fragColor = vCol;
}
</script>
<script id="hvertex" type="x-shader">
precision mediump float;
attribute vec3 pos;
attribute vec3 color;
attribute float size;
uniform mat4 uMMatrix;
uniform mat4 uVMatrix;
uniform mat4 uPMatrix;
uniform float uTreshold;
varying vec4 vCol;
varying float vSize;
varying float vTreshold;
void main() {
// apply transformations
vCol = vec4(color, 1.0);
gl_PointSize = abs(size)*8.0;
vSize = size;
vTreshold = uTreshold;
gl_Position = uPMatrix * uVMatrix*uMMatrix * vec4(pos,1.0);
}
</script>
<script id="hfragment" type="x-shader">
precision mediump float;
varying vec4 vCol;
varying float vSize;
varying float vTreshold;
//out vec4 fragColor;
void main() {
if(vSize<vTreshold) discard;
gl_FragColor = vCol;
// use vertex color
//fragColor = vCol;
}
</script>
<script id="h2vertex" type="x-shader">
precision mediump float;
attribute vec3 pos;
attribute vec3 color;
attribute float size;
attribute vec3 normal;
uniform mat4 uMMatrix;
uniform mat4 uVMatrix;
uniform mat4 uPMatrix;
uniform mat4 uNMatrix;
uniform float uTreshold;
uniform vec3 uCameraPos;
uniform vec3 uLightPos;
varying vec4 vCol;
varying float vSize;
varying float vTreshold;
varying vec3 vNormal;
varying vec3 vPos;
varying vec3 vLight;
varying vec3 vCamera;
void main() {
// apply transformations
vCol = vec4(color, 1.0);
//gl_PointSize = abs(size)*8.0;
vSize = size;
vTreshold = uTreshold;
//mat3 nMatrix =transpose(inverse(mat3(uVMatrix*uMMatrix)));
vNormal = normalize((uNMatrix*vec4(normal,1.0)).xyz);
vPos = (uVMatrix*uMMatrix*vec4(pos,1.0)).xyz;
vLight = normalize(uLightPos - vPos);
vCamera = normalize(uCameraPos - vPos);
gl_Position = uPMatrix * uVMatrix*uMMatrix * vec4(pos,1.0);
}
</script>
<script id="h2fragment" type="x-shader">
precision mediump float;
// uniform vec3 uLightPos;
varying vec4 vCol;
varying float vSize;
varying float vTreshold;
varying vec3 vNormal;
varying vec3 vPos;
varying vec3 vLight;
varying vec3 vCamera;
const float shininess = 16.0;
const float screenGamma = 2.2; // Assume the monitor is calibrated to the sRGB color space
void main() {
//if(vSize<vTreshold) discard;
vec3 ambientColor = vCol.rgb/4.0;
vec3 diffuseColor = vCol.rgb;
vec3 specColor = vec3(1.0+vCol.rgb);
vec3 light = normalize(vLight);
vec3 eye = normalize(-vPos);
vec3 normal = normalize(vNormal);
float diffuse = max(dot(normal,light),0.0);
vec3 colorLinear = diffuse*diffuseColor+ambientColor;
vec3 colorGammaCorrected = pow(colorLinear, vec3(1.0/screenGamma));
// use the gamma corrected color in the fragment
gl_FragColor = vec4(colorGammaCorrected, 1.0);
//gl_FragColor = vCol;
}
</script>
<script id="vertex" type="x-shader">
attribute vec3 inputPosition;
attribute vec3 inputNormal;
attribute vec2 textureCoords;
attribute vec3 textureCoords3d;
uniform mat4 projection, model, view, camera;
varying vec3 normalInterp;
varying vec3 vertPos;
varying vec2 texCoords;
varying vec3 texCoords3d;
void main(){
gl_Position = projection * camera * view * model * vec4(inputPosition, 1.0);
gl_PointSize =10.0;
vec4 vertPos4 = view * model * vec4(inputPosition, 1.0);
vertPos = vec3(vertPos4) / vertPos4.w;
normalInterp = vec3(view * model * vec4(inputNormal, 0.0));
texCoords = textureCoords;
texCoords3d =textureCoords3d;
}
</script>
<script id="fragment" type="x-shader">
precision mediump float;
varying vec3 normalInterp;
varying vec3 vertPos;
varying vec2 texCoords;
varying vec3 texCoords3d;
uniform vec4 uColor;
uniform vec4 uColor2;
uniform vec4 uColor3;
uniform float uDice;
uniform float uTextureOffset;
uniform sampler2D uSampler;
uniform vec3 uLightPos;
const vec3 lightPos = vec3(0.0,0.0,0.0);
const float shininess = 16.0;
const float screenGamma = 2.2; // Assume the monitor is calibrated to the sRGB color space
vec3 mod289(vec3 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
vec4 mod289(vec4 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
vec4 permute(vec4 x) {
return mod289(((x*34.0)+1.0)*x);
}
vec4 taylorInvSqrt(vec4 r)
{
return 1.79284291400159 - 0.85373472095314 * r;
}
float snoise(vec3 v)
{
const vec2 C = vec2(1.0/6.0, 1.0/3.0) ;
const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);
// First corner
vec3 i = floor(v + dot(v, C.yyy) );
vec3 x0 = v - i + dot(i, C.xxx) ;
// Other corners
vec3 g = step(x0.yzx, x0.xyz);
vec3 l = 1.0 - g;
vec3 i1 = min( g.xyz, l.zxy );
vec3 i2 = max( g.xyz, l.zxy );
// x0 = x0 - 0.0 + 0.0 * C.xxx;
// x1 = x0 - i1 + 1.0 * C.xxx;
// x2 = x0 - i2 + 2.0 * C.xxx;
// x3 = x0 - 1.0 + 3.0 * C.xxx;
vec3 x1 = x0 - i1 + C.xxx;
vec3 x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y
vec3 x3 = x0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y
// Permutations
i = mod289(i);
vec4 p = permute( permute( permute(
i.z + vec4(0.0, i1.z, i2.z, 1.0 ))
+ i.y + vec4(0.0, i1.y, i2.y, 1.0 ))
+ i.x + vec4(0.0, i1.x, i2.x, 1.0 ));
// Gradients: 7x7 points over a square, mapped onto an octahedron.
// The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294)
float n_ = 0.142857142857; // 1.0/7.0
vec3 ns = n_ * D.wyz - D.xzx;
vec4 j = p - 49.0 * floor(p * ns.z * ns.z); // mod(p,7*7)
vec4 x_ = floor(j * ns.z);
vec4 y_ = floor(j - 7.0 * x_ ); // mod(j,N)
vec4 x = x_ *ns.x + ns.yyyy;
vec4 y = y_ *ns.x + ns.yyyy;
vec4 h = 1.0 - abs(x) - abs(y);
vec4 b0 = vec4( x.xy, y.xy );
vec4 b1 = vec4( x.zw, y.zw );
//vec4 s0 = vec4(lessThan(b0,0.0))*2.0 - 1.0;
//vec4 s1 = vec4(lessThan(b1,0.0))*2.0 - 1.0;
vec4 s0 = floor(b0)*2.0 + 1.0;
vec4 s1 = floor(b1)*2.0 + 1.0;
vec4 sh = -step(h, vec4(0.0));
vec4 a0 = b0.xzyw + s0.xzyw*sh.xxyy ;
vec4 a1 = b1.xzyw + s1.xzyw*sh.zzww ;
vec3 p0 = vec3(a0.xy,h.x);
vec3 p1 = vec3(a0.zw,h.y);
vec3 p2 = vec3(a1.xy,h.z);
vec3 p3 = vec3(a1.zw,h.w);
//Normalise gradients
vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3)));
p0 *= norm.x;
p1 *= norm.y;
p2 *= norm.z;
p3 *= norm.w;
// Mix final noise value
vec4 m = max(0.6 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0);
m = m * m;
return 42.0 * dot( m*m, vec4( dot(p0,x0), dot(p1,x1),
dot(p2,x2), dot(p3,x3) ) );
}
float turbulence(vec3 pos,float size)
{
float value = 0.0, initialSize = size;
float size2 = size;
for(float s =0.0; s<5.0; s+=1.0)
{
value += snoise(pos/size2) * size2;
size2/=2.0;
}
return value / initialSize;
}
float wood(vec3 pos)
{
float xyPeriod = 12.0; //number of rings
float turbPower = 0.02; //makes twists
float turbSize = 32.0; //initial size of the turbulence
float noiseWidth = 256.0;
float noiseHeight = 256.0;
float xValue = pos.x/noiseWidth;
float yValue = pos.y/noiseHeight;
float distValue = sqrt(xValue * xValue + yValue * yValue) + turbPower * turbulence(vec3(pos.x,pos.y,pos.z*0.1), turbSize) ;
float sineValue = 0.5*abs(sin(2.0 * xyPeriod * distValue * 3.14159));
return sineValue;
}
float marble(vec3 pos)
{
float noiseWidth = 256.0;
float noiseHeight = 256.0;
float xPeriod = 5.0; //defines repetition of marble lines in x direction
float yPeriod = 10.0; //defines repetition of marble lines in y direction
//turbPower = 0 ==> it becomes a normal sine pattern
float turbPower = 5.0; //makes twists
float turbSize = 32.0; //initial size of the turbulence
float xyValue = pos.x * xPeriod / noiseWidth + pos.y * yPeriod / noiseHeight + turbPower * turbulence(pos,turbSize);
float sineValue = abs(sin(xyValue * 3.14159));
return sineValue;
}
void main() {
vec4 c1 =texture2D(uSampler, vec2(texCoords.s,texCoords.t));
float luma = 0.0;
if(uDice<0.5)
{
luma = marble((texCoords3d+vec3(0,0,uTextureOffset))*100.0);
}
else {
luma = wood((texCoords3d+vec3(0,0,uTextureOffset))*1200.0);
}
float lumambient = luma/2.0;
vec4 c = vec4(mix(uColor.xyz,uColor3.xyz,luma),1.0);
if( c1.a>0.2)
{
c = vec4(mix(c.xyz,uColor2.xyz,c1.a),c1.a);
}
//c.a = c1.a;
vec3 ambientColor = c.xyz/4.0;
vec3 diffuseColor = c.xyz;
vec3 specColor = vec3(0.8,0.8,0.8);
vec3 normal = normalize(normalInterp);
vec3 lightDir = normalize(uLightPos - vertPos);
float lambertian = max(dot(lightDir,normal), 0.0);
float specular = 0.0;
if(lambertian > 0.0) {
vec3 viewDir = normalize(-vertPos);
// this is blinn phong
vec3 halfDir = normalize(lightDir + viewDir);
float specAngle = max(dot(halfDir, normal), 0.0);
specular = pow(specAngle, shininess);
vec3 reflectDir = reflect(-lightDir, normal);
specAngle = max(dot(reflectDir, viewDir), 0.0);
// note that the exponent is different here
specular = pow(specAngle, shininess);
}
vec3 colorLinear = ambientColor +
lambertian * diffuseColor +
specular * specColor;
// apply gamma correction (assume ambientColor, diffuseColor and specColor
// have been linearized, i.e. have no gamma correction in them)
vec3 colorGammaCorrected = pow(colorLinear, vec3(1.0/screenGamma));
// use the gamma corrected color in the fragment
gl_FragColor = vec4(colorGammaCorrected, 1.0);
}
</script>
</head>
<body onload="PlotterLib.startdice(); " onresize="PlotterLib.resize();" id="bod" style="height: 100%; overflow:hidden;">
<layer id="canvaslayer" style=" z-index:-1; top:0; left:0; position:absolute;">
<canvas tabIndex="0" id="glcanvas" width="600" height="600" style="overscroll-behavior:none;">
Your browser doesn't appear to support the
<code><canvas></code> element.
</canvas>
</layer>
<layer id="textlayer" style=" z-index:0; top:0; left:0; position:absolute;">
<button style="width:75px;height:25px" onclick="PlotterLib.toggleWalls()">ToggleWalls</button>
<button style="width:75px;height:25px" onclick="PlotterLib.toggleFlatShading()">Shading</button>
<button style="width:75px;height:25px" onclick="PlotterLib.togglePoints()">Points</button>
<button style="width:75px;height:25px" onclick="PlotterLib.toggleMesh()">Mesh</button>
<button style="width:75px;height:25px" onclick="PlotterLib.toggleAxis()">Axis</button>
<button style="width:75px;height:25px" onclick="PlotterLib.toggleLegend()">Legend</button>
<button style="width:75px;height:25px" onclick="PlotterLib.fullScreen()">Fullscreen</button>
<button style="width:75px;height:25px" onclick="PlotterLib.screenshot()">Screenshot</button>
<button style="width:120px;height:25px" id="stop-start">Start VR display</button>
<label>
<input type="file" id="inputfiledialog"/>
</label>
<br/>
<button id="recordButton">record</button>
<button id="playButton">play</button>
<button id="downloadButton">download</button>
<input type="text" name="filename" id="filename" value="test.webm">
<br/>
<input type="range" id="tresholdslider" min="0" max="1" step = "0.001"/>
<input type="color" id="colorinput" />
<input type="range" id="alphaslider" min="0" max="255" step="1"/>
<br/>
<canvas id="legend" width="300" height="100"/></canvas>
<!--<br/>
<p id="fillertext" style="color:white">Tex Filler</p>-->
</layer>
<script type="text/javascript" src="connection.js"></script>
<script type="text/javascript" src="vema/vema.js"></script>
<script type="text/javascript" src="shader.js"></script>
<script type="text/javascript" src="sphere.js"></script>
<script type="text/javascript" src="walls.js"></script>
<script type="text/javascript" src="vr.js"></script>
<script type="text/javascript" src="legend.js"></script>
<script type="text/javascript" src="axis.js"></script>
<script type="text/javascript" src="dataReader.js"></script>
<script type="text/javascript" src="plotter.js"></script>
</body>
</html>