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 `TranslucentTileClassification` for classifying translucent 3D Tiles.

### 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
14 changes: 9 additions & 5 deletions Source/Scene/Batched3DModel3DTileContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ function Batched3DModel3DTileContent(
this._batchTable = undefined;
this._features = undefined;

this._classificationType = tileset.noClassificationModels
? undefined
: tileset.classificationType;

// Populate from gltf when available
this._batchIdAttributeName = undefined;
this._diffuseAttributeOrUniformName = {};
Expand Down Expand Up @@ -161,7 +165,7 @@ function getBatchIdAttributeName(gltf) {
function getVertexShaderCallback(content) {
return function (vs, programId) {
var batchTable = content._batchTable;
var handleTranslucent = !defined(content._tileset.classificationType);
var handleTranslucent = !defined(content._classificationType);

var gltf = content._model.gltf;
if (defined(gltf)) {
Expand All @@ -183,7 +187,7 @@ function getVertexShaderCallback(content) {
function getFragmentShaderCallback(content) {
return function (fs, programId) {
var batchTable = content._batchTable;
var handleTranslucent = !defined(content._tileset.classificationType);
var handleTranslucent = !defined(content._classificationType);

var gltf = content._model.gltf;
if (defined(gltf)) {
Expand Down Expand Up @@ -348,7 +352,7 @@ function initialize(content, arrayBuffer, byteOffset) {
}

var colorChangedCallback;
if (defined(tileset.classificationType)) {
if (defined(content._classificationType)) {
colorChangedCallback = createColorChangedCallback(content);
}

Expand Down Expand Up @@ -403,7 +407,7 @@ function initialize(content, arrayBuffer, byteOffset) {
new Matrix4()
);

if (!defined(tileset.classificationType)) {
if (!defined(content._classificationType)) {
// PERFORMANCE_IDEA: patch the shader on demand, e.g., the first time show/color changes.
// The pick shader still needs to be patched.
content._model = new Model({
Expand Down Expand Up @@ -571,7 +575,7 @@ Batched3DModel3DTileContent.prototype.update = function (tileset, frameState) {
if (
commandStart < commandEnd &&
(frameState.passes.render || frameState.passes.pick) &&
!defined(tileset.classificationType)
!defined(this._classificationType)
) {
this._batchTable.addDerivedCommands(frameState, commandStart);
}
Expand Down
10 changes: 9 additions & 1 deletion 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 @@ -1615,7 +1616,14 @@ Cesium3DTile.prototype.update = function (tileset, frameState, passOptions) {
updateClippingPlanes(this, tileset);
applyDebugSettings(this, tileset, frameState, passOptions);
updateContent(this, tileset, frameState);
this._commandsLength = frameState.commandList.length - initCommandLength;
var commandsLength = (this._commandsLength =
frameState.commandList.length - initCommandLength);

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

this.clippingPlanesDirty = false; // reset after content update
};
Expand Down
20 changes: 20 additions & 0 deletions Source/Scene/Cesium3DTileset.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ import TileOrientedBoundingBox from "./TileOrientedBoundingBox.js";
* @param {Boolean} [options.debugShowRenderingStatistics=false] For debugging only. When true, draws labels to indicate the number of commands, points, triangles and features for each tile.
* @param {Boolean} [options.debugShowMemoryUsage=false] For debugging only. When true, draws labels to indicate the texture and geometry memory in megabytes used by each tile.
* @param {Boolean} [options.debugShowUrl=false] For debugging only. When true, draws labels to indicate the url of each tile.
* @param {Boolean} [options.noClassificationModels=false] Do not use b3dms for classification.
ebogo1 marked this conversation as resolved.
Show resolved Hide resolved
*
* @exception {DeveloperError} The tileset must be 3D Tiles version 0.0 or 1.0.
*
Expand Down Expand Up @@ -274,6 +275,11 @@ function Cesium3DTileset(options) {
this._clippingPlanesOriginMatrix = undefined; // Combines the above with any run-time transforms.
this._clippingPlanesOriginMatrixDirty = true;

this._noClassificationModels = defaultValue(
options.noClassificationModels,
false
);

/**
* Preload tiles when <code>tileset.show</code> is <code>false</code>. Loads tiles as if the tileset is visible but does not render them.
*
Expand Down Expand Up @@ -1662,6 +1668,20 @@ Object.defineProperties(Cesium3DTileset.prototype, {
Cartesian2.clone(value, this._imageBasedLightingFactor);
},
},

/**
* Indicates that the tileset's b3dms should be used for classification.
*
* @memberof Cesium3DTileset.prototype
*
* @type {Boolean}
* @default false
*/
noClassificationModels: {
get: function () {
return this._noClassificationModels;
},
},
});

/**
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 hasClassificationOnTranslucent =
frustumCommands.indices[Pass.CESIUM_3D_TILE_CLASSIFICATION] > 0;
if (
hasClassificationOnTranslucent &&
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