Skip to content

Commit 258de6c

Browse files
enzofrancescaHMmrxzCodyJasonBennettvincentfretinEnzo Francesca
authored
Post-Process example (#5648)
* Create base html file for post-processing bloom example * Create bloom.js for post-process bloom example * Update index.html changing path * Update index.html to use importmap * Update bloom.js to use importmap * Update examples/post-process/index.html Typo Co-authored-by: Noeri Huisman <8823461+mrxz@users.noreply.github.com> * Update examples/post-process/bloom.js deleted useless tick function Co-authored-by: Noeri Huisman <8823461+mrxz@users.noreply.github.com> * Update bloom.js to discard useless wait * Update index.html to set bloom directly on a-scene tag * Update index.html to fix typo and fix importmap paths * Update bloom.js to fix various issues and to optimize code * Rename examples/post-process/bloom.js to examples/showcase/post-processing/bloom.js * Rename examples/post-process/index.html to examples/showcase/post-processing/index.html * Update index.html to get rid of useless tags * Update bloom.js to use right value of delta * Update bloom.js to reflect better formatting of schema * Update index.html to get rid of semicolon and trailing comma * Update bloom.js to implement multisampling * Update bloom.js to resize EffectComposer * Update bloom.js with correct parameter in setSize * Update index.html to get right position and raise red cube emissive * Update bloom.js to fix distorsions in VR Mode * Update bloom.js to add OutputPass, improving quality * Update bloom.js, removed useless parameter in OutputPass * Update index.html, added toneMapping tag * Update bloom.js, FullScreenQuad global patch * Update index.html to list post-processing example * Update bloom.js to get rid of reduntant parts already implemented in superthree * Update examples/showcase/post-processing/bloom.js Co-authored-by: Cody Bennett <hi@codyb.co> * Update examples/showcase/post-processing/bloom.js Co-authored-by: Vincent Fretin <vincent.fretin@gmail.com> * Update examples/showcase/post-processing/bloom.js Co-authored-by: Vincent Fretin <vincent.fretin@gmail.com> * Updated bloom.js after lint:fix passed * Final demo scene with toon car * Refactor names * Update index.html * change description * Added info panel, changed model * Update message.html to remove useless statement * Update index.html to add toggle bloom in VR * Update message.html to add toggle instructions * resolve conflict * Update index.html to implement component * use cdn model, prettified html, events tag * fix doube line * Update examples/showcase/post-processing/index.html Co-authored-by: Vincent Fretin <vincent.fretin@gmail.com> * Update examples/showcase/post-processing/index.html Co-authored-by: Vincent Fretin <vincent.fretin@gmail.com> * Update index.html, removed useless params * removed model, now on CDN * Update examples/showcase/post-processing/index.html Co-authored-by: Vincent Fretin <vincent.fretin@gmail.com> * Update examples/showcase/post-processing/bloom.js Co-authored-by: Vincent Fretin <vincent.fretin@gmail.com> * adopt new enable param, changed component name * fix unused params * effect-controls now is an external file * Update effect-controls.js to simplify code * lint fix * Replace let/const with var --------- Co-authored-by: Noeri Huisman <8823461+mrxz@users.noreply.github.com> Co-authored-by: Cody Bennett <hi@codyb.co> Co-authored-by: Vincent Fretin <vincent.fretin@gmail.com> Co-authored-by: Enzo Francesca <holomask.xr@gmail.com> Co-authored-by: Diego Marcos <diego.marcos@gmail.com>
1 parent 08e6645 commit 258de6c

File tree

5 files changed

+223
-0
lines changed

5 files changed

+223
-0
lines changed

examples/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ <h2>Examples</h2>
159159
<li><a href="mixed-reality/real-world-meshing/">Real World Meshing (Mixed Reality)</a></li>
160160
<li><a href="boilerplate/importmap/">Importmap (import teapot geometry from three/addons)</a></li>
161161
<li><a href="showcase/webgpu/">WebGPU renderer and TSL</a></li>
162+
<li><a href="showcase/post-processing/">Post-Processing</a></li>
162163
</ul>
163164

164165
<h2>Examples from Documentation</h2>
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/* global THREE */
2+
/**
3+
* Unreal Bloom Effect
4+
* Implementation for A-Frame
5+
* Code modified from Akbartus's post-processing A-Frame integration
6+
* https://github.com/akbartus/A-Frame-Component-Postprocessing
7+
*/
8+
9+
import AFRAME from 'aframe';
10+
import { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js';
11+
import { RenderPass } from 'three/addons/postprocessing/RenderPass.js';
12+
import { UnrealBloomPass } from 'three/addons/postprocessing/UnrealBloomPass.js';
13+
import { OutputPass } from 'three/addons/postprocessing/OutputPass.js';
14+
15+
AFRAME.registerComponent('bloom', {
16+
schema: {
17+
enabled: { type: 'boolean', default: true },
18+
threshold: { type: 'number', default: 1 },
19+
strength: { type: 'number', default: 0.5 },
20+
radius: { type: 'number', default: 1 }
21+
},
22+
events: {
23+
rendererresize: function () {
24+
this.renderer.getSize(this.size);
25+
this.composer.setSize(this.size.width, this.size.height);
26+
}
27+
},
28+
init: function () {
29+
this.size = new THREE.Vector2();
30+
this.scene = this.el.object3D;
31+
this.renderer = this.el.renderer;
32+
this.camera = this.el.camera;
33+
this.originalRender = this.el.renderer.render;
34+
this.bind();
35+
},
36+
update: function (oldData) {
37+
if (oldData.enabled === false && this.data.enabled === true) {
38+
this.bind();
39+
}
40+
41+
if (oldData.enabled === true && this.data.enabled === false) {
42+
this.el.renderer.render = this.originalRender;
43+
}
44+
45+
if (this.composer) {
46+
this.composer.dispose();
47+
}
48+
// create composer with multisampling to avoid aliasing
49+
var resolution = this.renderer.getDrawingBufferSize(new THREE.Vector2());
50+
var renderTarget = new THREE.WebGLRenderTarget(
51+
resolution.width,
52+
resolution.height,
53+
{ type: THREE.HalfFloatType, samples: 8 }
54+
);
55+
56+
this.composer = new EffectComposer(this.renderer, renderTarget);
57+
58+
// create render pass
59+
var renderScene = new RenderPass(this.scene, this.camera);
60+
this.composer.addPass(renderScene);
61+
62+
// create bloom pass
63+
var strength = this.data.strength;
64+
var radius = this.data.radius;
65+
var threshold = this.data.threshold;
66+
if (this.bloomPass) {
67+
this.bloomPass.dispose();
68+
}
69+
this.bloomPass = new UnrealBloomPass(
70+
resolution,
71+
strength,
72+
radius,
73+
threshold
74+
);
75+
this.composer.addPass(this.bloomPass);
76+
77+
// create output pass
78+
if (this.outputPass) {
79+
this.outputPass.dispose();
80+
}
81+
this.outputPass = new OutputPass();
82+
this.composer.addPass(this.outputPass);
83+
},
84+
85+
bind: function () {
86+
var self = this;
87+
var isInsideComposerRender = false;
88+
89+
this.el.renderer.render = function () {
90+
if (isInsideComposerRender) {
91+
self.originalRender.apply(this, arguments);
92+
} else {
93+
isInsideComposerRender = true;
94+
self.composer.render(self.el.sceneEl.delta / 1000);
95+
isInsideComposerRender = false;
96+
}
97+
};
98+
},
99+
100+
remove: function () {
101+
this.el.renderer.render = this.originalRender;
102+
this.bloomPass.dispose();
103+
this.outputPass.dispose();
104+
this.composer.dispose();
105+
}
106+
});
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import AFRAME from 'aframe';
2+
AFRAME.registerComponent('effect-controls', {
3+
schema: {
4+
hand: { type: 'string', default: 'left' }
5+
},
6+
7+
events: {
8+
pinchstarted: function () {
9+
this.toggleEffect();
10+
},
11+
buttondown: function () {
12+
this.toggleEffect();
13+
}
14+
},
15+
16+
init: function () {
17+
// initialize control variable
18+
this.effectEnabled = true;
19+
20+
// set the proper controller on the specified hand
21+
this.el.setAttribute('meta-touch-controls', {
22+
hand: this.data.hand
23+
});
24+
this.el.setAttribute('hand-tracking-controls', {
25+
hand: this.data.hand
26+
});
27+
},
28+
29+
toggleEffect: function () {
30+
// toggle control variable and effect
31+
this.effectEnabled = !this.effectEnabled;
32+
this.el.sceneEl.setAttribute('bloom', { enabled: this.effectEnabled });
33+
}
34+
});
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>Post Processing Bloom Effect</title>
6+
<meta name="description" content="Post Processing Bloom Effect • A-Frame" />
7+
<script type="importmap">
8+
{
9+
"imports": {
10+
"aframe": "../../../dist/aframe-master.module.min.js",
11+
"three": "../../../super-three-package/build/three.module.js",
12+
"three/addons/": "../../../super-three-package/examples/jsm/"
13+
}
14+
}
15+
</script>
16+
<script type="module">
17+
import AFRAME from 'aframe';
18+
</script>
19+
<script src="../../js/info-message.js" type="module"></script>
20+
<script src="./effect-controls.js" type="module"></script>
21+
<script src="./bloom.js" type="module"></script>
22+
</head>
23+
24+
<body>
25+
<a-scene
26+
bloom="threshold: 1.0; strength: 0.3; radius: 1;"
27+
background="color: #000000"
28+
renderer="toneMapping: ACESFilmic;"
29+
info-message="htmlSrc: #messageText"
30+
>
31+
<a-assets>
32+
<!-- model by arturs.vitas https://skfb.ly/owUr9 -->
33+
<a-asset-item id="testbed" src="https://cdn.aframe.io/examples/post-processing/fancy-car.glb"></a-asset-item>
34+
<a-asset-item id="messageText" src="message.html"></a-asset-item>
35+
</a-assets>
36+
37+
<a-entity id="rig" position="0 0 2">
38+
<a-entity id="camera" position="0 1.6 0" camera look-controls wasd-controls></a-entity>
39+
40+
<a-entity id="lhand" effect-controls="hand: left;"> </a-entity>
41+
42+
<a-entity id="rhand" effect-controls="hand: right;"> </a-entity>
43+
</a-entity>
44+
45+
<a-entity
46+
id="base"
47+
geometry="primitive: cylinder; height: 0.1; radius: 1.93"
48+
position="0 0 -2"
49+
material="color: #201d1d"
50+
shadow
51+
animation="property: rotation; to: 0 360 0 ; loop: true; dur: 15000; easing: linear;"
52+
>
53+
<a-entity id="tooncar" gltf-model="#testbed" position="0 0.050 0" scale="2 2 2" shadow> </a-entity>
54+
55+
<a-entity
56+
id="neon01"
57+
geometry="primitive: torus; radius: 1.92; radiusTubular: 0.02; segmentsRadial: 50; segmentsTubular: 40"
58+
material="color: #d100e0; emissive: #b300a4; emissiveIntensity: 9.34"
59+
rotation="90 0 0"
60+
>
61+
</a-entity>
62+
</a-entity>
63+
64+
<a-entity id="ambient" light="type: ambient; intensity: 0.48; color: #ffffff"> </a-entity>
65+
66+
<a-entity id="point01" light="color: #7cd2fe; intensity: 5; type: point;" position="0 3.51 -1"> </a-entity>
67+
</a-scene>
68+
</body>
69+
</html>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<p>A-Frame Post-Processing Example with Bloom Effect</p>
2+
3+
<p>
4+
<strong>Desktop:</strong>Mouse and Keyboard support<br />
5+
<strong>VR:</strong>Targeted to Quest 3 for performance reasons, press any button to toggle effect<br />
6+
</p>
7+
8+
<p>
9+
Model:
10+
<a href="https://skfb.ly/owUr9" target="_blank" rel="noopener">Low-poly cartoon style car 03</a>
11+
by
12+
<a href="https://sketchfab.com/arturs.vitas" target="_blank" rel="noopener">artus.vitas</a>, CC Attribution.
13+
</p>

0 commit comments

Comments
 (0)