-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
index.html
217 lines (209 loc) · 7.74 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<base href="/glsl-canvas/">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=2,user-scalable=yes">
<title>GlslCanvas</title>
<link rel="stylesheet" type="text/css" href="/glsl-canvas/css/docs.min.css">
<script type="text/javascript" src="/glsl-canvas/js/vendors.js"></script>
<script type="text/javascript" src="/glsl-canvas/js/glsl-canvas.js"></script>
</head>
<body>
<h3>WebGl 1</h3>
<div class="examples">
<div class="example">
<h4>fragment via attribute</h4>
<canvas class="canvas" controls data-fragment-url="/glsl-canvas/shaders/example-0.glsl"></canvas>
<button type="button" class="btn btn-toggle">toggle</button>
</div>
<div class="example">
<h4>buffers</h4>
<canvas class="canvas" controls data-fragment-url="/glsl-canvas/shaders/example-1.glsl"></canvas>
<button type="button" class="btn btn-toggle">toggle</button>
</div>
<div class="example">
<h4>texture url in fragment shader</h4>
<canvas class="canvas" controls data-fragment-url="/glsl-canvas/shaders/example-2.glsl"></canvas>
<button type="button" class="btn btn-toggle">toggle</button>
</div>
<div class="example">
<h4>update texture uniform</h4>
<canvas class="canvas" controls data-fragment-url="/glsl-canvas/shaders/example-3.glsl"></canvas>
<button type="button" class="btn btn-toggle">toggle</button>
</div>
<div class="example">
<h4>video texture</h4>
<canvas class="canvas" controls data-fragment-url="/glsl-canvas/shaders/example-4.glsl"></canvas>
<button type="button" class="btn btn-toggle">toggle</button>
</div>
<div class="example">
<h4>animation</h4>
<canvas class="canvas" controls data-fragment-url="/glsl-canvas/shaders/example-5.glsl"></canvas>
<button type="button" class="btn btn-toggle">toggle</button>
</div>
<div class="example">
<h4>vec2 update</h4>
<canvas class="canvas" controls data-fragment-url="/glsl-canvas/shaders/example-6.glsl"></canvas>
<button type="button" class="btn btn-toggle">toggle</button>
</div>
<div class="example">
<h4>vec3 update</h4>
<canvas class="canvas" controls data-fragment-url="/glsl-canvas/shaders/example-7.glsl"></canvas>
<button type="button" class="btn btn-toggle">toggle</button>
</div>
<div class="example">
<h4>vec4 update</h4>
<canvas class="canvas" controls data-fragment-url="/glsl-canvas/shaders/example-8.glsl"></canvas>
<button type="button" class="btn btn-toggle">toggle</button>
</div>
<div class="example">
<h4>texture array</h4>
<canvas class="canvas" controls data-fragment-url="/glsl-canvas/shaders/example-9.glsl"></canvas>
<button type="button" class="btn btn-toggle">toggle</button>
</div>
<div class="example">
<h4>set multiple uniforms</h4>
<canvas class="canvas" controls data-fragment-url="/glsl-canvas/shaders/example-10.glsl"></canvas>
<button type="button" class="btn btn-toggle">toggle</button>
</div>
<div class="example">
<h4>includes</h4>
<canvas class="canvas" controls data-fragment-url="/glsl-canvas/shaders/example-11.glsl"></canvas>
<button type="button" class="btn btn-toggle">toggle</button>
</div>
<div class="example">
<h4>texture map nearest</h4>
<canvas class="canvas" controls data-fragment-url="/glsl-canvas/shaders/example-12.glsl"></canvas>
<button type="button" class="btn btn-toggle">toggle</button>
</div>
<div class="example">
<h4>camera</h4>
<canvas class="canvas" controls data-fragment-url="/glsl-canvas/shaders/example-camera.glsl"></canvas>
<button type="button" class="btn btn-toggle">toggle</button>
</div>
<div class="example">
<h4>mouse</h4>
<canvas class="canvas" controls data-fragment-url="/glsl-canvas/shaders/example-mouse.glsl"></canvas>
<button type="button" class="btn btn-toggle">toggle</button>
</div>
</div>
<div class="examples">
<div class="example">
<h4>video source</h4>
<video id="video-4" muted loop playsinline autoplay controls src="/glsl-canvas/data/moon.mp4"></video>
</div>
</div>
<h3>WebGl 2</h3>
<div class="examples">
<div class="example">
<h4>fragment via attribute</h4>
<canvas class="canvas" controls data-fragment-url="/glsl-canvas/shaders/example-20.glsl"></canvas>
<button type="button" class="btn btn-toggle">toggle</button>
</div>
<div class="example">
<h4>buffers</h4>
<canvas class="canvas" controls data-fragment-url="/glsl-canvas/shaders/example-21.glsl"></canvas>
<button type="button" class="btn btn-toggle">toggle</button>
</div>
<div class="example">
<h4>texture url in fragment shader</h4>
<canvas class="canvas" controls data-fragment-url="/glsl-canvas/shaders/example-22.glsl"></canvas>
<button type="button" class="btn btn-toggle">toggle</button>
</div>
<!--
<div class="example">
<h4>test buffers</h4>
<canvas class="canvas" controls data-fragment-url="/glsl-canvas/shaders/example-23.glsl"></canvas>
<button type="button" class="btn btn-toggle">toggle</button>
</div>
-->
</div>
<h3>Default</h3>
<div class="examples">
<div class="example">
<h4>default</h4>
<canvas class="canvas" controls></canvas>
<button type="button" class="btn btn-toggle">toggle</button>
</div>
</div>
</body>
<script>
var stats = new Stats();
stats.showPanel(0); // 0: fps, 1: ms, 2: mb, 3+: custom
document.body.appendChild(stats.dom);
// glsl.Canvas.logger.enabled = false;
var canvases = [].slice.call(document.querySelectorAll('.canvas'))
.map(function(element, i) {
var canvas = glsl.of(element, { extensions: i === 3 ? ['EXT_shader_texture_lod'] : [] });
canvas.on('render', function() {
stats.end();
stats.begin();
});
switch (i) {
case 3:
canvas.on('over', function() {
if (canvas.uniforms.get('u_texture').texture.url === 'glsl-canvas/data/mars.jpg') {
canvas.setUniform('u_texture', 'glsl-canvas/data/moon.jpg');
/*
canvas.setTexture('u_texture', 'glsl-canvas/data/moon.jpg', { repeat: true });
*/
} else {
// canvas.setUniform('u_texture', 'glsl-canvas/data/mars.jpg');
canvas.setTexture('u_texture', 'glsl-canvas/data/mars.jpg', { repeat: true });
}
});
break;
case 4:
canvas.setUniform('u_video', '#video-4');
break;
case 5:
canvas.setTexture('u_texture', 'glsl-canvas/data/noise.png', { repeat: true });
break;
case 6:
canvas.on('render', function() {
canvas.setUniform('u_pos', Math.random() - 0.5, Math.random() - 0.5);
});
break;
case 7:
canvas.on('render', function() {
canvas.setUniform('u_pos', Math.random() - 0.5, Math.random() - 0.5);
canvas.setUniform('u_col', Math.random(), Math.random(), Math.random());
});
break;
case 8:
canvas.on('render', function() {
canvas.setUniform('u_pos', Math.random() - 0.5, Math.random() - 0.5);
canvas.setUniform('u_col', [Math.random(), Math.random(), Math.random(), Math.random()]);
});
break;
case 9:
canvas.setUniform('u_texture', ['glsl-canvas/data/moon.jpg', 'glsl-canvas/data/mars.jpg']);
break;
case 10:
canvas.setUniform('u_video', '#video-4');
canvas.on('move', function(mouse) {
canvas.setUniforms({
u_x: mouse.x + 0.001,
u_y: mouse.y + 0.001,
});
});
break;
case 12:
// canvas.setTexture('u_texture', 'glsl-canvas/data/bayer-matrix.png', { filtering: 'nearest' });
canvas.setTexture('u_texture', 'glsl-canvas/data/bayer-matrix.png?filtering=nearest&repeat=true');
break;
}
return canvas;
});
var buttons = [].slice.call(document.querySelectorAll('.btn-toggle'))
.forEach(function(button, i) {
button.addEventListener('click', function() {
var canvas = canvases[i];
if (canvas) {
canvas.toggle();
}
});
});
</script>
</html>