Skip to content

Commit

Permalink
Merge pull request #9398 from CesiumGS/clamp-vector-tiles
Browse files Browse the repository at this point in the history
Add clamped vector polylines
  • Loading branch information
lilleyse authored Mar 12, 2021
2 parents 37d6d11 + 2736e09 commit 2315c51
Show file tree
Hide file tree
Showing 15 changed files with 1,710 additions and 73 deletions.
51 changes: 51 additions & 0 deletions Source/Core/decodeVectorPolylinePositions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import AttributeCompression from "./AttributeCompression.js";
import Cartesian3 from "./Cartesian3.js";
import Cartographic from "./Cartographic.js";
import CesiumMath from "./Math.js";

var maxShort = 32767;

var scratchBVCartographic = new Cartographic();
var scratchEncodedPosition = new Cartesian3();

function decodeVectorPolylinePositions(
positions,
rectangle,
minimumHeight,
maximumHeight,
ellipsoid
) {
var positionsLength = positions.length / 3;
var uBuffer = positions.subarray(0, positionsLength);
var vBuffer = positions.subarray(positionsLength, 2 * positionsLength);
var heightBuffer = positions.subarray(
2 * positionsLength,
3 * positionsLength
);
AttributeCompression.zigZagDeltaDecode(uBuffer, vBuffer, heightBuffer);

var decoded = new Float64Array(positions.length);
for (var i = 0; i < positionsLength; ++i) {
var u = uBuffer[i];
var v = vBuffer[i];
var h = heightBuffer[i];

var lon = CesiumMath.lerp(rectangle.west, rectangle.east, u / maxShort);
var lat = CesiumMath.lerp(rectangle.south, rectangle.north, v / maxShort);
var alt = CesiumMath.lerp(minimumHeight, maximumHeight, h / maxShort);

var cartographic = Cartographic.fromRadians(
lon,
lat,
alt,
scratchBVCartographic
);
var decodedPosition = ellipsoid.cartographicToCartesian(
cartographic,
scratchEncodedPosition
);
Cartesian3.pack(decodedPosition, decoded, i * 3);
}
return decoded;
}
export default decodeVectorPolylinePositions;
17 changes: 11 additions & 6 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.vectorClassificationOnly
? 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 All @@ -193,7 +197,8 @@ function getFragmentShaderCallback(content) {
}
var callback = batchTable.getFragmentShaderCallback(
handleTranslucent,
content._diffuseAttributeOrUniformName[programId]
content._diffuseAttributeOrUniformName[programId],
false
);
return defined(callback) ? callback(fs) : fs;
};
Expand Down Expand Up @@ -348,7 +353,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 +408,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 +576,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
22 changes: 18 additions & 4 deletions Source/Scene/Cesium3DTileBatchTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,8 @@ function modifyDiffuse(source, diffuseAttributeOrUniformName, applyHighlight) {

Cesium3DTileBatchTable.prototype.getFragmentShaderCallback = function (
handleTranslucent,
diffuseAttributeOrUniformName
diffuseAttributeOrUniformName,
hasPremultipliedAlpha
) {
if (this.featuresLength === 0) {
return;
Expand All @@ -1210,8 +1211,13 @@ Cesium3DTileBatchTable.prototype.getFragmentShaderCallback = function (
"varying vec4 tile_featureColor; \n" +
"void main() \n" +
"{ \n" +
" tile_color(tile_featureColor); \n" +
"}";
" tile_color(tile_featureColor); \n";

if (hasPremultipliedAlpha) {
source += " gl_FragColor.rgb *= gl_FragColor.a; \n";
}

source += "}";
} else {
if (handleTranslucent) {
source += "uniform bool tile_translucentCommand; \n";
Expand Down Expand Up @@ -1246,7 +1252,13 @@ Cesium3DTileBatchTable.prototype.getFragmentShaderCallback = function (
" } \n";
}

source += " tile_color(featureProperties); \n" + "} \n";
source += " tile_color(featureProperties); \n";

if (hasPremultipliedAlpha) {
source += " gl_FragColor.rgb *= gl_FragColor.a; \n";
}

source += "} \n";
}
return source;
};
Expand All @@ -1268,6 +1280,7 @@ Cesium3DTileBatchTable.prototype.getClassificationFragmentShaderCallback = funct
"{ \n" +
" tile_main(); \n" +
" gl_FragColor = tile_featureColor; \n" +
" gl_FragColor.rgb *= gl_FragColor.a; \n" +
"}";
} else {
source +=
Expand All @@ -1282,6 +1295,7 @@ Cesium3DTileBatchTable.prototype.getClassificationFragmentShaderCallback = funct
" discard; \n" +
" } \n" +
" gl_FragColor = featureProperties; \n" +
" gl_FragColor.rgb *= gl_FragColor.a; \n" +
"} \n";
}
return source;
Expand Down
31 changes: 31 additions & 0 deletions Source/Scene/Cesium3DTileset.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ import TileOrientedBoundingBox from "./TileOrientedBoundingBox.js";
* @param {Cartesian3[]} [options.sphericalHarmonicCoefficients] The third order spherical harmonic coefficients used for the diffuse color of image-based lighting.
* @param {String} [options.specularEnvironmentMaps] A URL to a KTX file that contains a cube map of the specular lighting and the convoluted specular mipmaps.
* @param {Boolean} [options.backFaceCulling=true] Whether to cull back-facing geometry. When true, back face culling is determined by the glTF material's doubleSided property; when false, back face culling is disabled.
* @param {Boolean} [options.vectorClassificationOnly=false] Indicates that only the tileset's vector tiles should be used for classification.
* @param {String} [options.debugHeatmapTilePropertyName] The tile variable to colorize as a heatmap. All rendered tiles will be colorized relative to each other's specified variable value.
* @param {Boolean} [options.debugFreezeFrame=false] For debugging only. Determines if only the tiles from last frame should be used for rendering.
* @param {Boolean} [options.debugColorizeTiles=false] For debugging only. When true, assigns a random color to each tile.
Expand Down Expand Up @@ -273,6 +274,11 @@ function Cesium3DTileset(options) {
this._clippingPlanesOriginMatrix = undefined; // Combines the above with any run-time transforms.
this._clippingPlanesOriginMatrixDirty = true;

this._vectorClassificationOnly = defaultValue(
options.vectorClassificationOnly,
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 @@ -898,6 +904,15 @@ function Cesium3DTileset(options) {
*/
this.debugShowUrl = defaultValue(options.debugShowUrl, false);

/**
* Function for examining vector lines as they are being streamed.
*
* @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
*
* @type {Function}
*/
this.examineVectorLinesFunction = undefined;

var that = this;
var resource;
when(options.url)
Expand Down Expand Up @@ -1654,6 +1669,22 @@ Object.defineProperties(Cesium3DTileset.prototype, {
Cartesian2.clone(value, this._imageBasedLightingFactor);
},
},

/**
* Indicates that only the tileset's vector tiles should be used for classification.
*
* @memberof Cesium3DTileset.prototype
*
* @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
*
* @type {Boolean}
* @default false
*/
vectorClassificationOnly: {
get: function () {
return this._vectorClassificationOnly;
},
},
});

/**
Expand Down
6 changes: 4 additions & 2 deletions Source/Scene/ModelInstanceCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,8 @@ function getFragmentShaderCallback(collection) {
);
fs = batchTable.getFragmentShaderCallback(
true,
diffuseAttributeOrUniformName
diffuseAttributeOrUniformName,
false
)(fs);
} else {
fs = "varying vec4 v_pickColor;\n" + fs;
Expand Down Expand Up @@ -536,7 +537,8 @@ function getFragmentShaderNonInstancedCallback(collection) {
);
fs = batchTable.getFragmentShaderCallback(
true,
diffuseAttributeOrUniformName
diffuseAttributeOrUniformName,
false
)(fs);
} else {
fs = "uniform vec4 czm_pickColor;\n" + fs;
Expand Down
3 changes: 2 additions & 1 deletion Source/Scene/PointCloud3DTileContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ function getFragmentShaderLoaded(content) {
if (defined(content._batchTable)) {
return content._batchTable.getFragmentShaderCallback(
false,
undefined
undefined,
false
)(fs);
}
return "uniform vec4 czm_pickColor;\n" + fs;
Expand Down
Loading

0 comments on commit 2315c51

Please sign in to comment.