Skip to content

Commit 5815127

Browse files
committed
add the ability to disable shadows to see performance difference.
1 parent d005f12 commit 5815127

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

examples/webgl_lights_physical.html

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
var camera, scene, renderer,
5454
bulbLight, bulbMat, ambientLight,
5555
object, loader, stats;
56+
var ballMat, cubeMat, floorMat;
57+
5658

5759
// ref for lumens: http://www.power-sure.com/lumens.htm
5860
var bulbLuminousPowers = {
@@ -82,6 +84,7 @@
8284
};
8385

8486
var params = {
87+
shadows: true,
8588
exposure: 0.68,
8689
bulbPower: Object.keys( bulbLuminousPowers )[2],
8790
hemiIrradiance: Object.keys( hemiLuminousIrradiances )[0]
@@ -127,7 +130,7 @@
127130
hemiLight = new THREE.HemisphereLight( 0xddeeff, 0x0f0e0d, 0.02 );
128131
scene.add( hemiLight );
129132

130-
var floorMat = new THREE.MeshStandardMaterial( {
133+
floorMat = new THREE.MeshStandardMaterial( {
131134
roughness: 0.8,
132135
color: 0xffffff,
133136
metalness: 0.2,
@@ -159,8 +162,7 @@
159162
floorMat.needsUpdate = true;
160163
} );
161164

162-
163-
var cubeMat = new THREE.MeshStandardMaterial( {
165+
cubeMat = new THREE.MeshStandardMaterial( {
164166
roughness: 0.7,
165167
color: 0xffffff,
166168
bumpScale: 0.002,
@@ -183,7 +185,7 @@
183185
cubeMat.needsUpdate = true;
184186
} );
185187

186-
var ballMat = new THREE.MeshStandardMaterial( {
188+
ballMat = new THREE.MeshStandardMaterial( {
187189
roughness: 0,
188190
metalness: 0.0,
189191
color: 0xffffff
@@ -257,6 +259,7 @@
257259
gui.add( params, 'hemiIrradiance', Object.keys( hemiLuminousIrradiances ) );
258260
gui.add( params, 'bulbPower', Object.keys( bulbLuminousPowers ) );
259261
gui.add( params, 'exposure', 0, 1 );
262+
gui.add( params, 'shadows' );
260263
gui.open();
261264
}
262265

@@ -279,10 +282,19 @@
279282

280283
}
281284

285+
var previousShadowMap = false;
286+
282287
function render() {
283288

284289
renderer.toneMappingExposure = Math.pow( params.exposure, 5.0 ); // to allow for very bright scenes.
285-
290+
renderer.shadowMap.enabled = params.shadows;
291+
bulbLight.castShadow = params.shadows;
292+
if( params.shadows !== previousShadowMap ) {
293+
ballMat.needsUpdate = true;
294+
cubeMat.needsUpdate = true;
295+
floorMat.needsUpdate = true;
296+
previousShadowMap = params.shadows;
297+
}
286298
bulbLight.power = bulbLuminousPowers[ params.bulbPower ];
287299
bulbMat.emissiveIntensity = bulbLight.intensity / Math.pow( 0.02, 2.0 ); // convert from intensity to irradiance at bulb surface
288300

0 commit comments

Comments
 (0)