Skip to content

Commit 2e9cf8b

Browse files
authored
Merge pull request #6883 from AnalyticalGraphicsInc/oit-shadow-fix
Fix OIT analytical shadows crash
2 parents 79d7443 + 36f278d commit 2e9cf8b

File tree

5 files changed

+42
-13
lines changed

5 files changed

+42
-13
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Change Log
1313
* The Geocoder widget now takes terrain altitude into account when calculating its final destination.
1414
* The Viewer widget now takes terrain altitude into account when zooming or flying to imagery layers.
1515
* 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)
16+
* 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)
1617

1718
### 1.48 - 2018-08-01
1819

Source/Scene/FrameState.js

+6
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,12 @@ define([
239239
*/
240240
shadowsEnabled : true,
241241

242+
/**
243+
* Whether there are any active shadow maps that originate from light sources. Does not
244+
* include shadow maps that are used for analytical purposes.
245+
*/
246+
lightShadowsEnabled : true,
247+
242248
/**
243249
* All shadow maps that are enabled this frame.
244250
*/

Source/Scene/OIT.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ define([
540540
var framebuffer = passState.framebuffer;
541541
var length = commands.length;
542542

543-
var shadowsEnabled = scene.frameState.shadowHints.shadowsEnabled;
543+
var lightShadowsEnabled = scene.frameState.shadowHints.lightShadowsEnabled;
544544

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

560560
if (defined(invertClassification)) {
561561
command = invertClassification.unclassifiedCommand;
562562
command = defined(command.derivedCommands.logDepth) ? command.derivedCommands.logDepth.command : command;
563-
derivedCommand = (shadowsEnabled && command.receiveShadows) ? command.derivedCommands.oit.shadows.translucentCommand : command.derivedCommands.oit.translucentCommand;
563+
derivedCommand = (lightShadowsEnabled && command.receiveShadows) ? command.derivedCommands.oit.shadows.translucentCommand : command.derivedCommands.oit.translucentCommand;
564564
executeFunction(derivedCommand, scene, context, passState, debugFramebuffer);
565565
}
566566

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

576576
if (defined(invertClassification)) {
577577
command = invertClassification.unclassifiedCommand;
578578
command = defined(command.derivedCommands.logDepth) ? command.derivedCommands.logDepth.command : command;
579-
derivedCommand = (shadowsEnabled && command.receiveShadows) ? command.derivedCommands.oit.shadows.alphaCommand : command.derivedCommands.oit.alphaCommand;
579+
derivedCommand = (lightShadowsEnabled && command.receiveShadows) ? command.derivedCommands.oit.shadows.alphaCommand : command.derivedCommands.oit.alphaCommand;
580580
executeFunction(derivedCommand, scene, context, passState, debugFramebuffer);
581581
}
582582

@@ -588,7 +588,7 @@ define([
588588
var framebuffer = passState.framebuffer;
589589
var length = commands.length;
590590

591-
var shadowsEnabled = scene.frameState.shadowHints.shadowsEnabled;
591+
var lightShadowsEnabled = scene.frameState.shadowHints.lightShadowsEnabled;
592592

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

609609
if (defined(invertClassification)) {
610610
command = invertClassification.unclassifiedCommand;
611611
command = defined(command.derivedCommands.logDepth) ? command.derivedCommands.logDepth.command : command;
612-
derivedCommand = (shadowsEnabled && command.receiveShadows) ? command.derivedCommands.oit.shadows.translucentCommand : command.derivedCommands.oit.translucentCommand;
612+
derivedCommand = (lightShadowsEnabled && command.receiveShadows) ? command.derivedCommands.oit.shadows.translucentCommand : command.derivedCommands.oit.translucentCommand;
613613
executeFunction(derivedCommand, scene, context, passState, debugFramebuffer);
614614
}
615615

Source/Scene/Scene.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1498,7 +1498,7 @@ define([
14981498
var shadowsEnabled = frameState.shadowHints.shadowsEnabled;
14991499
var shadowMaps = frameState.shadowHints.shadowMaps;
15001500
var lightShadowMaps = frameState.shadowHints.lightShadowMaps;
1501-
var lightShadowsEnabled = shadowsEnabled && (lightShadowMaps.length > 0);
1501+
var lightShadowsEnabled = frameState.shadowHints.lightShadowsEnabled;
15021502

15031503
// Update derived commands when any shadow maps become dirty
15041504
var shadowsDirty = false;
@@ -2082,10 +2082,7 @@ define([
20822082
return;
20832083
}
20842084

2085-
var shadowsEnabled = scene.frameState.shadowHints.shadowsEnabled;
2086-
var lightShadowsEnabled = shadowsEnabled && (scene.frameState.shadowHints.lightShadowMaps.length > 0);
2087-
2088-
if (lightShadowsEnabled && command.receiveShadows && defined(command.derivedCommands.shadows)) {
2085+
if (frameState.shadowHints.lightShadowsEnabled && command.receiveShadows && defined(command.derivedCommands.shadows)) {
20892086
// If the command receives shadows, execute the derived shadows command.
20902087
// Some commands, such as OIT derived commands, do not have derived shadow commands themselves
20912088
// and instead shadowing is built-in. In this case execute the command regularly below.
@@ -2940,6 +2937,8 @@ define([
29402937
frameState.shadowHints.shadowsEnabled = shadowsEnabled;
29412938
}
29422939

2940+
frameState.shadowHints.lightShadowsEnabled = false;
2941+
29432942
if (!shadowsEnabled) {
29442943
return;
29452944
}
@@ -2964,6 +2963,7 @@ define([
29642963

29652964
if (shadowMap.fromLightSource) {
29662965
frameState.shadowHints.lightShadowMaps.push(shadowMap);
2966+
frameState.shadowHints.lightShadowsEnabled = true;
29672967
}
29682968

29692969
if (shadowMap.dirty) {

Specs/Scene/ShadowMapSpec.js

+22
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,28 @@ defineSuite([
11341134
floor.show = false;
11351135
});
11361136

1137+
it('does not receive shadows if fromLightSource is false', function() {
1138+
box.show = true;
1139+
floorTranslucent.show = true;
1140+
createCascadedShadowMap();
1141+
scene.shadowMap.fromLightSource = false;
1142+
1143+
// Render without shadows
1144+
scene.shadowMap.enabled = false;
1145+
var unshadowedColor;
1146+
renderAndCall(function(rgba) {
1147+
unshadowedColor = rgba;
1148+
expect(rgba).not.toEqual(backgroundColor);
1149+
});
1150+
1151+
// Render with shadows
1152+
scene.shadowMap.enabled = true;
1153+
renderAndCall(function(rgba) {
1154+
expect(rgba).not.toEqual(backgroundColor);
1155+
expect(rgba).toEqual(unshadowedColor);
1156+
});
1157+
});
1158+
11371159
it('tweaking shadow bias parameters works', function() {
11381160
box.show = true;
11391161
floor.show = true;

0 commit comments

Comments
 (0)