Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add translucent tile classification #9399

Merged
merged 14 commits into from
Mar 9, 2021
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
##### Additions :tada:

- Added `Cesium3DTileset.pickPrimitive` for rendering primitives instead of the tileset during the pick pass.
- Added support for for drawing ground primitives on translucent 3D Tiles. [#9399](https://github.com/CesiumGS/cesium/pull/9399)

### 1.79.1 - 2021-03-01

Expand Down
25 changes: 25 additions & 0 deletions Source/Renderer/DrawCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ function DrawCommand(options) {
this._pickId = options.pickId;
this._pickOnly = defaultValue(options.pickOnly, false);

this._depthForTranslucentClassification = defaultValue(
options.depthForTranslucentClassification,
false
);

this.dirty = true;
this.lastDirtyTime = 0;

Expand Down Expand Up @@ -513,6 +518,24 @@ Object.defineProperties(DrawCommand.prototype, {
}
},
},
/**
* Whether this command should be derived to draw depth for classification of translucent primitives.
*
* @memberof DrawCommand.prototype
* @type {Boolean}
* @default false
*/
depthForTranslucentClassification: {
get: function () {
return this._depthForTranslucentClassification;
},
set: function (value) {
if (this._depthForTranslucentClassification !== value) {
this._depthForTranslucentClassification = value;
this.dirty = true;
}
},
},
});

/**
Expand Down Expand Up @@ -549,6 +572,8 @@ DrawCommand.shallowClone = function (command, result) {
result._receiveShadows = command._receiveShadows;
result._pickId = command._pickId;
result._pickOnly = command._pickOnly;
result._depthForTranslucentClassification =
command._depthForTranslucentClassification;

result.dirty = true;
result.lastDirtyTime = 0;
Expand Down
15 changes: 13 additions & 2 deletions Source/Scene/Cesium3DTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import SceneMode from "./SceneMode.js";
import TileBoundingRegion from "./TileBoundingRegion.js";
import TileBoundingSphere from "./TileBoundingSphere.js";
import TileOrientedBoundingBox from "./TileOrientedBoundingBox.js";
import Pass from "../Renderer/Pass.js";

/**
* A tile in a {@link Cesium3DTileset}. When a tile is first created, its content is not loaded;
Expand Down Expand Up @@ -1611,11 +1612,21 @@ function updateClippingPlanes(tile, tileset) {
* @private
*/
Cesium3DTile.prototype.update = function (tileset, frameState, passOptions) {
var initCommandLength = frameState.commandList.length;
var commandStart = frameState.commandList.length;

updateClippingPlanes(this, tileset);
applyDebugSettings(this, tileset, frameState, passOptions);
updateContent(this, tileset, frameState);
this._commandsLength = frameState.commandList.length - initCommandLength;

var commandEnd = frameState.commandList.length;
var commandsLength = commandEnd - commandStart;
this._commandsLength = commandsLength;

for (var i = 0; i < commandsLength; ++i) {
var command = frameState.commandList[commandStart + i];
var translucent = command.pass === Pass.TRANSLUCENT;
command.depthForTranslucentClassification = translucent;
}

this.clippingPlanesDirty = false; // reset after content update
};
Expand Down
37 changes: 37 additions & 0 deletions Source/Scene/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -2658,6 +2658,28 @@ function executeCommands(scene, passState) {
invertClassification
);

// Classification for translucent 3D Tiles
var has3DTilesClassificationCommands =
frustumCommands.indices[Pass.CESIUM_3D_TILE_CLASSIFICATION] > 0;
if (
has3DTilesClassificationCommands &&
view.translucentTileClassification.isSupported()
) {
view.translucentTileClassification.executeTranslucentCommands(
scene,
executeCommand,
passState,
commands,
globeDepth.framebuffer
);
view.translucentTileClassification.executeClassificationCommands(
scene,
executeCommand,
passState,
frustumCommands
);
}

if (
context.depthTexture &&
scene.useDepthPicking &&
Expand Down Expand Up @@ -3439,6 +3461,13 @@ function updateAndClearFramebuffers(scene, passState, clearColor) {
environmentState.useOIT = oit.isSupported();
}

if (
useGlobeDepthFramebuffer &&
view.translucentTileClassification.isSupported()
) {
view.translucentTileClassification.clear(context, passState);
}

var postProcess = scene.postProcessStages;
var usePostProcess = (environmentState.usePostProcess =
!picking &&
Expand Down Expand Up @@ -3545,6 +3574,14 @@ Scene.prototype.resolveFramebuffers = function (passState) {
view.oit.execute(context, passState);
}

var translucentTileClassification = view.translucentTileClassification;
if (
translucentTileClassification.hasTranslucentDepth &&
translucentTileClassification.isSupported()
) {
translucentTileClassification.execute(this, passState);
}

if (usePostProcess) {
var inputFramebuffer = sceneFramebuffer;
if (useGlobeDepthFramebuffer && !useOIT) {
Expand Down
Loading