Skip to content

Commit 7d2c540

Browse files
authored
Examples: Clean up. (#26934)
1 parent 8c76040 commit 7d2c540

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

examples/webgl_postprocessing_smaa.html

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,20 @@
2727
import * as THREE from 'three';
2828

2929
import Stats from 'three/addons/libs/stats.module.js';
30+
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
3031

3132
import { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js';
3233
import { RenderPass } from 'three/addons/postprocessing/RenderPass.js';
3334
import { SMAAPass } from 'three/addons/postprocessing/SMAAPass.js';
3435
import { OutputPass } from 'three/addons/postprocessing/OutputPass.js';
3536

37+
let camera, scene, renderer, composer, stats, smaaPass;
3638

37-
let camera, scene, renderer, composer, stats;
39+
const params = {
40+
enabled: true,
41+
autoRotate: true
42+
43+
};
3844

3945
init();
4046
animate();
@@ -66,7 +72,7 @@
6672
scene.add( mesh1 );
6773

6874
const texture = new THREE.TextureLoader().load( 'textures/brick_diffuse.jpg' );
69-
texture.anisotropy = 4;
75+
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
7076
texture.colorSpace = THREE.SRGBColorSpace;
7177

7278
const material2 = new THREE.MeshBasicMaterial( { map: texture } );
@@ -80,14 +86,22 @@
8086
composer = new EffectComposer( renderer );
8187
composer.addPass( new RenderPass( scene, camera ) );
8288

83-
const pass = new SMAAPass( window.innerWidth * renderer.getPixelRatio(), window.innerHeight * renderer.getPixelRatio() );
84-
composer.addPass( pass );
89+
smaaPass = new SMAAPass( window.innerWidth * renderer.getPixelRatio(), window.innerHeight * renderer.getPixelRatio() );
90+
composer.addPass( smaaPass );
8591

8692
const outputPass = new OutputPass();
8793
composer.addPass( outputPass );
8894

8995
window.addEventListener( 'resize', onWindowResize );
9096

97+
const gui = new GUI();
98+
99+
const smaaFolder = gui.addFolder( 'SMAA' );
100+
smaaFolder.add( params, 'enabled' );
101+
102+
const sceneFolder = gui.addFolder( 'Scene' );
103+
sceneFolder.add( params, 'autoRotate' );
104+
91105
}
92106

93107
function onWindowResize() {
@@ -109,15 +123,21 @@
109123

110124
stats.begin();
111125

112-
for ( let i = 0; i < scene.children.length; i ++ ) {
126+
if ( params.autoRotate === true ) {
113127

114-
const child = scene.children[ i ];
128+
for ( let i = 0; i < scene.children.length; i ++ ) {
115129

116-
child.rotation.x += 0.005;
117-
child.rotation.y += 0.01;
130+
const child = scene.children[ i ];
131+
132+
child.rotation.x += 0.005;
133+
child.rotation.y += 0.01;
134+
135+
}
118136

119137
}
120138

139+
smaaPass.enabled = params.enabled;
140+
121141
composer.render();
122142

123143
stats.end();

0 commit comments

Comments
 (0)