-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.html
70 lines (57 loc) · 2.26 KB
/
example.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
<script src="../../importmap.js"></script>
<lume-scene webgl id="scene">
<lume-camera-rig horizontal-angle="-30" vertical-angle="30"></lume-camera-rig>
<lume-box size="100 100 100" mount-point="0.5 0.5 0.5"></lume-box>
<lume-point-light position="200 400 500" color="deeppink" intensity="1600"></lume-point-light>
<lume-point-light position="-200 -400 -500" color="royalblue" intensity="1600"></lume-point-light>
</lume-scene>
<style>
html,
body {
margin: 0;
height: 100%;
}
lume-element3d {
padding: 5px;
}
</style>
<script type="module">
import {Motor} from 'lume'
import {EffectComposer} from 'three/examples/jsm/postprocessing/EffectComposer.js'
import {RenderPass} from 'three/examples/jsm/postprocessing/RenderPass.js'
import {GlitchPass} from 'three/examples/jsm/postprocessing/GlitchPass.js'
import {OutputPass} from 'three/examples/jsm/postprocessing/OutputPass.js'
const composer = new EffectComposer(scene.glRenderer)
function setDimensions() {
composer.setPixelRatio(window.devicePixelRatio)
const resize = () => composer.setSize(scene.clientWidth, scene.clientHeight)
const observer = new ResizeObserver(resize)
observer.observe(scene)
}
// If you do things manually with Three.js, you need to make sure to set the
// proper rendering dimensions. Comment this out and it will still work, but
// the demo may be lower resolution and look pixelated.
setDimensions()
const renderPass = new RenderPass(scene.three, scene.threeCamera)
composer.addPass(renderPass)
const glitchPass = new GlitchPass()
composer.addPass(glitchPass)
const outputPass = new OutputPass()
composer.addPass(outputPass)
scene.drawScene = () => {
// If there are multiple cameras in the Lume scene, make sure to always
// use the currently-active camera.
renderPass.camera = scene.threeCamera
composer.render()
}
// If you need the scene to be continuously rendering for a certain
// post-processing effects (for example, the GlitchPass is animated over
// time), then make a loop that calls scene.needsUpdate() repeatedly. Here
// we do that with Lume's Motor:
Motor.addRenderTask(() => scene.needsUpdate())
// Alternatively, make an rAF loop:
// requestAnimationFrame(function loop() {
// scene.needsUpdate()
// requestAnimationFrame(loop)
// })
</script>