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

Handle multiple feature ID sets in ModelExperimental #10018

Merged
merged 42 commits into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
3ec8430
Default to empty array
ptrgags Jan 13, 2022
fe5e5a0
Make model feature tables always defined
ptrgags Jan 13, 2022
e9e1ba7
Start handling IDs without property tables
ptrgags Jan 14, 2022
2b83629
Reorganize feature IDs in ModelComponents
ptrgags Jan 18, 2022
58e6d7c
Add featureIdIndex and instanceFeatureIdIndex
ptrgags Jan 18, 2022
7cc3265
Update pipeline stages
ptrgags Jan 18, 2022
e22c111
Split out FeatureIdPipelineStage
ptrgags Jan 18, 2022
e24eb37
Reorganize shaders
ptrgags Jan 18, 2022
15586dd
Add [fv]sInput.featureIds to CustomShader parser
ptrgags Jan 18, 2022
05915ac
Add feature IDs to the custom shader
ptrgags Jan 19, 2022
b042d79
Update custom shader specs
ptrgags Jan 19, 2022
30ffa8a
Fix ModelExperimentalPrimitive specs
ptrgags Jan 19, 2022
993922a
Update SelectedFeatureIdPipelineStage
ptrgags Jan 19, 2022
e56ef99
Fix picking
ptrgags Jan 19, 2022
85bbb21
Fix shader compilation error in VS
ptrgags Jan 19, 2022
9c01d4f
Update photogrammetry classification sandcastle
ptrgags Jan 19, 2022
28cc68e
Start fixing unit tests
ptrgags Jan 20, 2022
0fea72c
Merge branch 'main' into multi-feature-ids
ptrgags Jan 21, 2022
dd69bc7
Make new unit tests for FeatureIdPipelineStage
ptrgags Jan 21, 2022
754843e
Update SelectedFeatureIdPipelineStage specs
ptrgags Jan 21, 2022
6fef5c6
Mark tests as WebGL
ptrgags Jan 21, 2022
33c86b6
Add note in changelog about feature IDs in CustomShader
ptrgags Jan 21, 2022
9c45411
Update I3dmLoader
ptrgags Jan 21, 2022
71d8513
Select different feature ID sets at runtime
ptrgags Jan 21, 2022
2c3c315
Fix race condition
ptrgags Jan 21, 2022
b59697e
Update style when feature ID index is changed
ptrgags Jan 24, 2022
d114a53
Update feature ID in other sandcastle
ptrgags Jan 24, 2022
e0839b4
Update Custom Shader guide
ptrgags Jan 24, 2022
b551bac
Update documentation
ptrgags Jan 24, 2022
a187a94
Merge branch 'main' into multi-feature-ids
ptrgags Jan 24, 2022
7f336aa
Fix unit tests
ptrgags Jan 24, 2022
2563438
Fix typo
ptrgags Jan 24, 2022
f95f680
Update CHANGES.md
ptrgags Jan 24, 2022
004af76
Fix prettier
ptrgags Jan 24, 2022
42263c2
Fix JSDoc formatting
ptrgags Jan 24, 2022
b10e308
Demonstrate using multiple feature ID sets
ptrgags Jan 25, 2022
33b4bab
Update documentation
ptrgags Jan 26, 2022
7323aa9
Handle filtering by pass type
ptrgags Jan 26, 2022
f6df243
applyStyle doesn't need an if guard
ptrgags Jan 26, 2022
b937b9c
Merge tag 'pre-let-const' into lets-merge2
ptrgags Jan 26, 2022
6ff5186
Merge tag 'post-let-const' into lets-merge2
ptrgags Jan 26, 2022
2a61e4f
Simplify multi-feature ID sandcastle
ptrgags Jan 27, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
var scene = viewer.scene;

var tileset = new Cesium.Cesium3DTileset({
url: Cesium.IonResource.fromAssetId(666297),
url: Cesium.IonResource.fromAssetId(775877),
});

var translation = new Cesium.Cartesian3(
Expand Down Expand Up @@ -107,8 +107,7 @@
"const float TOTAL_FEATURES = 12.0;",
"",
"void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material) {",
" // NOTE: This is exposing internal details of the shader. It would be better if this was added to fsInput somewhere...",
" float featureId = floor(texture2D(FEATURE_ID_TEXTURE, FEATURE_ID_TEXCOORD).FEATURE_ID_CHANNEL * 255.0 + 0.5);",
" float featureId = fsInput.featureIds.featureId_0;",
"",
" if (featureId == WINDOW || featureId == SKYLIGHT) {",
" material.alpha = 0.4;",
Expand Down Expand Up @@ -136,8 +135,7 @@
"const float TRAFFIC_LIGHT = 11.0;",
"",
"void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material) {",
" // NOTE: This is exposing internal details of the shader. It would be better if this was added to fsInput somewhere...",
" float featureId = floor(texture2D(FEATURE_ID_TEXTURE, FEATURE_ID_TEXCOORD).FEATURE_ID_CHANNEL * 255.0 + 0.5);",
" float featureId = fsInput.featureIds.featureId_0;",
"",
" if (featureId == CLOCK) {",
" // Shiny brass",
Expand Down Expand Up @@ -183,8 +181,7 @@
fragmentShaderText: [
"const float NOTHING_SELECTED = 12.0;",
"void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material) {",
" // NOTE: This is exposing internal details of the shader. It would be better if this was added to fsInput somewhere...",
" float featureId = floor(texture2D(FEATURE_ID_TEXTURE, FEATURE_ID_TEXCOORD).FEATURE_ID_CHANNEL * 255.0 + 0.5);",
" float featureId = fsInput.featureIds.featureId_0;",
"",
" if (u_selectedFeature < NOTHING_SELECTED && featureId == u_selectedFeature) {",
" material.specular = vec3(1.00, 0.85, 0.57);",
Expand All @@ -194,13 +191,68 @@
].join("\n"),
});

var multipleFeatureIdsShader = new Cesium.CustomShader({
uniforms: {
u_selectedFeature: {
type: Cesium.UniformType.FLOAT,
value: NOTHING_SELECTED,
},
},
lightingModel: Cesium.LightingModel.UNLIT,
fragmentShaderText: [
"const float IDS0_WALL = 2.0;",
"const float IDS1_STREET = 0.0;",
"const float IDS1_TOWER = 1.0;",
"const vec3 XZ_DIRECTION = normalize(vec3(1.0, 0.0, 1.0));",
"const vec3 RED = vec3(1.0, 0.0, 0.0);",
"const vec3 YELLOW = vec3(0.0, 0.8, 0.0);",
"const vec3 BLACK = vec3(0.0);",
"const vec3 WHITE = vec3(1.0);",
"float stripes(float x) {",
" return smoothstep(-0.4, 0.4, sin(2.0 * czm_pi * 10.0 * x));",
"}",
"",
"void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material) {",
" float featureId0 = fsInput.featureIds.featureId_0; // fine features",
" float featureId1 = fsInput.featureIds.featureId_1; // coarse features",
"",
" // since photogrammetry UVs are hard to work with, use",
" // model space coordinates instead to make stripes in different",
" // directions",
" vec3 position = fsInput.attributes.positionMC / 100.0;",
" float horizontalStripes = stripes(dot(position, XZ_DIRECTION));",
" float verticalStripes = stripes(position.y);",
"",
" // use both feature ID sets to determine where the features are",
" float isWall = float(featureId0 == IDS0_WALL);",
" float isStreet = float(featureId1 == IDS1_STREET);",
" float isTower = float(featureId1 == IDS1_TOWER);",
"",
" // composite several layers to make the final image",
" // layer 0: original photogrammetry",
" vec3 color = material.diffuse;",
" // layer 1: overlay green stripes over the street",
" color = mix(color, YELLOW, isStreet * horizontalStripes);",
" // layer 2: paint the wall with red and black stripes",
" vec3 wallColor = mix(BLACK, RED, horizontalStripes);",
" color = mix(color, wallColor, isWall);",
" // layer 3: paint the tower with black and white stripes",
" vec3 towerColor = mix(BLACK, WHITE, verticalStripes);",
" color = mix(color, towerColor, isTower);",
"",
" material.diffuse = color;",
"}",
].join("\n"),
});

// Demo Functions =====================================================================

function defaults() {
tileset.style = undefined;
tileset.customShader = unlitShader;
tileset.colorBlendMode = Cesium.Cesium3DTileColorBlendMode.HIGHLIGHT;
tileset.colorBlendAmount = 0.5;
tileset.featureIdIndex = 0;
}

var showPhotogrammetry = defaults;
Expand All @@ -211,6 +263,12 @@
tileset.colorBlendMode = Cesium.Cesium3DTileColorBlendMode.MIX;
}

function showAlternativeClassification() {
showClassification();
// This dataset has a second feature ID texture.
tileset.featureIdIndex = 1;
}

function translucentWindows() {
defaults();
tileset.customShader = translucentWindowsShader;
Expand All @@ -226,6 +284,11 @@
tileset.customShader = selectFeatureShader;
}

function multipleFeatureIds() {
defaults();
tileset.customShader = multipleFeatureIdsShader;
}

// Pick Handlers ======================================================================

// HTML overlay for showing feature name on mouseover
Expand Down Expand Up @@ -304,6 +367,10 @@
text: "Show Classification",
onselect: showClassification,
},
{
text: "Show Alternative Classification",
onselect: showAlternativeClassification,
},
{
text: "Translucent Windows",
onselect: translucentWindows,
Expand All @@ -316,6 +383,10 @@
text: "Golden Touch",
onselect: goldenTouch,
},
{
text: "Multiple Feature ID Sets",
onselect: multipleFeatureIds,
},
];
Sandcastle.addToolbarMenu(demos);

Expand Down
3 changes: 1 addition & 2 deletions Apps/Sandcastle/gallery/3D Tiles Next S2 Globe.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@
fragmentShaderText: [
"void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material)",
"{",
" // NOTE: this is exposing internal details of the shader.",
" float featureId = floor(texture2D(FEATURE_ID_TEXTURE, FEATURE_ID_TEXCOORD).FEATURE_ID_CHANNEL * 255.0 + 0.5);",
" float featureId = fsInput.featureIds.featureId_0;",
" // Use cartesian coordinates but scale to be roughly [-1, 1]",
" vec3 positionWC = fsInput.attributes.positionWC / 6.3e6;",
" if (featureId == 60.0)",
Expand Down
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

##### Additions :tada:

- Feature IDs for styling and picking in `ModelExperimental` can now be selected via `(tileset|model).featureIdIndex` and `(tileset|model).instanceFeatureIdIndex`. [#10018](https://github.com/CesiumGS/cesium/pull/10018)
- Added support for all types of feature IDs in `CustomShader`. [#10018](https://github.com/CesiumGS/cesium/pull/10018)
- Added getters `Cesium3DTileFeature.featureId` and `ModelFeature.featureId` so the feature ID or batch ID can be accessed from a picked feature. [#10022](https://github.com/CesiumGS/cesium/pull/10022)
- Added `I3dmLoader` to transcode .i3dm to `ModelExperimental`. [#9968](https://github.com/CesiumGS/cesium/pull/9968)
- Added `PntsLoader` to transcode .pnts to `ModelExperimental`. [#9978](https://github.com/CesiumGS/cesium/pull/9978)
Expand Down
21 changes: 21 additions & 0 deletions Source/Scene/Cesium3DTileset.js
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,27 @@ function Cesium3DTileset(options) {
ExperimentalFeatures.enableModelExperimental
);

/**
* The index into the list of primitive feature IDs used for picking and
* styling. For EXT_feature_metadata, feature ID attributes are listed before
* feature ID textures. If both per-primitive and per-instance feature IDs are
* present, the instance feature IDs take priority.
*
* @type {Number}
* @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.
*/
this.featureIdIndex = defaultValue(options.featureIdIndex, 0);

/**
* The index into the list of instance feature IDs used for picking and
* styling. If both per-primitive and per-instance feature IDs are present,
* the instance feature IDs take priority.
*
* @type {Number}
* @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.
*/
this.instanceFeatureIdIndex = defaultValue(options.instanceFeatureIdIndex, 0);

ptrgags marked this conversation as resolved.
Show resolved Hide resolved
this._schemaLoader = undefined;

var that = this;
Expand Down
Loading