-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathdepthTexture.html
70 lines (65 loc) · 2.35 KB
/
depthTexture.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title>Hilo3d Depth Texture Demo</title>
<link rel="stylesheet" type="text/css" href="./example.css">
</head>
<body>
<div id="container"></div>
<script src="../build/Hilo3d.js"></script>
<script src="./js/stats.js"></script>
<script src="./js/OrbitControls.js"></script>
<script src="./js/init.js"></script>
<script>
Hilo3d.extensions.use('WEBGL_depth_texture');
var boxGeometry = new Hilo3d.BoxGeometry();
boxGeometry.setAllRectUV([[0, 1], [1, 1], [1, 0], [0, 0]]);
var material = new Hilo3d.BasicMaterial({
lightType: 'NONE',
});
var depthNode = new Hilo3d.Node({
onUpdate: function() {
this.rotationY += 0.5;
this.rotationX += 0.5;
}
});
for(let i = 0;i < 20;i ++) {
depthNode.addChild(new Hilo3d.Mesh({
material: material,
geometry: boxGeometry,
x: (Math.random() * 2 - 1) * 5,
y: (Math.random() * 2 - 1) * 5,
z: (Math.random() * 2 - 1) * 5,
rotationX: Math.random() * 360,
rotationY: Math.random() * 360,
rotationZ: Math.random() * 360,
onUpdate: function() {
this.rotationY += 0.5;
this.rotationX += 0.5;
}
})).setScale(.1);
};
stage.onUpdate = function() {
framebuffer.bind();
depthNode.onUpdate();
stage.renderer.render(depthNode, camera);
framebuffer.unbind();
}
var framebuffer = new Hilo3d.Framebuffer(renderer, {
colorAttachmentInfos: [],
depthStencilAttachmentInfo: {
attachmentType: Hilo3d.Framebuffer.ATTACHMENT_TYPE_TEXTURE,
attachment: Hilo3d.constants.DEPTH_ATTACHMENT,
format: Hilo3d.constants.DEPTH_COMPONENT,
internalFormat: Hilo3d.constants.DEPTH_COMPONENT16,
type: Hilo3d.constants.UNSIGNED_SHORT,
}
});
renderer.on('afterRender', () => {
framebuffer.render(0, 0, 1, 1, null, framebuffer.depthStencilAttachmentInfo.texture);
})
</script>
</body>
</html>