-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
47 lines (41 loc) · 1.17 KB
/
index.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
47
const THREE = require('three')
const createOrbitViewer = require('three-orbit-viewer')(THREE)
const glslify = require('glslify')
//our basic full-screen application and render loop
let time = 0
const app = createOrbitViewer({
clearColor: 0x000000,
clearAlpha: 1.0,
fov: 65,
position: new THREE.Vector3(0.85, 1, -1.5)
})
//load up a test image
const tex = THREE.ImageUtils.loadTexture('baboon.png', undefined, ready)
//here we create a custom shader with glslify
//note USE_MAP is needed to get a 'uv' attribute
const mat = new THREE.ShaderMaterial({
vertexShader: glslify('./vert.glsl'),
fragmentShader: glslify('./frag.glsl'),
uniforms: {
iChannel0: { type: 't', value: tex },
iGlobalTime: { type: 'f', value: 0 }
},
defines: {
USE_MAP: ''
}
})
//make a box, hidden until the texture has loaded
const geo = new THREE.BoxGeometry(1, 1, 1)
const box = new THREE.Mesh(geo, mat)
box.visible = false
box.rotation.y = -Math.PI
app.scene.add(box)
//provide our shader with iGlobalTime for cool effects
app.on('tick', dt => {
time += dt / 1000
mat.uniforms.iGlobalTime.value = time
})
//once texture is ready, show our box
function ready() {
box.visible = true
}