Skip to content

Commit 5731e2f

Browse files
authored
Merge pull request #5940 from AnalyticalGraphicsInc/fix-flickering
Fix flickering for tileset with thin walls
2 parents 35f810e + c6d9dcd commit 5731e2f

5 files changed

+24
-6
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Change Log
1616
* Added `customTags` property to the UrlTemplateImageryProvider to allow custom keywords in the template URL. [#5696](https://github.com/AnalyticalGraphicsInc/cesium/pull/5696)
1717
* Improved CZML Reference Properties example [#5754](https://github.com/AnalyticalGraphicsInc/cesium/pull/5754)
1818
* 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)
19+
* Fixed flickering artifacts on tilesets with thin walls. [#5940](https://github.com/AnalyticalGraphicsInc/cesium/pull/5940)
1920
* 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)
2021

2122
### 1.38 - 2017-10-02

Source/Scene/Batched3DModel3DTileContent.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,8 @@ define([
452452
// If any commands were pushed, add derived commands
453453
var commandEnd = frameState.commandList.length;
454454
if ((commandStart < commandEnd) && frameState.passes.render) {
455-
this._batchTable.addDerivedCommands(frameState, commandStart);
455+
var finalResolution = this._tile._finalResolution;
456+
this._batchTable.addDerivedCommands(frameState, commandStart, finalResolution);
456457
}
457458
};
458459

Source/Scene/Cesium3DTileBatchTable.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ define([
12091209
OPAQUE_AND_TRANSLUCENT : 2
12101210
};
12111211

1212-
Cesium3DTileBatchTable.prototype.addDerivedCommands = function(frameState, commandStart) {
1212+
Cesium3DTileBatchTable.prototype.addDerivedCommands = function(frameState, commandStart, finalResolution) {
12131213
var commandList = frameState.commandList;
12141214
var commandEnd = commandList.length;
12151215
var tile = this._content._tile;
@@ -1236,7 +1236,7 @@ define([
12361236
}
12371237

12381238
if (bivariateVisibilityTest) {
1239-
if (command.pass !== Pass.TRANSLUCENT) {
1239+
if (command.pass !== Pass.TRANSLUCENT && !finalResolution) {
12401240
if (!defined(derivedCommands.zback)) {
12411241
derivedCommands.zback = deriveZBackfaceCommand(derivedCommands.originalCommand);
12421242
}
@@ -1329,6 +1329,20 @@ define([
13291329
var rs = clone(derivedCommand.renderState, true);
13301330
rs.cull.enabled = true;
13311331
rs.cull.face = CullFace.FRONT;
1332+
// Back faces do not need to write color.
1333+
rs.colorMask = {
1334+
red : false,
1335+
green : false,
1336+
blue : false,
1337+
alpha : false
1338+
};
1339+
// Push back face depth away from the camera so it is less likely that back faces and front faces of the same tile
1340+
// intersect and overlap. This helps avoid flickering for very thin double-sided walls.
1341+
rs.polygonOffset = {
1342+
enabled : true,
1343+
factor : 5.0,
1344+
units : 5.0
1345+
};
13321346
derivedCommand.renderState = RenderState.fromCache(rs);
13331347
derivedCommand.castShadows = false;
13341348
derivedCommand.receiveShadows = false;

Source/Scene/Instanced3DModel3DTileContent.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ define([
517517
// If any commands were pushed, add derived commands
518518
var commandEnd = frameState.commandList.length;
519519
if ((commandStart < commandEnd) && frameState.passes.render) {
520-
this._batchTable.addDerivedCommands(frameState, commandStart);
520+
this._batchTable.addDerivedCommands(frameState, commandStart, false);
521521
}
522522
};
523523

Specs/Scene/Cesium3DTilesetSpec.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -2492,8 +2492,9 @@ defineSuite([
24922492

24932493
scene.renderForSpecs();
24942494

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

0 commit comments

Comments
 (0)