Skip to content

Commit c6fde0d

Browse files
authored
Merge pull request #8470 from AnalyticalGraphicsInc/terrain-back-face-culling
Looks good to me, thanks @lilleyse
2 parents 96dcc60 + 4c2478b commit c6fde0d

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

CHANGES.md

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ Change Log
99
* Fixed primitive culling when below the ellipsoid but above terrain. [#8398](https://github.com/AnalyticalGraphicsInc/cesium/pull/8398)
1010
* Improved the translucency calculation for the Water material type. [#8455](https://github.com/AnalyticalGraphicsInc/cesium/pull/8455)
1111

12+
##### Additions :tada:
13+
* Added `Globe.backFaceCulling` to support viewing terrain from below the surface. [#8470](https://github.com/AnalyticalGraphicsInc/cesium/pull/8470)
14+
1215
### 1.64.0 - 2019-12-02
1316

1417
##### Fixes :wrench:

Source/Scene/Globe.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,14 @@ import TileSelectionResult from './TileSelectionResult.js';
250250
*/
251251
this.atmosphereBrightnessShift = 0.0;
252252

253+
/**
254+
* Whether to cull back-facing terrain. Set this to false when viewing terrain from below the surface.
255+
*
256+
* @type {Boolean}
257+
* @default true
258+
*/
259+
this.backFaceCulling = true;
260+
253261
this._oceanNormalMap = undefined;
254262
this._zoomedOutOceanSpecularIntensity = undefined;
255263
}
@@ -739,7 +747,7 @@ import TileSelectionResult from './TileSelectionResult.js';
739747
tileProvider.saturationShift = this.atmosphereSaturationShift;
740748
tileProvider.brightnessShift = this.atmosphereBrightnessShift;
741749
tileProvider.fillHighlightColor = this.fillHighlightColor;
742-
750+
tileProvider.backFaceCulling = this.backFaceCulling;
743751
surface.beginFrame(frameState);
744752
}
745753
};

Source/Scene/GlobeSurfaceTileProvider.js

+17-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Cartesian2 from '../Core/Cartesian2.js';
44
import Cartesian3 from '../Core/Cartesian3.js';
55
import Cartesian4 from '../Core/Cartesian4.js';
66
import Cartographic from '../Core/Cartographic.js';
7+
import clone from '../Core/clone.js';
78
import Color from '../Core/Color.js';
89
import ColorGeometryInstanceAttribute from '../Core/ColorGeometryInstanceAttribute.js';
910
import combine from '../Core/combine.js';
@@ -100,13 +101,17 @@ import TileSelectionResult from './TileSelectionResult.js';
100101
this.saturationShift = 0.0;
101102
this.brightnessShift = 0.0;
102103

104+
this.backFaceCulling = true;
105+
103106
this._quadtree = undefined;
104107
this._terrainProvider = options.terrainProvider;
105108
this._imageryLayers = options.imageryLayers;
106109
this._surfaceShaderSet = options.surfaceShaderSet;
107110

108111
this._renderState = undefined;
109112
this._blendRenderState = undefined;
113+
this._disableCullingRenderState = undefined;
114+
this._disableCullingBlendRenderState = undefined;
110115

111116
this._errorEvent = new Event();
112117

@@ -405,6 +410,16 @@ import TileSelectionResult from './TileSelectionResult.js';
405410
});
406411
}
407412

413+
if (!this.backFaceCulling && !defined(this._disableCullingRenderState)) {
414+
var rs = clone(this._renderState, true);
415+
rs.cull.enabled = false;
416+
this._disableCullingRenderState = RenderState.fromCache(rs);
417+
418+
rs = clone(this._blendRenderState, true);
419+
rs.cull.enabled = false;
420+
this._disableCullingBlendRenderState = RenderState.fromCache(rs);
421+
}
422+
408423
// If this frame has a mix of loaded and fill tiles, we need to propagate
409424
// loaded heights to the fill tiles.
410425
if (this._hasFillTilesThisFrame && this._hasLoadedTilesThisFrame) {
@@ -1652,8 +1667,8 @@ import TileSelectionResult from './TileSelectionResult.js';
16521667
var imageryIndex = 0;
16531668
var imageryLen = tileImageryCollection.length;
16541669

1655-
var firstPassRenderState = tileProvider._renderState;
1656-
var otherPassesRenderState = tileProvider._blendRenderState;
1670+
var firstPassRenderState = tileProvider.backFaceCulling ? tileProvider._renderState : tileProvider._disableCullingRenderState;
1671+
var otherPassesRenderState = tileProvider.backFaceCulling ? tileProvider._blendRenderState : tileProvider._disableCullingBlendRenderState;
16571672
var renderState = firstPassRenderState;
16581673

16591674
var initialColor = tileProvider._firstPassInitialColor;

Specs/Scene/GlobeSpec.js

+15
Original file line numberDiff line numberDiff line change
@@ -259,4 +259,19 @@ describe('Scene/Globe', function() {
259259
});
260260
});
261261
});
262+
263+
it('applies back face culling', function() {
264+
scene.camera.setView({ destination : new Rectangle(0.0001, 0.0001, 0.0025, 0.0025) });
265+
266+
return updateUntilDone(globe).then(function() {
267+
globe.backFaceCulling = true;
268+
scene.render();
269+
var command = scene.frameState.commandList[0];
270+
expect(command.renderState.cull.enabled).toBe(true);
271+
globe.backFaceCulling = false;
272+
scene.render();
273+
command = scene.frameState.commandList[0];
274+
expect(command.renderState.cull.enabled).toBe(false);
275+
});
276+
});
262277
}, 'WebGL');

0 commit comments

Comments
 (0)