Fix incorrect clipping polygon region selection in vertex shaders#13298
Open
alarkbentley wants to merge 5 commits intoCesiumGS:mainfrom
Open
Fix incorrect clipping polygon region selection in vertex shaders#13298alarkbentley wants to merge 5 commits intoCesiumGS:mainfrom
alarkbentley wants to merge 5 commits intoCesiumGS:mainfrom
Conversation
Contributor
|
Thank you for the pull request, @alarkbentley! ✅ We can confirm we have a CLA on file for you. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Fixes a bug where the clipping polygon vertex shaders (
GlobeVS.glslandModelClippingPolygonsStageVS.glsl) could select the wrong clipping region for a vertex, leading to incorrect polygon clipping results.Demo
Sandcastle
1. Open Sandcastle Link
It should correctly render Clipping Polygon A and Clipping Polygon B
2. Change "Spacing = 5", "Scale = 2" and click "Update ClippingPolygons"
Clipping Polygon A fails because the large distance forces the two polygons to reside in different regions in the texture atlas and Polygon A incorrectly uses the region data from Polygon B where the scale differs.
Problem
The previous implementation used a minimum-distance heuristic to choose which clipping region a vertex belongs to. It tracked the closest region boundary (
minDistance) and always updatedv_clippingPositionwhenever a closer boundary was found — even if the vertex was outside that region. Thev_regionIndexwas only set when the vertex was actually inside the region, butv_clippingPositioncould be overwritten by an incorrect, closer-but-wrong region.This had two issues:
v_clippingPositioncould refer to the wrong region. The distance comparisonminDistance.x > distance.x || minDistance.y > distance.ywould overwritev_clippingPositionwith UV coordinates from a region the vertex doesn't belong to, as long as that region's boundary was closer on either axis.Unnecessary computation. Clamping, distance calculations, and comparisons were performed for every region even when a simple containment check suffices.
Solution
Replace the minimum-distance heuristic with a direct containment test. For each region, compute the UV coordinates and check whether the vertex falls within the region bounds (with a small threshold). On the first match, set both
v_clippingPositionandv_regionIndexand move on — since clipping regions should never overlap, the first match is always the correct one.Changes
packages/engine/Source/Shaders/GlobeVS.glsl— Replaced distance-based region selection with containment test in theENABLE_CLIPPING_POLYGONSblock.packages/engine/Source/Shaders/Model/ModelClippingPolygonsStageVS.glsl— Same fix applied to the model clipping polygons stage.Testing
Verified visually that clipping polygons render correctly and clip to the intended regions. The fix is a shader-only change with no API surface modifications.
Author checklist
CONTRIBUTORS.mdCHANGES.mdwith a short summary of my change