-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo.js
46 lines (38 loc) · 987 Bytes
/
demo.js
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
var Editor = require('glsl-editor')
var format = require('./')
var outFrag = Editor({ container: document.querySelector('#out-frag'), readOnly: true })
var outVert = Editor({ container: document.querySelector('#out-vert'), readOnly: true })
var source = Editor({
container: document.querySelector('#source'),
value: `
attribute vec2 position;
uniform float time;
varying vec2 uv;
void vert() {
uv = position * 0.5 + 0.5;
gl_Position = vec4(position, 1, 1);
}
void frag() {
gl_FragColor.rg = uv;
gl_FragColor.b = sin(time) * 0.5 + 0.5;
gl_FragColor.a = 1.0;
}
`.trim()
})
setTimeout(function () {
update()
source.editor.on('change', update)
})
require('glsl-editor/css')
require('glsl-editor/theme')
window.addEventListener('resize', function () {
source.resize()
outFrag.resize()
outVert.resize()
}, false)
function update () {
var value = source.getValue()
var result = format(value)
outFrag.setValue(result.frag)
outVert.setValue(result.vert)
}