diff --git a/Source/Scene/OIT.js b/Source/Scene/OIT.js index b7fd40090c9e..84bc7084918d 100644 --- a/Source/Scene/OIT.js +++ b/Source/Scene/OIT.js @@ -525,6 +525,8 @@ define([ var framebuffer = passState.framebuffer; var length = commands.length; + var shadowsEnabled = scene.frameState.shadowHints.shadowsEnabled; + passState.framebuffer = oit._adjustTranslucentFBO; oit._adjustTranslucentCommand.execute(context, passState); passState.framebuffer = oit._adjustAlphaFBO; @@ -535,7 +537,7 @@ define([ for (j = 0; j < length; ++j) { command = commands[j]; - derivedCommand = command.derivedCommands.oit.translucentCommand; + derivedCommand = shadowsEnabled ? command.derivedCommands.oit.shadows.translucentCommand : command.derivedCommands.oit.translucentCommand; executeFunction(derivedCommand, scene, context, passState, debugFramebuffer); } @@ -543,7 +545,7 @@ define([ for (j = 0; j < length; ++j) { command = commands[j]; - derivedCommand = command.derivedCommands.oit.alphaCommand; + derivedCommand = shadowsEnabled ? command.derivedCommands.oit.shadows.alphaCommand : command.derivedCommands.oit.alphaCommand; executeFunction(derivedCommand, scene, context, passState, debugFramebuffer); } @@ -555,6 +557,8 @@ define([ var framebuffer = passState.framebuffer; var length = commands.length; + var shadowsEnabled = scene.frameState.shadowHints.shadowsEnabled; + passState.framebuffer = oit._adjustTranslucentFBO; oit._adjustTranslucentCommand.execute(context, passState); @@ -563,7 +567,7 @@ define([ for (var j = 0; j < length; ++j) { var command = commands[j]; - var derivedCommand = command.derivedCommands.oit.translucentCommand; + var derivedCommand = shadowsEnabled ? command.derivedCommands.oit.shadows.translucentCommand : command.derivedCommands.oit.translucentCommand; executeFunction(derivedCommand, scene, context, passState, debugFramebuffer); } diff --git a/Source/Scene/Scene.js b/Source/Scene/Scene.js index d43b448aab00..23189bcbb990 100644 --- a/Source/Scene/Scene.js +++ b/Source/Scene/Scene.js @@ -1108,15 +1108,13 @@ define([ var lightShadowMaps = frameState.shadowHints.lightShadowMaps; var lightShadowsEnabled = shadowsEnabled && (lightShadowMaps.length > 0); + // Update derived commands when any shadow maps become dirty var shadowsDirty = false; - if (shadowsEnabled && (command.receiveShadows || command.castShadows)) { - // Update derived commands when any shadow maps become dirty - var lastDirtyTime = frameState.shadowHints.lastDirtyTime; - if (command.lastDirtyTime !== lastDirtyTime) { - command.lastDirtyTime = lastDirtyTime; - command.dirty = true; - shadowsDirty = true; - } + var lastDirtyTime = frameState.shadowHints.lastDirtyTime; + if (command.lastDirtyTime !== lastDirtyTime) { + command.lastDirtyTime = lastDirtyTime; + command.dirty = true; + shadowsDirty = true; } if (command.dirty) { @@ -1131,7 +1129,8 @@ define([ var oit = scene._oit; if (command.pass === Pass.TRANSLUCENT && defined(oit) && oit.isSupported()) { if (lightShadowsEnabled && command.receiveShadows) { - derivedCommands.oit = oit.createDerivedCommands(command.derivedCommands.shadows.receiveCommand, context, derivedCommands.oit); + derivedCommands.oit = defined(derivedCommands.oit) ? derivedCommands.oit : {}; + derivedCommands.oit.shadows = oit.createDerivedCommands(command.derivedCommands.shadows.receiveCommand, context, derivedCommands.oit.shadows); } else { derivedCommands.oit = oit.createDerivedCommands(command, context, derivedCommands.oit); } @@ -2144,8 +2143,14 @@ define([ var shadowMaps = frameState.shadowMaps; var length = shadowMaps.length; - frameState.shadowHints.shadowsEnabled = (length > 0) && !frameState.passes.pick && (scene.mode === SceneMode.SCENE3D); - if (!frameState.shadowHints.shadowsEnabled) { + var shadowsEnabled = (length > 0) && !frameState.passes.pick && (scene.mode === SceneMode.SCENE3D); + if (shadowsEnabled !== frameState.shadowHints.shadowsEnabled) { + // Update derived commands when shadowsEnabled changes + ++frameState.shadowHints.lastDirtyTime; + frameState.shadowHints.shadowsEnabled = shadowsEnabled; + } + + if (!shadowsEnabled) { return; }