-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
base: master
Are you sure you want to change the base?
Post-Process example #5648
Changes from 5 commits
9094de9
19f78b4
868863a
22ad7d0
fbd5cef
d6b9d96
d86dd9f
2b409aa
5617d2f
485fe53
f12edb5
b8fc265
2c30d30
d1f9285
003bb43
c72fb8c
97c97f7
fbf8c44
53afd13
97d4fed
3ecf142
b08a29d
cdc609c
70ca6bd
3c422ac
3276558
4c2cb7c
0a342d0
eae775a
379acfe
4e4041f
b954921
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/** | ||
* Unreal Bloom Effect | ||
* Implementation for A-Frame | ||
* Code modified from Akbartus's UnrealBloomPass.js | ||
* https://github.com/akbartus/A-Frame-Component-Postprocessing | ||
*/ | ||
|
||
import AFRAME from "aframe"; | ||
import { EffectComposer } from "three/addons/postprocessing/EffectComposer.js"; // This uses the same three instance. | ||
import { RenderPass } from "three/addons/postprocessing/RenderPass.js"; // This uses the same three instance. | ||
import { UnrealBloomPass } from "three/addons/postprocessing/UnrealBloomPass.js"; // This uses the same three instance. | ||
enzofrancescaHM marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
///////////////////////////////////// | ||
// A-FRAME COMPONENT: POST-PROCESSING // | ||
///////////////////////////////////// | ||
AFRAME.registerComponent("bloom", { | ||
schema: { | ||
threshold: { | ||
type: "number", | ||
default: 0, | ||
}, | ||
strength: { | ||
type: "number", | ||
default: 0.4, | ||
}, | ||
radius: { | ||
type: "number", | ||
default: 0, | ||
}, | ||
exposure: { | ||
type: "number", | ||
default: 1, | ||
}, | ||
enzofrancescaHM marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
init: function () { | ||
|
||
this.scene = this.el.object3D; | ||
this.renderer = this.el.renderer; | ||
this.camera = this.el.camera; | ||
this.bound = false; | ||
enzofrancescaHM marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
var that = this; | ||
|
||
// delay half second to get the right resolution | ||
setTimeout(function () { | ||
that.evaluateEffect(); | ||
that.bind(); | ||
}, 500); | ||
enzofrancescaHM marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
update: function (oldData) { | ||
console.log("Post-processing UPDATE effect"); | ||
this.evaluateEffect(); | ||
}, | ||
evaluateEffect: function () { | ||
this.scene = this.el.object3D; | ||
this.renderer = this.el.renderer; | ||
this.camera = this.el.camera; | ||
this.composer = new EffectComposer(this.renderer); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of recreating |
||
const renderScene = new RenderPass(this.scene, this.camera); | ||
this.composer.addPass(renderScene); | ||
|
||
// creating bloom pass | ||
const bloomPass = new UnrealBloomPass( | ||
new THREE.Vector2( | ||
this.renderer.domElement.clientWidth, | ||
this.renderer.domElement.clientHeight | ||
), | ||
1.5, | ||
0.4, | ||
0.85 | ||
); | ||
|
||
bloomPass.threshold = this.data.threshold; | ||
bloomPass.strength = this.data.strength; | ||
bloomPass.radius = this.data.radius; | ||
this.composer.addPass(bloomPass); | ||
}, | ||
tick: function (t, dt) { | ||
this.t = t; | ||
this.dt = dt; | ||
}, | ||
enzofrancescaHM marked this conversation as resolved.
Show resolved
Hide resolved
|
||
bind: function () { | ||
const render = this.renderer.render; | ||
const system = this; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: this isn't a system, probably better to name it |
||
let isDigest = false; | ||
enzofrancescaHM marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
this.renderer.render = function () { | ||
|
||
if (isDigest) { | ||
render.apply(this, arguments); | ||
} else { | ||
isDigest = true; | ||
if (system.occlusionComposer) { | ||
system.occlusionComposer.render(system.dt); | ||
} else { | ||
system.composer.render(system.dt); | ||
} | ||
enzofrancescaHM marked this conversation as resolved.
Show resolved
Hide resolved
|
||
isDigest = false; | ||
} | ||
|
||
}; | ||
|
||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<html> | ||
|
||
<head> | ||
<script type="importmap"> | ||
{ | ||
"imports": { | ||
"aframe": "../../dist/aframe-master.module.min.js", | ||
"three": "https://cdn.jsdelivr.net/npm/[email protected]/build/three.module.js", | ||
"three/addons/": "https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be
like https://github.com/aframevr/aframe/blob/master/examples/boilerplate/importmap/index.html |
||
} | ||
} | ||
</script> | ||
<script type="module" src="./bloom.js"></script>; | ||
|
||
<meta charset="utf-8"> | ||
<title>Post Processing Bloom A-Frame Demo</title> | ||
<meta name="description" content="Post Processing Bloom Demo"> | ||
|
||
</head> | ||
|
||
<body> | ||
|
||
<a-scene | ||
reflection="directionalLight:#sun;" | ||
ßshadow="type: pcfsoft; autoUpdate: true" | ||
enzofrancescaHM marked this conversation as resolved.
Show resolved
Hide resolved
|
||
background="color:black;" | ||
renderer="anisotropy:4; stencil:true; alpha:false; colorManagement:true; exposure:1.0;"> | ||
|
||
<a-entity id="pov-camera" position="0 1.6 2" rotation="3.323 -8.136 0" camera="" look-controls="" wasd-controls="" data-aframe-inspector-original-camera=""></a-entity> | ||
|
||
<a-box id="boxemissivewhite" shadow="cast:false; receive:false" position="1 1.720 -1" rotation="0 0 0" | ||
scale="0.2 0.2 0.2" color="#FFFFFF" material="emissive: #FFF; emissiveIntensity:4;"></a-box> | ||
|
||
<a-box id="boxemissivegreen" shadow="cast:false; receive:false" position="0 1.720 -1" rotation="0 0 0" | ||
scale="0.2 0.2 0.2" color="#00FF00" material="emissive: #0F0; emissiveIntensity:4;"></a-box> | ||
|
||
<a-box id="boxemissivered" shadow="cast: false; receive: false" position="-1 1.720 -1" rotation="" | ||
scale="0.2 0.2 0.2" color="#FF0000" material="emissive: #F00; emissiveIntensity: 4"></a-box> | ||
|
||
<a-box id="boxwhite" shadow="cast:false; receive:false" position="1 1 -1" rotation="0 0 0" | ||
scale="0.2 0.2 0.2" color="#FFFFFF" material="emissive: #FFF; emissiveIntensity:0;"></a-box> | ||
|
||
<a-box id="boxgreen" shadow="cast:false; receive:false" position="0 1 -1" rotation="0 0 0" | ||
scale="0.2 0.2 0.2" color="#00FF00" material="emissive: #0F0; emissiveIntensity:0;"></a-box> | ||
|
||
<a-box id="boxred" shadow="cast: false; receive: false" position="-1 1 -1" rotation="" | ||
scale="0.2 0.2 0.2" color="#FF0000" material="emissive: #F00; emissiveIntensity:0;"></a-box> | ||
|
||
<a-box id="pulsingneon" shadow="cast:false; receive:false" position="0 1.250 -1" rotation="0 0 0" | ||
scale="2 0.1 0.1" color="#FF00FF" material="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"shadow></a-plane> | ||
|
||
<a-entity id="sun" radius="0.5" color="#FFD" | ||
light="type: directional; intensity:2.6; color: #FFD; shadowBias: -0.00001; castShadow: true; shadowCameraRight: 7.9; shadowMapHeight: 2048; shadowMapWidth: 2048;" | ||
position="0.12 5.76 -2.14" rotation="0 0 0"> | ||
</a-entity> | ||
|
||
</a-scene> | ||
|
||
<script> | ||
// intercept the scene loaded event | ||
document.querySelector('a-scene').addEventListener('loaded', function () { | ||
enzofrancescaHM marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// get the scene | ||
var scene = document.querySelector('a-scene'); | ||
// add the bloom effect | ||
scene.setAttribute('bloom', {threshold: 1.0, strength: 0.6, radius: 1, exposure: 1.0}); | ||
}); | ||
</script> | ||
|
||
</body> | ||
|
||
</html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that the source is MIT licensed, the original copyright and license notice should be included.