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

Examples: Introduce OutputPass. #26102

Merged
merged 3 commits into from
May 21, 2023
Merged
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Examples: Simplify selective bloom demo.
Mugen87 committed May 21, 2023
commit 24009996e702dde53afac421dacb47c107231316
72 changes: 10 additions & 62 deletions examples/webgl_postprocessing_unreal_bloom_selective.html
Original file line number Diff line number Diff line change
@@ -67,7 +67,7 @@
import { UnrealBloomPass } from 'three/addons/postprocessing/UnrealBloomPass.js';
import { OutputPass } from 'three/addons/postprocessing/OutputPass.js';

const ENTIRE_SCENE = 0, BLOOM_SCENE = 1;
const BLOOM_SCENE = 1;

const bloomLayer = new THREE.Layers();
bloomLayer.set( BLOOM_SCENE );
@@ -142,50 +142,28 @@

const gui = new GUI();

gui.add( params, 'scene', [ 'Scene with Glow', 'Glow only', 'Scene only' ] ).onChange( function ( value ) {

switch ( value ) {

case 'Scene with Glow':
bloomComposer.renderToScreen = false;
break;
case 'Glow only':
bloomComposer.renderToScreen = true;
break;
case 'Scene only':
// nothing to do
break;

}

render();

} );

const folder = gui.addFolder( 'Bloom Parameters' );

folder.add( params, 'exposure', 0.1, 2 ).onChange( function ( value ) {
gui.add( params, 'exposure', 0.1, 2 ).onChange( function ( value ) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Personally, I would prefer to retain the separation of model parameters from tone mapping parameters in the GUI. (It is less confusing to users, IMO.) We have used folders for that.

I would try to be consistent and put exposure/tonemapping last in the GUI.

Copy link
Collaborator Author

@Mugen87 Mugen87 May 21, 2023

Choose a reason for hiding this comment

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

So you mean we should make a separate GUI folder "tonemapping" that holds the exposure control and a separate folder for the bloom settings, right? I'll update the PR.


outputPass.toneMappingExposure = Math.pow( value, 4.0 );
render();

} );

folder.add( params, 'bloomThreshold', 0.0, 1.0 ).onChange( function ( value ) {
gui.add( params, 'bloomThreshold', 0.0, 1.0 ).onChange( function ( value ) {

bloomPass.threshold = Number( value );
render();

} );

folder.add( params, 'bloomStrength', 0.0, 10.0 ).onChange( function ( value ) {
gui.add( params, 'bloomStrength', 0.0, 10.0 ).onChange( function ( value ) {

bloomPass.strength = Number( value );
render();

} );

folder.add( params, 'bloomRadius', 0.0, 1.0 ).step( 0.01 ).onChange( function ( value ) {
gui.add( params, 'bloomRadius', 0.0, 1.0 ).step( 0.01 ).onChange( function ( value ) {

bloomPass.radius = Number( value );
render();
@@ -269,42 +247,12 @@

function render() {

switch ( params.scene ) {

case 'Scene only':
renderer.render( scene, camera );
break;
case 'Glow only':
renderBloom( false );
break;
case 'Scene with Glow':
default:
// render scene with bloom
renderBloom( true );
scene.traverse( darkenNonBloomed );
bloomComposer.render();
scene.traverse( restoreMaterial );

// render the entire scene, then render bloom scene on top
finalComposer.render();
break;

}

}

function renderBloom( mask ) {

if ( mask === true ) {

scene.traverse( darkenNonBloomed );
bloomComposer.render();
scene.traverse( restoreMaterial );

} else {

camera.layers.set( BLOOM_SCENE );
bloomComposer.render();
camera.layers.set( ENTIRE_SCENE );

}
// render the entire scene, then render bloom scene on top
finalComposer.render();

}