Skip to content

Examples: Make tone mapping demos more interesting. #31045

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

Merged
merged 1 commit into from
May 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
Binary file added examples/models/gltf/venice_mask.glb
Binary file not shown.
Binary file modified examples/screenshots/webgl_tonemapping.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgpu_tonemapping.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 32 additions & 23 deletions examples/webgl_tonemapping.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<body>
<div id="info">
<a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - Tone Mapping<br />
Battle Damaged Sci-fi Helmet by
<a href="https://sketchfab.com/theblueturtle_" target="_blank" rel="noopener">theblueturtle_</a><br />
Venice Mask by
<a href="https://sketchfab.com/D.art" target="_blank" rel="noopener">DailyArt</a> is licensed under <a href="https://creativecommons.org/licenses/by-nc/4.0/" target="_blank" rel="noopener">CC Attribution-NonCommercial</a><br />
<a href="https://hdrihaven.com/hdri/?h=venice_sunset" target="_blank" rel="noopener">Venice Sunset</a> from <a href="https://hdrihaven.com/" target="_blank" rel="noopener">HDRI Haven</a>
</div>

Expand All @@ -31,14 +31,15 @@
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
import { RGBELoader } from 'three/addons/loaders/RGBELoader.js';

let mesh, renderer, scene, camera, controls;
let renderer, scene, camera, controls;
let gui, guiExposure = null;

const params = {
exposure: 1.0,
toneMapping: 'AgX',
toneMapping: 'Neutral',
blurriness: 0.3,
intensity: 1.0,
};
Expand All @@ -65,6 +66,7 @@
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setAnimationLoop( animate );
document.body.appendChild( renderer.domElement );

renderer.toneMapping = toneMappingOptions[ params.toneMapping ];
Expand Down Expand Up @@ -92,24 +94,36 @@
scene = new THREE.Scene();
scene.backgroundBlurriness = params.blurriness;

camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.25, 20 );
camera.position.set( - 1.8, 0.6, 2.7 );
const light = new THREE.DirectionalLight( 0xfff3ee, 3 ); // simualte sun
light.position.set( 1, 0.05, 0.7 );
scene.add( light );

// scene.add( new THREE.DirectionalLightHelper( light, 1, 0x000000 ) );

camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.01, 10 );
camera.position.set( - 0.02, 0.03, 0.05 );

controls = new OrbitControls( camera, renderer.domElement );
controls.addEventListener( 'change', render ); // use if there is no animation loop
controls.enableZoom = false;
controls.enablePan = false;
controls.target.set( 0, 0, - 0.2 );
controls.enableDamping = true;
controls.minDistance = 0.03;
controls.maxDistance = 0.2;
controls.target.set( 0, 0.03, 0 );
controls.update();

const rgbeLoader = new RGBELoader()
.setPath( 'textures/equirectangular/' );

const gltfLoader = new GLTFLoader().setPath( 'models/gltf/DamagedHelmet/glTF/' );
const dracoLoader = new DRACOLoader();
dracoLoader.setDecoderPath( 'jsm/libs/draco/gltf/' );

const gltfLoader = new GLTFLoader();
gltfLoader.setDRACOLoader( dracoLoader );
gltfLoader.setPath( 'models/gltf/' );

const [ texture, gltf ] = await Promise.all( [
rgbeLoader.loadAsync( 'venice_sunset_1k.hdr' ),
gltfLoader.loadAsync( 'DamagedHelmet.gltf' ),
gltfLoader.loadAsync( 'venice_mask.glb' ),
] );

// environment
Expand All @@ -121,13 +135,12 @@

// model

mesh = gltf.scene.getObjectByName( 'node_damagedHelmet_-6514' );
scene.add( mesh );

render();
scene.add( gltf.scene );

window.addEventListener( 'resize', onWindowResize );

//

gui = new GUI();
const toneMappingFolder = gui.addFolder( 'Tone Mapping' );

Expand All @@ -136,10 +149,9 @@
.name( 'type' )
.onChange( function () {

updateGUI( toneMappingFolder );

Check warning

Code scanning / CodeQL

Superfluous trailing arguments Warning

Superfluous argument passed to
function updateGUI
.

renderer.toneMapping = toneMappingOptions[ params.toneMapping ];
render();

} );

Expand All @@ -148,7 +160,6 @@
.onChange( function ( value ) {

renderer.toneMappingExposure = value;
render();

} );

Expand All @@ -159,7 +170,6 @@
.onChange( function ( value ) {

scene.backgroundBlurriness = value;
render();

} );

Expand All @@ -168,17 +178,16 @@
.onChange( function ( value ) {

scene.backgroundIntensity = value;
render();

} );

updateGUI( toneMappingFolder );

Check warning

Code scanning / CodeQL

Superfluous trailing arguments Warning

Superfluous argument passed to
function updateGUI
.

gui.open();

}

function updateGUI( folder ) {
function updateGUI() {

if ( params.toneMapping === 'None' ) {

Expand All @@ -200,11 +209,11 @@

renderer.setSize( window.innerWidth, window.innerHeight );

render();

}

function render() {
function animate() {

controls.update();

renderer.render( scene, camera );

Expand Down
43 changes: 30 additions & 13 deletions examples/webgpu_tonemapping.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<body>
<div id="info">
<a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> webgpu - tone mapping<br />
Battle Damaged Sci-fi Helmet by
<a href="https://sketchfab.com/theblueturtle_" target="_blank" rel="noopener">theblueturtle_</a><br />
Venice Mask by
<a href="https://sketchfab.com/D.art" target="_blank" rel="noopener">DailyArt</a> is licensed under <a href="https://creativecommons.org/licenses/by-nc/4.0/" target="_blank" rel="noopener">CC Attribution-NonCommercial</a><br />
<a href="https://hdrihaven.com/hdri/?h=venice_sunset" target="_blank" rel="noopener">Venice Sunset</a> from <a href="https://hdrihaven.com/" target="_blank" rel="noopener">HDRI Haven</a>
</div>

Expand All @@ -33,14 +33,15 @@
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
import { RGBELoader } from 'three/addons/loaders/RGBELoader.js';

let mesh, renderer, scene, camera, controls;
let renderer, scene, camera, controls;
let gui, guiExposure = null;

const params = {
exposure: 1.0,
toneMapping: 'AgX',
toneMapping: 'Neutral',
blurriness: 0.3,
intensity: 1.0,
};
Expand Down Expand Up @@ -75,23 +76,36 @@
scene = new THREE.Scene();
scene.backgroundBlurriness = params.blurriness;

camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.25, 20 );
camera.position.set( - 1.8, 0.6, 2.7 );
const light = new THREE.DirectionalLight( 0xfff3ee, 3 ); // simualte sun
light.position.set( 1, 0.05, 0.7 );
scene.add( light );

// scene.add( new THREE.DirectionalLightHelper( light, 1, 0x000000 ) );

camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.01, 10 );
camera.position.set( - 0.02, 0.03, 0.05 );

controls = new OrbitControls( camera, renderer.domElement );
controls.enableZoom = false;
controls.enablePan = false;
controls.target.set( 0, 0, - 0.2 );
controls.enableDamping = true;
controls.minDistance = 0.03;
controls.maxDistance = 0.2;
controls.target.set( 0, 0.03, 0 );
controls.update();

const rgbeLoader = new RGBELoader()
.setPath( 'textures/equirectangular/' );

const gltfLoader = new GLTFLoader().setPath( 'models/gltf/DamagedHelmet/glTF/' );
const dracoLoader = new DRACOLoader();
dracoLoader.setDecoderPath( 'jsm/libs/draco/gltf/' );

const gltfLoader = new GLTFLoader();
gltfLoader.setDRACOLoader( dracoLoader );
gltfLoader.setPath( 'models/gltf/' );

const [ texture, gltf ] = await Promise.all( [
rgbeLoader.loadAsync( 'venice_sunset_1k.hdr' ),
gltfLoader.loadAsync( 'DamagedHelmet.gltf' ),
gltfLoader.loadAsync( 'venice_mask.glb' ),
] );

// environment
Expand All @@ -103,11 +117,12 @@

// model

mesh = gltf.scene.getObjectByName( 'node_damagedHelmet_-6514' );
scene.add( mesh );
scene.add( gltf.scene );

window.addEventListener( 'resize', onWindowResize );

//

gui = new GUI();
const toneMappingFolder = gui.addFolder( 'Tone Mapping' );

Expand All @@ -116,7 +131,7 @@
.name( 'type' )
.onChange( function () {

updateGUI( toneMappingFolder );

Check warning

Code scanning / CodeQL

Superfluous trailing arguments Warning

Superfluous argument passed to
function updateGUI
.

renderer.toneMapping = toneMappingOptions[ params.toneMapping ];

Expand Down Expand Up @@ -148,13 +163,13 @@

} );

updateGUI( toneMappingFolder );

Check warning

Code scanning / CodeQL

Superfluous trailing arguments Warning

Superfluous argument passed to
function updateGUI
.

gui.open();

}

function updateGUI( folder ) {
function updateGUI() {

if ( params.toneMapping === 'None' ) {

Expand All @@ -180,6 +195,8 @@

function animate() {

controls.update();

renderer.render( scene, camera );

}
Expand Down