Avoid creating too many sampler2D uniforms in ModelExperimental
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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