Skip to content

Commit

Permalink
Merge pull request #9719 from CesiumGS/edl-fixes
Browse files Browse the repository at this point in the history
Fix eye dome lighting crashes
  • Loading branch information
ebogo1 authored Aug 13, 2021
2 parents 1323f5e + 9d6b0bf commit e981812
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

### 1.85 - 2021-08-10

##### Fixes :wrench:

- Fixed several crashes related to point cloud eye dome lighting. [#9719](https://github.com/CesiumGS/cesium/pull/9719)

### 1.84 - 2021-08-02

##### Breaking Changes :mega:
Expand Down
34 changes: 29 additions & 5 deletions Source/Scene/PointCloudEyeDomeLighting.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ PointCloudEyeDomeLighting.prototype.update = function (
var commandList = frameState.commandList;
var commandEnd = commandList.length;

var derivedCommand;
var originalShaderProgram;

for (i = commandStart; i < commandEnd; ++i) {
var command = commandList[i];
if (
Expand All @@ -243,24 +246,45 @@ PointCloudEyeDomeLighting.prototype.update = function (
) {
continue;
}
var derivedCommand = command.derivedCommands.pointCloudProcessor;

// These variables need to get reset for each iteration. It has to be
// done manually since var is function scope not block scope.
derivedCommand = undefined;
originalShaderProgram = undefined;

var derivedCommandObject = command.derivedCommands.pointCloudProcessor;
if (defined(derivedCommandObject)) {
derivedCommand = derivedCommandObject.command;
originalShaderProgram = derivedCommandObject.originalShaderProgram;
}

if (
!defined(derivedCommand) ||
command.dirty ||
dirty ||
originalShaderProgram !== command.shaderProgram ||
derivedCommand.framebuffer !== this._framebuffer
) {
// Prevent crash when tiles out-of-view come in-view during context size change
derivedCommand = DrawCommand.shallowClone(command);
command.derivedCommands.pointCloudProcessor = derivedCommand;

// Prevent crash when tiles out-of-view come in-view during context size change or
// when the underlying shader changes while EDL is disabled
derivedCommand = DrawCommand.shallowClone(command, derivedCommand);
derivedCommand.framebuffer = this._framebuffer;
derivedCommand.shaderProgram = getECShaderProgram(
frameState.context,
command.shaderProgram
);
derivedCommand.castShadows = false;
derivedCommand.receiveShadows = false;

if (!defined(derivedCommandObject)) {
derivedCommandObject = {
command: derivedCommand,
originalShaderProgram: command.shaderProgram,
};
command.derivedCommands.pointCloudProcessor = derivedCommandObject;
}

derivedCommandObject.originalShaderProgram = command.shaderProgram;
}

commandList[i] = derivedCommand;
Expand Down
49 changes: 43 additions & 6 deletions Specs/Scene/PointCloudEyeDomeLightingSpec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Cartesian3 } from "../../Source/Cesium.js";
import { Cesium3DTileStyle } from "../../Source/Cesium.js";
import { HeadingPitchRange } from "../../Source/Cesium.js";
import { Math as CesiumMath } from "../../Source/Cesium.js";
import { PerspectiveFrustum } from "../../Source/Cesium.js";
Expand Down Expand Up @@ -45,14 +46,12 @@ describe(
});

it("adds a clear command and a post-processing draw call", function () {
if (!PointCloudEyeDomeLighting.isSupported(scene.frameState.context)) {
return;
}

return Cesium3DTilesTester.loadTileset(scene, pointCloudNoColorUrl).then(
function (tileset) {
if (
!PointCloudEyeDomeLighting.isSupported(scene.frameState.context)
) {
return;
}

tileset.pointCloudShading.eyeDomeLighting = true;

scene.renderForSpecs();
Expand All @@ -67,6 +66,10 @@ describe(
});

it("does not change commands for pick calls", function () {
if (!PointCloudEyeDomeLighting.isSupported(scene.frameState.context)) {
return;
}

return Cesium3DTilesTester.loadTileset(scene, pointCloudNoColorUrl).then(
function (tileset) {
tileset.pointCloudShading.eyeDomeLighting = true;
Expand All @@ -81,6 +84,40 @@ describe(
}
);
});

it("works when point cloud shader changes", function () {
if (!PointCloudEyeDomeLighting.isSupported(scene.frameState.context)) {
return;
}

return Cesium3DTilesTester.loadTileset(scene, pointCloudNoColorUrl).then(
function (tileset) {
tileset.pointCloudShading.attenuation = true;
tileset.pointCloudShading.eyeDomeLighting = true;

scene.renderForSpecs();

tileset.pointCloudShading.eyeDomeLighting = false;

scene.renderForSpecs();

tileset.style = new Cesium3DTileStyle({
color: "color('red')",
});

scene.renderForSpecs();

// Forces destroyed shaders to be released
scene.context.shaderCache.destroyReleasedShaderPrograms();

tileset.pointCloudShading.eyeDomeLighting = true;

scene.renderForSpecs();

expect(scene.frameState.commandList.length).toBe(3);
}
);
});
},
"WebGL"
);

0 comments on commit e981812

Please sign in to comment.