Skip to content

Commit

Permalink
Merge pull request #5940 from AnalyticalGraphicsInc/fix-flickering
Browse files Browse the repository at this point in the history
Fix flickering for tileset with thin walls
  • Loading branch information
bagnell authored Oct 30, 2017
2 parents 35f810e + c6d9dcd commit 5731e2f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Change Log
* Added `customTags` property to the UrlTemplateImageryProvider to allow custom keywords in the template URL. [#5696](https://github.com/AnalyticalGraphicsInc/cesium/pull/5696)
* Improved CZML Reference Properties example [#5754](https://github.com/AnalyticalGraphicsInc/cesium/pull/5754)
* Fixed bug with placemarks in imported KML: placemarks with no specified icon would be displayed with default icon. [#5819](https://github.com/AnalyticalGraphicsInc/cesium/issues/5819)
* Fixed flickering artifacts on tilesets with thin walls. [#5940](https://github.com/AnalyticalGraphicsInc/cesium/pull/5940)
* Fixed bright fog when terrain lighting is enabled and added `Fog.minimumBrightness` to affect how bright the fog will be when in complete darkness. [#5934](https://github.com/AnalyticalGraphicsInc/cesium/pull/5934)

### 1.38 - 2017-10-02
Expand Down
3 changes: 2 additions & 1 deletion Source/Scene/Batched3DModel3DTileContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,8 @@ define([
// If any commands were pushed, add derived commands
var commandEnd = frameState.commandList.length;
if ((commandStart < commandEnd) && frameState.passes.render) {
this._batchTable.addDerivedCommands(frameState, commandStart);
var finalResolution = this._tile._finalResolution;
this._batchTable.addDerivedCommands(frameState, commandStart, finalResolution);
}
};

Expand Down
18 changes: 16 additions & 2 deletions Source/Scene/Cesium3DTileBatchTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,7 @@ define([
OPAQUE_AND_TRANSLUCENT : 2
};

Cesium3DTileBatchTable.prototype.addDerivedCommands = function(frameState, commandStart) {
Cesium3DTileBatchTable.prototype.addDerivedCommands = function(frameState, commandStart, finalResolution) {
var commandList = frameState.commandList;
var commandEnd = commandList.length;
var tile = this._content._tile;
Expand All @@ -1236,7 +1236,7 @@ define([
}

if (bivariateVisibilityTest) {
if (command.pass !== Pass.TRANSLUCENT) {
if (command.pass !== Pass.TRANSLUCENT && !finalResolution) {
if (!defined(derivedCommands.zback)) {
derivedCommands.zback = deriveZBackfaceCommand(derivedCommands.originalCommand);
}
Expand Down Expand Up @@ -1329,6 +1329,20 @@ define([
var rs = clone(derivedCommand.renderState, true);
rs.cull.enabled = true;
rs.cull.face = CullFace.FRONT;
// Back faces do not need to write color.
rs.colorMask = {
red : false,
green : false,
blue : false,
alpha : false
};
// Push back face depth away from the camera so it is less likely that back faces and front faces of the same tile
// intersect and overlap. This helps avoid flickering for very thin double-sided walls.
rs.polygonOffset = {
enabled : true,
factor : 5.0,
units : 5.0
};
derivedCommand.renderState = RenderState.fromCache(rs);
derivedCommand.castShadows = false;
derivedCommand.receiveShadows = false;
Expand Down
2 changes: 1 addition & 1 deletion Source/Scene/Instanced3DModel3DTileContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ define([
// If any commands were pushed, add derived commands
var commandEnd = frameState.commandList.length;
if ((commandStart < commandEnd) && frameState.passes.render) {
this._batchTable.addDerivedCommands(frameState, commandStart);
this._batchTable.addDerivedCommands(frameState, commandStart, false);
}
};

Expand Down
6 changes: 4 additions & 2 deletions Specs/Scene/Cesium3DTilesetSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2492,8 +2492,9 @@ defineSuite([

scene.renderForSpecs();

// 2 for root tile, 2 for child, 1 for stencil clear
expect(statistics.numberOfCommands).toEqual(5);
// 2 for root tile, 1 for child, 1 for stencil clear
// Tiles that are marked as finalResolution, including leaves, do not create back face commands
expect(statistics.numberOfCommands).toEqual(4);
expect(root.selected).toBe(true);
expect(root._finalResolution).toBe(false);
expect(root.children[0].children[0].children[3].selected).toBe(true);
Expand All @@ -2504,6 +2505,7 @@ defineSuite([
var rs = commandList[1].renderState;
expect(rs.cull.enabled).toBe(true);
expect(rs.cull.face).toBe(CullFace.FRONT);
expect(rs.polygonOffset.enabled).toBe(true);
});
});

Expand Down

0 comments on commit 5731e2f

Please sign in to comment.