CesiumGS / CesiumGS/cesium

Avoid creating too many sampler2D uniforms in ModelExperimental

Open
#10,090 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

category - metadata category - model/gltf
Dominant language
JavaScript
Stars
15.8k
Forks
3.9k
Avg merge
4d 6h
Merged PRs (30d)
34

Description

While I was working on #10087, I noticed that I had implemented feature ID textures such that they are labeled `u_featureIdTexture_{featureIdSet}`. The problem is sometimes two or more logical feature ID textures may refer to the same physical texture in the glTF file, so the same texture is added to the shader multiple times. This is wasteful, as there are only a limited number of texture slots when only one needs to be used.

When I get to property textures in Custom Shaders, there will be a similar case where multiple properties may share a single physical texture.

I think it'll be better to handle this by labeling by the glTF texture index, i.e. `u_featureIdTexture_{index}`. This should be pretty easy to do, but it will require changing the glTF parsing code a little:

- [ ] add an `index` property to `ModelComponents.TextureReader`
- [ ] In `GltfLoader` and any other resource loaders involving textures, store the `index` in addition to the `Texture` object.
- [ ] Update `FeatureIdPipelineStage` to use `textureReader.index` when creating the uniform name.
- [ ] Also update the uniformMap only if that uniform name isn't already in the uniformMap

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing ModelComponents.TextureReader through GltfLoader and other texture resource loaders, then inspect FeatureIdPipelineStage. Store each glTF texture index alongside its Texture object, use that index in feature ID uniform names, and verify that the uniformMap is not updated twice when multiple feature ID sets reference the same texture.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.