Handle undefined vector properties in styles better
- Dominant language
- JavaScript
- Stars
- 15.7k
- Forks
- 3.9k
- Avg merge
- 4d 6h
- Merged PRs (30d)
- 34
Description
Since https://github.com/CesiumGS/cesium/pull/9882, missing properties in point cloud styles resolve to `undefined` instead of throwing an error. `undefined` is converted to the sentinel value `czm_infinity`. This works ok if your property is a scalar but if it's a vector there may be type mismatches which cause the shader to not compile.
For example if your point cloud is missing a "Velocity" property the second condition of this style will not compile because it will resolve to `czm_infinity == vec3(0.0)`
```js
tileset.style = new Cesium.Cesium3DTileStyle({
color: {
conditions: [
["${Velocity} === undefined", "color('yellow')"],
["true", "${Velocity} === vec3(0.0) ? color('red') : color('blue')"],
],
},
});
```
If your point cloud has a "Velocity" property but the style has an undefined check it will also fail to compile because the first condition will resolve to `vec3(...) == czm_infinity`
```js
tileset.style = new Cesium.Cesium3DTileStyle({
color: {
conditions: [
["${Velocity} === undefined", "color('yellow')"],
["true", "color('red')"],
],
},
});
```
The left hand side of the `===` could be a more complicated expression and it would be very difficult to detect the type. But if it were possible to detect the type you could convert the `undefined` to a vec3 of `czm_infinity` (for example) so that the types match. Another thought is to always promote each side of the `===` to a vec4, but this isn't possible with GLSL's vec4 contructors without knowing the type. Another idea is to keep trying to promote each `undefined` to the right type until the shader compiles, but this is impractical because of the number of permutations possible.
In general `undefined` is not the easiest concept to work when styles are transpiled to GLSL and I think 3D Tiles Next metadata and custom shaders with their stricter type safety will avoid such problems.
Contributor guide
Research direction
Start with the point cloud style handling behind Cesium3DTileStyle and reproduce the two Velocity examples, focusing on how undefined values become czm_infinity during GLSL transpilation. Investigate the type-mismatch failures for scalar and vector properties. Done requires an agreed strategy for handling undefined in these expressions and shader compilation coverage, but the issue does not name files or tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100