Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post-Process example #5648

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
9094de9
Create base html file for post-processing bloom example
enzofrancescaHM Jan 30, 2025
19f78b4
Create bloom.js for post-process bloom example
enzofrancescaHM Jan 30, 2025
868863a
Update index.html changing path
enzofrancescaHM Jan 30, 2025
22ad7d0
Update index.html to use importmap
enzofrancescaHM Jan 30, 2025
fbd5cef
Update bloom.js to use importmap
enzofrancescaHM Jan 30, 2025
d6b9d96
Update examples/post-process/index.html
enzofrancescaHM Jan 30, 2025
d86dd9f
Update examples/post-process/bloom.js
enzofrancescaHM Jan 30, 2025
2b409aa
Update bloom.js to discard useless wait
enzofrancescaHM Jan 30, 2025
5617d2f
Update index.html to set bloom directly on a-scene tag
enzofrancescaHM Jan 30, 2025
485fe53
Update index.html to fix typo and fix importmap paths
enzofrancescaHM Jan 31, 2025
f12edb5
Update bloom.js to fix various issues and to optimize code
enzofrancescaHM Jan 31, 2025
b8fc265
Rename examples/post-process/bloom.js to examples/showcase/post-proce…
enzofrancescaHM Jan 31, 2025
2c30d30
Rename examples/post-process/index.html to examples/showcase/post-pro…
enzofrancescaHM Jan 31, 2025
d1f9285
Update index.html to get rid of useless tags
enzofrancescaHM Jan 31, 2025
003bb43
Update bloom.js to use right value of delta
enzofrancescaHM Jan 31, 2025
c72fb8c
Update bloom.js to reflect better formatting of schema
enzofrancescaHM Jan 31, 2025
97c97f7
Update index.html to get rid of semicolon and trailing comma
enzofrancescaHM Jan 31, 2025
fbf8c44
Update bloom.js to implement multisampling
enzofrancescaHM Jan 31, 2025
53afd13
Update bloom.js to resize EffectComposer
enzofrancescaHM Jan 31, 2025
97d4fed
Update bloom.js with correct parameter in setSize
enzofrancescaHM Feb 1, 2025
3ecf142
Update index.html to get right position and raise red cube emissive
enzofrancescaHM Feb 1, 2025
b08a29d
Update bloom.js to fix distorsions in VR Mode
enzofrancescaHM Feb 1, 2025
cdc609c
Update bloom.js to add OutputPass, improving quality
enzofrancescaHM Feb 1, 2025
70ca6bd
Update bloom.js, removed useless parameter in OutputPass
enzofrancescaHM Feb 1, 2025
3c422ac
Update index.html, added toneMapping tag
enzofrancescaHM Feb 1, 2025
3276558
Update bloom.js, FullScreenQuad global patch
enzofrancescaHM Feb 1, 2025
4c2cb7c
Update index.html to list post-processing example
enzofrancescaHM Feb 1, 2025
0a342d0
Update bloom.js to get rid of reduntant parts already implemented in …
enzofrancescaHM Feb 1, 2025
eae775a
Update examples/showcase/post-processing/bloom.js
enzofrancescaHM Feb 2, 2025
379acfe
Update examples/showcase/post-processing/bloom.js
enzofrancescaHM Feb 2, 2025
4e4041f
Update examples/showcase/post-processing/bloom.js
enzofrancescaHM Feb 3, 2025
b954921
Updated bloom.js after lint:fix passed
Feb 3, 2025
ec757df
Final demo scene with toon car
Feb 5, 2025
3c73498
Refactor names
Feb 5, 2025
448ea27
Update index.html
enzofrancescaHM Feb 5, 2025
cce2821
change description
Feb 5, 2025
4570f97
Merge branch 'master' of https://github.com/enzofrancescaHM/aframe_po…
Feb 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ <h2>Examples</h2>
<li><a href="mixed-reality/anchor/">Anchor (Mixed Reality)</a></li>
<li><a href="mixed-reality/real-world-meshing/">Real World Meshing (Mixed Reality)</a></li>
<li><a href="boilerplate/importmap/">Importmap (import teapot geometry from three/addons)</a></li>
<li><a href="showcase/post-processing/">Post-Processing (bloom effect)</a></li>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to add (bloom effect) for simplicity

</ul>

<h2>Examples from Documentation</h2>
Expand Down
112 changes: 112 additions & 0 deletions examples/showcase/post-processing/bloom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/* global THREE */
/**
* Unreal Bloom Effect
* Implementation for A-Frame
* Code modified from Akbartus's post-processing A-Frame integration
* https://github.com/akbartus/A-Frame-Component-Postprocessing
*/

import AFRAME from "aframe";

Check failure on line 9 in examples/showcase/post-processing/bloom.js

View workflow job for this annotation

GitHub Actions / Test Cases (20.x, latest)

Strings must use singlequote
import { EffectComposer } from "three/addons/postprocessing/EffectComposer.js";

Check failure on line 10 in examples/showcase/post-processing/bloom.js

View workflow job for this annotation

GitHub Actions / Test Cases (20.x, latest)

Strings must use singlequote
import { RenderPass } from "three/addons/postprocessing/RenderPass.js";

Check failure on line 11 in examples/showcase/post-processing/bloom.js

View workflow job for this annotation

GitHub Actions / Test Cases (20.x, latest)

Strings must use singlequote
import { UnrealBloomPass } from "three/addons/postprocessing/UnrealBloomPass.js";

Check failure on line 12 in examples/showcase/post-processing/bloom.js

View workflow job for this annotation

GitHub Actions / Test Cases (20.x, latest)

Strings must use singlequote
import { OutputPass } from "three/addons/postprocessing/OutputPass.js";

Check failure on line 13 in examples/showcase/post-processing/bloom.js

View workflow job for this annotation

GitHub Actions / Test Cases (20.x, latest)

Strings must use singlequote
import { FullScreenQuad } from "three/addons/postprocessing/Pass.js";

Check failure on line 14 in examples/showcase/post-processing/bloom.js

View workflow job for this annotation

GitHub Actions / Test Cases (20.x, latest)

Strings must use singlequote

// Disable XR projection for fullscreen effects
// https://github.com/mrdoob/three.js/pull/26160
const _render = FullScreenQuad.prototype.render;
FullScreenQuad.prototype.render = function (renderer) {
const xrEnabled = renderer.xr.enabled;
renderer.xr.enabled = false;
_render.apply(this, arguments);
renderer.xr.enabled = xrEnabled;
};

AFRAME.registerComponent("bloom", {

Check failure on line 26 in examples/showcase/post-processing/bloom.js

View workflow job for this annotation

GitHub Actions / Test Cases (20.x, latest)

Strings must use singlequote
schema: {
threshold: { type: "number", default: 1 },

Check failure on line 28 in examples/showcase/post-processing/bloom.js

View workflow job for this annotation

GitHub Actions / Test Cases (20.x, latest)

Strings must use singlequote
strength: { type: "number", default: 0.5 },

Check failure on line 29 in examples/showcase/post-processing/bloom.js

View workflow job for this annotation

GitHub Actions / Test Cases (20.x, latest)

Strings must use singlequote
radius: { type: "number", default: 1 },

Check failure on line 30 in examples/showcase/post-processing/bloom.js

View workflow job for this annotation

GitHub Actions / Test Cases (20.x, latest)

Strings must use singlequote
},
events: {
rendererresize: function () {
this.renderer.getSize(this.size);
this.composer.setSize(this.size.width, this.size.height);
},
"enter-vr": function () {
this.renderer.getSize(this.size);
this.composer.setSize(this.size.width, this.size.height);
},
},
init() {
enzofrancescaHM marked this conversation as resolved.
Show resolved Hide resolved
this.size = new THREE.Vector2();
this.scene = this.el.object3D;
this.renderer = this.el.renderer;
this.camera = this.el.camera;
this.bind();
},
update: function () {
if (this.composer) {
this.composer.dispose();
}
// create composer with multisampling to avoid aliasing
const resolution = this.renderer.getDrawingBufferSize(new THREE.Vector2());
const renderTarget = new THREE.WebGLRenderTarget(
resolution.width,
resolution.height,
{ type: THREE.HalfFloatType, samples: 8 }
);

this.composer = new EffectComposer(this.renderer, renderTarget);

// create render pass
const renderScene = new RenderPass(this.scene, this.camera);
this.composer.addPass(renderScene);

// create bloom pass
const strength = this.data.strength;
const radius = this.data.radius;
const threshold = this.data.threshold;
if (this.bloomPass) {
this.bloomPass.dispose();
}
this.bloomPass = new UnrealBloomPass(
resolution,
strength,
radius,
threshold
);
this.composer.addPass(this.bloomPass);

// create output pass
if (this.outputPass) {
this.outputPass.dispose();
}
this.outputPass = new OutputPass();
this.composer.addPass(this.outputPass);
},

bind: function () {
this.originalRender = this.el.renderer.render;
const self = this;
let isInsideComposerRender = false;

this.el.renderer.render = function () {
if (isInsideComposerRender) {
self.originalRender.apply(this, arguments);
} else {
isInsideComposerRender = true;
self.composer.render(self.el.sceneEl.delta / 1000);
isInsideComposerRender = false;
}
};
},

remove() {
Copy link
Member

@dmarcos dmarcos Feb 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be function: remove () { for consistency

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that you can press this button in review to suggest changes as I did.

{FE44035C-8CB4-45BC-B600-2DB36D504E27}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah. I can edit the PR directly too. Deliberate to make people do the changes. Especially first-time contributors :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

omg I always wondered how folks made suggestions, I saw that only on a few PRs, I never saw that icon myself, no idea to look at the style toolbar for it.
I still have no idea how you commit directly to a PR before merge @dmarcos

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think only owners of a repo can add commits to a PR but not 100% sure

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes obviously, but where and how?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh like this https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally
I always do the complicated way, add the remote, fetch the remote and get the branch on the command line. I had no idea you could just get the PR branch lol.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm reading the doc again, it's been years since I read those pages.
There is a screenshot with the suggest change icon:
https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/commenting-on-a-pull-request

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just edit the file on the PR directly on Github. living on the edge 😅

this.el.renderer.render = this.originalRender;
this.bloomPass.dispose();
this.outputPass.dispose();
this.composer.dispose();
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra comma

});
enzofrancescaHM marked this conversation as resolved.
Show resolved Hide resolved
102 changes: 102 additions & 0 deletions examples/showcase/post-processing/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<!DOCTYPE html>
<html>
enzofrancescaHM marked this conversation as resolved.
Show resolved Hide resolved
<head>
<meta charset="utf-8" />
<title>Post Processing Bloom Effect</title>
<meta name="description" content="Post Processing Bloom Effect • A-Frame" />
<script type="importmap">
{
"imports": {
"aframe": "../../dist/aframe-master.module.min.js",
"three": "../../../super-three-package/build/three.module.js",
"three/addons/": "../../../super-three-package/examples/jsm/"
}
}
</script>
<script type="module" src="./bloom.js"></script>
</head>

<body>
<a-scene
background="color: black"
renderer="toneMapping: ACESFilmic"
bloom="threshold: 1.0; strength: 0.5; radius: 1"
>
<a-entity id="rig" position="0 0 2">
<a-entity
id="camera"
position="0 1.6 0"
camera
look-controls
wasd-controls
></a-entity>
</a-entity>

<a-box
id="boxemissivewhite"
position="1 1.7 -1"
scale="0.2 0.2 0.2"
material="color: #FFF; emissive: #FFF; emissiveIntensity: 4"
></a-box>

<a-box
id="boxemissivegreen"
position="0 1.7 -1"
scale="0.2 0.2 0.2"
material="color: #0F0; emissive: #0F0; emissiveIntensity: 4"
></a-box>

<a-box
id="boxemissivered"
position="-1 1.7 -1"
scale="0.2 0.2 0.2"
material="color: #F00; emissive: #F00; emissiveIntensity: 5"
></a-box>

<a-box
id="boxwhite"
position="1 1 -1"
scale="0.2 0.2 0.2"
material="color: #FFF; emissive: #FFF; emissiveIntensity: 0"
></a-box>

<a-box
id="boxgreen"
position="0 1 -1"
scale="0.2 0.2 0.2"
material="color: #0F0;emissive: #0F0; emissiveIntensity: 0"
></a-box>

<a-box
id="boxred"
position="-1 1 -1"
scale="0.2 0.2 0.2"
material="color: #F00; emissive: #F00; emissiveIntensity: 0"
></a-box>

<a-box
id="pulsingneon"
position="0 1.25 -1"
scale="2 0.1 0.1"
material="color: #F0F; emissive: #F0F; emissiveIntensity: 2.5"
animation="property: material.emissiveIntensity; from: 2.5; to: 3.5; dir: alternate; dur: 2000; easing: linear; loop: true"
></a-box>

<a-plane
id="plane"
position="0 0.2 -4"
rotation="-90 0 0"
width="40"
height="40"
color="#111111"
></a-plane>

<a-entity
id="sun"
light="type: directional; intensity: 2.6; color: #FFD"
position="0.12 5.76 -2.14"
>
</a-entity>
</a-scene>
</body>
</html>