-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmocap.html
129 lines (95 loc) · 3.72 KB
/
mocap.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
<!DOCTYPE html>
<html>
<head>
<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="./axis.js"></script>
<script type="text/javascript" src="./sphere.js"></script>
<script type="text/javascript" src="./floor.js"></script>
<script type="text/javascript" src="./test1.bvh.js"></script>
<script type="text/javascript" src="./test2.bvh.js"></script>
<script src="./common/require.js"></script>
<script type="text/javascript" src="mocap.js"></script>
<!------------------------------------------------------------>
<!------------------------ Line shaders ---------------------->
<!------------------------------------------------------------>
<script id="line-vshader" type="x-shader/x-vertex">
attribute vec4 vPosition;
attribute vec4 vColor;
varying vec4 fColor;
uniform mat4 mvMatrix;
uniform mat4 pMatrix;
void main() {
gl_Position = pMatrix*mvMatrix*vPosition;
fColor = vColor;
}
</script>
<script id="line-fshader" type="x-shader/x-fragment">
#ifdef GL_ES
precision highp float;
#endif
varying vec4 fColor;
void main() {
gl_FragColor = fColor;
}
</script>
<!------------------------------------------------------------>
<!---------------------- Sphere shaders ---------------------->
<!------------------------------------------------------------>
<script id="sphere-vshader" type="x-shader/x-vertex">
attribute vec4 vPosition;
attribute vec4 vNormal;
attribute vec4 vColor;
varying vec4 fColor;
varying vec3 vLighting;
uniform mat4 mvMatrix;
uniform mat4 pMatrix;
uniform mat4 nMatrix;
void main() {
gl_Position = pMatrix*mvMatrix*vPosition;
// Material properties
vec3 ka = vec3(0.0, 0.0, 0.3);
vec3 kd = vec3(0.5, 0.5, 0.5);
vec3 ks = vec3(0.3, 0.3, 0.5);
// Light colors
vec3 La = vec3(1.0, 1.0, 1.0);
vec3 Ld = vec3(1.0, 1.0, 1.0);
vec3 Ls = vec3(1.0, 1.0, 1.0);
// Set the light position
vec3 lightPosition = vec3(10, 30, 50);
// Light direction in eye coordinates
vec3 l = lightPosition - gl_Position.xyz;
l = normalize(l);
// normal in eye coordinates
vec3 n = normalize((nMatrix * vNormal).xyz);
// specular values
float alpha = 10.0;
vec3 v = normalize(vec3(0.0, 0.0, 10.0) - gl_Position.xyz);
vec3 r = max(dot(l, n), 0.0)*n*vec3(2.0, 2.0, 2.0)-l;
vec3 ambient = ka*La;
vec3 diffuse = kd*Ld*max(dot(n, l), 0.0);
vec3 specular = ks*Ls*max(pow(max(dot(r,v), 0.0), alpha), 0.0);
vec3 lcolor = ambient + diffuse + specular;
fColor = vec4(lcolor, vColor.a);
}
</script>
<script id="sphere-fshader" type="x-shader/x-fragment">
precision mediump float;
varying vec4 fColor;
varying vec3 vLighting;
void main() {
//gl_FragColor = vec4(fColor.xyz * vLighting, fColor.a);
//gl_FragColor = vec4(vLighting, fColor.a);
gl_FragColor = fColor;
}
</script>
</head>
<body>
<input type="file" id="fileInput">
<br>
<canvas id="gl-canvas" width="512" height="512">
Oops ... your browser doesn't support the HTML5 canvas element
</canvas>
</body>
</html>