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

Fix OIT analytical shadows crash #6883

Merged
merged 3 commits into from
Aug 8, 2018
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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Change Log
##### Fixes :wrench:
* The Geocoder widget now takes terrain altitude into account when calculating its final destination.
* Fixed bug that caused a new `ClippingPlaneCollection` to be created every frame when used with a model entity [#6872](https://github.com/AnalyticalGraphicsInc/cesium/pull/6872)
* Fixed crash when rendering translucent objects when all shadow maps in the scene set `fromLightSource` to false. [#6883](https://github.com/AnalyticalGraphicsInc/cesium/pull/6883)

### 1.48 - 2018-08-01

Expand Down
6 changes: 6 additions & 0 deletions Source/Scene/FrameState.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,12 @@ define([
*/
shadowsEnabled : true,

/**
* Whether there are any active shadow maps that originate from light sources. Does not
* include shadow maps that are used for analytical purposes.
*/
lightShadowsEnabled : true,

/**
* All shadow maps that are enabled this frame.
*/
Expand Down
16 changes: 8 additions & 8 deletions Source/Scene/OIT.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ define([
var framebuffer = passState.framebuffer;
var length = commands.length;

var shadowsEnabled = scene.frameState.shadowHints.shadowsEnabled;
var lightShadowsEnabled = scene.frameState.shadowHints.lightShadowsEnabled;

passState.framebuffer = oit._adjustTranslucentFBO;
oit._adjustTranslucentCommand.execute(context, passState);
Expand All @@ -553,14 +553,14 @@ define([
for (j = 0; j < length; ++j) {
command = commands[j];
command = defined(command.derivedCommands.logDepth) ? command.derivedCommands.logDepth.command : command;
derivedCommand = (shadowsEnabled && command.receiveShadows) ? command.derivedCommands.oit.shadows.translucentCommand : command.derivedCommands.oit.translucentCommand;
derivedCommand = (lightShadowsEnabled && command.receiveShadows) ? command.derivedCommands.oit.shadows.translucentCommand : command.derivedCommands.oit.translucentCommand;
executeFunction(derivedCommand, scene, context, passState, debugFramebuffer);
}

if (defined(invertClassification)) {
command = invertClassification.unclassifiedCommand;
command = defined(command.derivedCommands.logDepth) ? command.derivedCommands.logDepth.command : command;
derivedCommand = (shadowsEnabled && command.receiveShadows) ? command.derivedCommands.oit.shadows.translucentCommand : command.derivedCommands.oit.translucentCommand;
derivedCommand = (lightShadowsEnabled && command.receiveShadows) ? command.derivedCommands.oit.shadows.translucentCommand : command.derivedCommands.oit.translucentCommand;
executeFunction(derivedCommand, scene, context, passState, debugFramebuffer);
}

Expand All @@ -569,14 +569,14 @@ define([
for (j = 0; j < length; ++j) {
command = commands[j];
command = defined(command.derivedCommands.logDepth) ? command.derivedCommands.logDepth.command : command;
derivedCommand = (shadowsEnabled && command.receiveShadows) ? command.derivedCommands.oit.shadows.alphaCommand : command.derivedCommands.oit.alphaCommand;
derivedCommand = (lightShadowsEnabled && command.receiveShadows) ? command.derivedCommands.oit.shadows.alphaCommand : command.derivedCommands.oit.alphaCommand;
executeFunction(derivedCommand, scene, context, passState, debugFramebuffer);
}

if (defined(invertClassification)) {
command = invertClassification.unclassifiedCommand;
command = defined(command.derivedCommands.logDepth) ? command.derivedCommands.logDepth.command : command;
derivedCommand = (shadowsEnabled && command.receiveShadows) ? command.derivedCommands.oit.shadows.alphaCommand : command.derivedCommands.oit.alphaCommand;
derivedCommand = (lightShadowsEnabled && command.receiveShadows) ? command.derivedCommands.oit.shadows.alphaCommand : command.derivedCommands.oit.alphaCommand;
executeFunction(derivedCommand, scene, context, passState, debugFramebuffer);
}

Expand All @@ -588,7 +588,7 @@ define([
var framebuffer = passState.framebuffer;
var length = commands.length;

var shadowsEnabled = scene.frameState.shadowHints.shadowsEnabled;
var lightShadowsEnabled = scene.frameState.shadowHints.lightShadowsEnabled;

passState.framebuffer = oit._adjustTranslucentFBO;
oit._adjustTranslucentCommand.execute(context, passState);
Expand All @@ -602,14 +602,14 @@ define([
for (var j = 0; j < length; ++j) {
command = commands[j];
command = defined(command.derivedCommands.logDepth) ? command.derivedCommands.logDepth.command : command;
derivedCommand = (shadowsEnabled && command.receiveShadows) ? command.derivedCommands.oit.shadows.translucentCommand : command.derivedCommands.oit.translucentCommand;
derivedCommand = (lightShadowsEnabled && command.receiveShadows) ? command.derivedCommands.oit.shadows.translucentCommand : command.derivedCommands.oit.translucentCommand;
executeFunction(derivedCommand, scene, context, passState, debugFramebuffer);
}

if (defined(invertClassification)) {
command = invertClassification.unclassifiedCommand;
command = defined(command.derivedCommands.logDepth) ? command.derivedCommands.logDepth.command : command;
derivedCommand = (shadowsEnabled && command.receiveShadows) ? command.derivedCommands.oit.shadows.translucentCommand : command.derivedCommands.oit.translucentCommand;
derivedCommand = (lightShadowsEnabled && command.receiveShadows) ? command.derivedCommands.oit.shadows.translucentCommand : command.derivedCommands.oit.translucentCommand;
executeFunction(derivedCommand, scene, context, passState, debugFramebuffer);
}

Expand Down
10 changes: 5 additions & 5 deletions Source/Scene/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -1498,7 +1498,7 @@ define([
var shadowsEnabled = frameState.shadowHints.shadowsEnabled;
var shadowMaps = frameState.shadowHints.shadowMaps;
var lightShadowMaps = frameState.shadowHints.lightShadowMaps;
var lightShadowsEnabled = shadowsEnabled && (lightShadowMaps.length > 0);
var lightShadowsEnabled = frameState.shadowHints.lightShadowsEnabled;

// Update derived commands when any shadow maps become dirty
var shadowsDirty = false;
Expand Down Expand Up @@ -2082,10 +2082,7 @@ define([
return;
}

var shadowsEnabled = scene.frameState.shadowHints.shadowsEnabled;
var lightShadowsEnabled = shadowsEnabled && (scene.frameState.shadowHints.lightShadowMaps.length > 0);

if (lightShadowsEnabled && command.receiveShadows && defined(command.derivedCommands.shadows)) {
if (frameState.shadowHints.lightShadowsEnabled && command.receiveShadows && defined(command.derivedCommands.shadows)) {
// If the command receives shadows, execute the derived shadows command.
// Some commands, such as OIT derived commands, do not have derived shadow commands themselves
// and instead shadowing is built-in. In this case execute the command regularly below.
Expand Down Expand Up @@ -2940,6 +2937,8 @@ define([
frameState.shadowHints.shadowsEnabled = shadowsEnabled;
}

frameState.shadowHints.lightShadowsEnabled = false;

if (!shadowsEnabled) {
return;
}
Expand All @@ -2964,6 +2963,7 @@ define([

if (shadowMap.fromLightSource) {
frameState.shadowHints.lightShadowMaps.push(shadowMap);
frameState.shadowHints.lightShadowsEnabled = true;
}

if (shadowMap.dirty) {
Expand Down
22 changes: 22 additions & 0 deletions Specs/Scene/ShadowMapSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,28 @@ defineSuite([
floor.show = false;
});

it('does not receive shadows if fromLightSource is false', function() {
box.show = true;
floorTranslucent.show = true;
createCascadedShadowMap();
scene.shadowMap.fromLightSource = false;

// Render without shadows
scene.shadowMap.enabled = false;
var unshadowedColor;
renderAndCall(function(rgba) {
unshadowedColor = rgba;
expect(rgba).not.toEqual(backgroundColor);
});

// Render with shadows
scene.shadowMap.enabled = true;
renderAndCall(function(rgba) {
expect(rgba).not.toEqual(backgroundColor);
expect(rgba).toEqual(unshadowedColor);
});
});

it('tweaking shadow bias parameters works', function() {
box.show = true;
floor.show = true;
Expand Down