fix(BillboardCollection): Fix precision loss in billboard image texcoords #13050
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Currently billboards compute texture coordinates (in 0–1 UV space) for each image in the texture atlas:
cesium/packages/engine/Source/Renderer/TextureAtlas.js
Lines 195 to 206 in ee2b381
Texture coordinates are then quantized to 12 bits:
cesium/packages/engine/Source/Core/AttributeCompression.js
Lines 308 to 317 in ee2b381
On testing all valid pixel offsets for all power-of-two atlas sizes...
... we find coordinates off by 1px about 25% of the time, which I believe explains the remaining issues from #5154. While we could modify the texture compression code to fix this, (1) texture coordinates outside of billboards may not correspond to integer pixel offsets at all, and (2) it's worth stepping back to consider what we're trying to do:
Ultimately each Billboard must sample from its image in the texture atlas. Images have integer pixel offsets and integer dimensions, which cannot exceed maximum texture sizes of ~16K. We need to pack pairs of these integers into 32-bit vertex attribute components. We can achieve this more simply by packing two integers into one 32-bit float directly...
... skipping both integer-to-float conversions and lossy quantization.
Preview:
TODO
Issue number and link
Testing plan
Because coordinates and attribute packing differs in WebGL2 vs. WebGL1, and with or without instancing, we need to test multiple environments:
WebGL2 guarantees instancing support, so we don't need to worry about that case. If #13042 is merged before this PR (preferred) then the WebGL1 vs. WebGL2 distinction is removed and we only need to worry about instanced vs. non-instanced code paths. Optionally instancing could be required (see #13053) but I've handled the non-instanced fallback here anyway.
More detailed test plan TBD.
Author checklist
CONTRIBUTORS.mdCHANGES.mdwith a short summary of my changePR Dependency Tree
This tree was auto-generated by Charcoal