Skip to content

Commit

Permalink
Merge pull request #10087 from CesiumGS/feature-id-changes
Browse files Browse the repository at this point in the history
Feature ID changes from EXT_mesh_features spec updates
  • Loading branch information
lilleyse authored Feb 11, 2022
2 parents bcceff1 + 6e61c1a commit 24f04d7
Show file tree
Hide file tree
Showing 34 changed files with 893 additions and 212 deletions.
8 changes: 3 additions & 5 deletions Apps/SampleData/models/BoxInstanced/BoxInstanced.gltf
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,18 @@
"TRANSLATION": 3,
"ROTATION": 4,
"SCALE": 5,
"FEATURE_ID_0": 6
"_FEATURE_ID_0": 6
}
},
"EXT_mesh_features": {
"propertyTables": [
0,
1
],
"featureIds": [
{
"propertyTable": 0,
"offset": 0,
"repeat": 1
},
{
"propertyTable": 1,
"attribute": 0
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@
lightingModel: Cesium.LightingModel.UNLIT,
isTranslucent: true,
fragmentShaderText: `
const float WINDOW = 0.0;
const float SKYLIGHT = 4.0;
const float TOTAL_FEATURES = 12.0;
const int WINDOW = 0;
const int SKYLIGHT = 4;
const int TOTAL_FEATURES = 12;
void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material) {
float featureId = fsInput.featureIds.featureId_0;
int featureId = fsInput.featureIds.featureId_0;
if (featureId == WINDOW || featureId == SKYLIGHT) {
material.alpha = 0.4;
Expand All @@ -120,21 +120,21 @@
lightingModel: Cesium.LightingModel.PBR,
isTranslucent: true,
fragmentShaderText: `
const float WINDOW = 0.0;
const float FRAME = 1.0;
const float WALL = 2.0;
const float ROOF = 3.0;
const float SKYLIGHT = 4.0;
const float AIR_CONDITIONER_WHITE = 5.0;
const float AIR_CONDITIONER_BLACK = 6.0;
const float AIR_CONDITIONER_TALL = 7.0;
const float CLOCK = 8.0;
const float PILLARS = 9.0;
const float STREET_LIGHT = 10.0;
const float TRAFFIC_LIGHT = 11.0;
const int WINDOW = 0;
const int FRAME = 1;
const int WALL = 2;
const int ROOF = 3;
const int SKYLIGHT = 4;
const int AIR_CONDITIONER_WHITE = 5;
const int AIR_CONDITIONER_BLACK = 6;
const int AIR_CONDITIONER_TALL = 7;
const int CLOCK = 8;
const int PILLARS = 9;
const int STREET_LIGHT = 10;
const int TRAFFIC_LIGHT = 11;
void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material) {
float featureId = fsInput.featureIds.featureId_0;
int featureId = fsInput.featureIds.featureId_0;
if (featureId == CLOCK) {
// Shiny brass
Expand Down Expand Up @@ -172,15 +172,15 @@
const selectFeatureShader = new Cesium.CustomShader({
uniforms: {
u_selectedFeature: {
type: Cesium.UniformType.FLOAT,
type: Cesium.UniformType.INT,
value: NOTHING_SELECTED,
},
},
lightingModel: Cesium.LightingModel.PBR,
fragmentShaderText: `
const float NOTHING_SELECTED = 12.0;
const int NOTHING_SELECTED = 12;
void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material) {
float featureId = fsInput.featureIds.featureId_0;
int featureId = fsInput.featureIds.featureId_0;
if (u_selectedFeature < NOTHING_SELECTED && featureId == u_selectedFeature) {
material.specular = vec3(1.00, 0.85, 0.57);
Expand All @@ -199,16 +199,16 @@
},
lightingModel: Cesium.LightingModel.UNLIT,
fragmentShaderText: `
const float IDS0_WINDOW = 0.0;
const float IDS1_FACADE = 2.0;
const float IDS1_ROOF = 3.0;
const int IDS0_WINDOW = 0;
const int IDS1_FACADE = 2;
const int IDS1_ROOF = 3;
const vec3 PURPLE = vec3(0.5, 0.0, 1.0);
const vec3 YELLOW = vec3(1.0, 1.0, 0.0);
const vec3 NO_TINT = vec3(1.0);
void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material) {
float featureId0 = fsInput.featureIds.featureId_0; // fine features
float featureId1 = fsInput.featureIds.featureId_1; // coarse features
int featureId0 = fsInput.featureIds.featureId_0; // fine features
int featureId1 = fsInput.featureIds.featureId_1; // coarse features
// use both feature ID sets to determine where the features are
float isWindow = float(featureId0 == IDS0_WINDOW);
Expand Down
4 changes: 2 additions & 2 deletions Apps/Sandcastle/gallery/3D Tiles Next S2 Globe.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@
fragmentShaderText: `
void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material)
{
float featureId = fsInput.featureIds.featureId_0;
int 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)
if (featureId == 60)
{
// Something like FM synthesis to make irregularly spaced waves
float wave = sin(14.0 * positionWC.z - u_time);
Expand Down
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Added support for shadows in `ModelExperimental`. [#10077](https://github.com/CesiumGS/cesium/pull/10077)
- Added the ability to load implicit tiling subtree files from JSON. [#10086](https://github.com/CesiumGS/cesium/pull/10086)
- Added support for subtree metadata in tilesets with implicit tiling. [#10093](https://github.com/CesiumGS/cesium/pull/10093)
- Updated Feature ID parsing to match changes to the EXT_mesh_features specification. [#10087](https://github.com/CesiumGS/cesium/pull/10087)

##### Fixes :wrench:

Expand Down
33 changes: 22 additions & 11 deletions Documentation/CustomShaderGuide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,13 @@ This struct is dynamically generated to gather all the various feature IDs into
a single collection, regardless of whether the value came from an attribute,
texture or varying.

Feature IDs are represented as a GLSL `int`, though in WebGL 1 this has a couple
limitations:

- Above `2^24`, values may have a loss of precision since WebGL 1 implements
`highp int` as a floating point value.
- Ideally the type would be `uint` but this is not available until WebGL 2

### 3D Tiles 1.0 Batch IDs

In 3D Tiles 1.0, the same concept of identifying features within a primitive
Expand Down Expand Up @@ -303,28 +310,29 @@ For example, suppose we had a glTF primitive with the following feature IDs:
"EXT_mesh_gpu_instancing": {
"attributes": {
"TRANSLATION": 3,
"FEATURE_ID_0": 4
"_FEATURE_ID_0": 4
}
},
"EXT_mesh_features": {
"propertyTables": [0, 1],
"featureIds": [
{
// Feature ID attribute from implicit range
//
// Vertex Shader: vsInput.featureIds.instanceFeatureId_0
// Fragment Shader: fsInput.featureIds.instanceFeatureId_0
"propertyTable": 0,
"offset": 0,
"repeat": 1
},
{
// Feature ID attribute. This corresponds to FEATURE_ID_0 from the
// Feature ID attribute. This corresponds to _FEATURE_ID_0 from the
// instancing extension above. Note that this is
// labeled as instanceFeatureId_1 since it is the second feature ID
// set in the featureIds array
//
// Vertex Shader: vsInput.featureIds.instanceFeatureId_1
// Fragment Shader: fsInput.featureIds.instanceFeatureId_1
"propertyTable": 1,
"attribute": 0
}
]
Expand All @@ -338,18 +346,18 @@ For example, suppose we had a glTF primitive with the following feature IDs:
{
"attributes": {
"POSITION": 0,
"FEATURE_ID_0": 1,
"FEATURE_ID_1": 2
"_FEATURE_ID_0": 1,
"_FEATURE_ID_1": 2
},
"extensions": {
"EXT_mesh_features": {
"propertyTables": [2, 3, 4, 5],
"featureIds": [
{
// Feature ID Texture
//
// Vertex Shader: (Not supported)
// Fragment Shader: fsInput.featureIds.featureId_0
"propertyTable": 2,
"index": 0,
"texCoord": 0,
"channel": 0
Expand All @@ -359,25 +367,28 @@ For example, suppose we had a glTF primitive with the following feature IDs:
//
// Vertex Shader: vsInput.featureIds.featureId_1
// Fragment Shader: fsInput.featureIds.featureId_1
"propertyTable": 3,
"offset": 0,
"repeat": 3
},
{
// Feature ID Attribute (FEATURE_ID_0). Note that this
// Feature ID Attribute (_FEATURE_ID_0). Note that this
// is labeled featureId_2 for its index in the featureIds
// array
//
// Vertex Shader: vsInput.featureIds.featureId_2
// Fragment Shader: fsInput.featureIds.featureId_2
"propertyTable": 4,
"attribute": 0
},
{
// Feature ID Attribute (FEATURE_ID_1). Note that this
// Feature ID Attribute (_FEATURE_ID_1). Note that this
// is labeled featureId_3 for its index in the featureIds
// array
//
// Vertex Shader: vsInput.featureIds.featureId_3
// Fragment Shader: fsInput.featureIds.featureId_3
"propertyTable": 5,
"attribute": 1
}
]
Expand Down Expand Up @@ -434,7 +445,7 @@ to the `EXT_feature_metadata` extension:
}
},
{
// Feature ID attribute. This corresponds to FEATURE_ID_0 from the
// Feature ID attribute. This corresponds to _FEATURE_ID_0 from the
// instancing extension above. Note that this is
// labeled as instanceFeatureId_1 since it is the second feature ID
// set in the featureIds array
Expand Down Expand Up @@ -477,7 +488,7 @@ to the `EXT_feature_metadata` extension:
}
},
{
// Feature ID Attribute (FEATURE_ID_0). Note that this
// Feature ID Attribute (_FEATURE_ID_0). Note that this
// is labeled featureId_1 for its index in the featureIds
// array
//
Expand All @@ -489,7 +500,7 @@ to the `EXT_feature_metadata` extension:
}
},
{
// Feature ID Attribute (FEATURE_ID_1). Note that this
// Feature ID Attribute (_FEATURE_ID_1). Note that this
// is labeled featureId_2 for its index in the featureIds
// array
//
Expand Down
2 changes: 2 additions & 0 deletions Source/Renderer/ShaderSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,10 @@ function combineShader(shaderSource, isFragmentShader, context) {
"\
#ifdef GL_FRAGMENT_PRECISION_HIGH\n\
precision highp float;\n\
precision highp int;\n\
#else\n\
precision mediump float;\n\
precision mediump int;\n\
#define highp mediump\n\
#endif\n\n";
}
Expand Down
Loading

0 comments on commit 24f04d7

Please sign in to comment.