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 clamped vector polylines #9398

Merged
merged 24 commits into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
071a6a8
add diff files
ebogo1 Mar 1, 2021
a2ac850
renaming, remove unused property
ebogo1 Mar 3, 2021
d16882a
add experimental option to constructor
ebogo1 Mar 3, 2021
58b5789
add missing line
ebogo1 Mar 3, 2021
e07921d
improve docs
ebogo1 Mar 3, 2021
0351120
Premultiplied alpha to fix colors for globe translucency
lilleyse Mar 4, 2021
a7b1859
minor fixes
ebogo1 Mar 5, 2021
902f668
add classificationType changes
ebogo1 Mar 8, 2021
4668ca6
add back Cesium3DTileset properties
ebogo1 Mar 9, 2021
0133ec3
Merge branch 'master' into clamp-vector-tiles
lilleyse Mar 9, 2021
1ac71d1
Revert "Premultiplied alpha to fix colors for globe translucency"
lilleyse Mar 9, 2021
7ada1a7
Premultiplied alpha to fix colors for globe translucency
lilleyse Mar 9, 2021
9849b6c
first pass of specs
ebogo1 Mar 10, 2021
2794dbc
Merge branch 'clamp-vector-tiles' of github.com:CesiumGS/cesium into …
ebogo1 Mar 10, 2021
6e4d7ef
clamped polyline specs
ebogo1 Mar 11, 2021
da38f78
fix clamped vector polylines not drawing when camera is inside volume…
likangning93 Mar 12, 2021
6602501
use bounding volume that covers whole shadow volume for draw commands…
likangning93 Mar 12, 2021
6245716
fix specs
ebogo1 Mar 12, 2021
eef86b4
remove unused test tileset
ebogo1 Mar 12, 2021
6b90864
remove files from last commit
ebogo1 Mar 12, 2021
418c96a
Merge branch 'master' into clamp-vector-tiles
lilleyse Mar 12, 2021
2fcc409
Renamed noClassificationModels to vectorClassificationOnly
lilleyse Mar 12, 2021
4fd49c5
Remove tileset.minimumMaximumVectorHeights
lilleyse Mar 12, 2021
2736e09
Attempt to add @experimental tag to examineVectorLinesFunction
lilleyse Mar 12, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
lilleyse marked this conversation as resolved.
Show resolved Hide resolved

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;
},
},
lilleyse marked this conversation as resolved.
Show resolved Hide resolved
});

/**
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