Skip to content

Shader rework for terrain polygon clipping - #13637

Open
mzschwartz5 wants to merge 5 commits into
clipping-texture-plumbingfrom
clipping-globe-shader-rework
Open

Shader rework for terrain polygon clipping#13637
mzschwartz5 wants to merge 5 commits into
clipping-texture-plumbingfrom
clipping-globe-shader-rework

Conversation

@mzschwartz5

@mzschwartz5 mzschwartz5 commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Description

This PR is the 4th installment in the effort to reimplement Clipping Polygons on top of the vector data pipeline -- specifically, for terrain (3d tiles and models to come).

In this PR, I wire up the vector-clipping texture uniforms and make the shader changes to actually use them. Thus, as of this PR, terrain clipping actually operates via the vector shaders!

And just look at the difference in quality:

Vector-based clipping:

image

SDF-based clipping:

image

Issue number and link

https://github.com/iTwin/cesiumjs-web3d-internal/issues/34

Testing plan

A sandcastle that uses a star shaped polygon to clip the globe (feel free to add terrain and test that too). Use the slider or input field to change the scale of the star and ensure it's crisp at all scales.

Dynamic clipping collection -- this one tests adding and removing clipping polygons from a collection. On this PR branch, the 3D tiles option still uses the SDF approach and will not render crisply.

Standard clipping regions sandcastle -- basic functionality check

The clipping performance dev sandcastle is another good one for testing various numbers (of polygons, points per polygon, spacing, etc.). NOTE: in this PR, I have not yet removed the SDF code paths. So the performance of clipping will appear the same or worse, as the SDF textures are still being generated.

Author checklist

  • I have submitted a Contributor License Agreement
  • I have added my name to CONTRIBUTORS.md
  • I have updated CHANGES.md with a short summary of my change
  • I have added or updated unit tests to ensure consistent code coverage
  • I have updated the inline documentation, and included code examples where relevant
  • I have performed a self-review of my code

AI acknowledgment

  • I used AI to generate content in this PR
  • If yes, I have reviewed the AI-generated content before submitting

If yes, I used the following Tools(s) and/or Service(s):

If yes, I used the following Model(s):

PR Dependency Tree

This tree was auto-generated by Charcoal

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for the pull request, @mzschwartz5!

✅ We can confirm we have a CLA on file for you.

@mzschwartz5
mzschwartz5 force-pushed the clipping-globe-shader-rework branch from 987ae15 to 28c14d6 Compare July 20, 2026 16:45
@mzschwartz5
mzschwartz5 force-pushed the clipping-texture-plumbing branch from 0bcf38f to cfc9407 Compare July 21, 2026 15:54
@mzschwartz5
mzschwartz5 force-pushed the clipping-globe-shader-rework branch from 28c14d6 to 6fb2a70 Compare July 21, 2026 17:31
@mzschwartz5
mzschwartz5 force-pushed the clipping-texture-plumbing branch from cfc9407 to 7886bf6 Compare July 29, 2026 18:55
@mzschwartz5
mzschwartz5 force-pushed the clipping-globe-shader-rework branch from 6fb2a70 to 9953e6b Compare July 29, 2026 18:55

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, I'm mainly just factoring out some code into a reusable function (vectorCellRange), and adding a new function vectorClip for the actual clipping flow. Two notes:

  1. You'll notice vectorClip is pretty similar structurally to vectorPolygonRender. It's possible they could be refactored to share even more code and avoid repeating ourselves. I did try this, but it was kind of ugly and added a little performance overhead. Decided to leave as-is.
  2. I added a couple uniforms for clipping. Ideally, I think a better solution would be for this file to not explicitly declare uniforms, and to have the functions be parameterized to accept them. I'm leaving that as a TODO; it's good enough as-is.

@mzschwartz5
mzschwartz5 marked this pull request as ready for review July 30, 2026 15:21
@mzschwartz5
mzschwartz5 force-pushed the clipping-texture-plumbing branch from 7886bf6 to 0c9fd7e Compare July 31, 2026 16:57
@mzschwartz5
mzschwartz5 force-pushed the clipping-globe-shader-rework branch from 1704714 to c8346e0 Compare July 31, 2026 16:57
@mzschwartz5
mzschwartz5 force-pushed the clipping-texture-plumbing branch from 0c9fd7e to e044831 Compare July 31, 2026 18:55
@mzschwartz5
mzschwartz5 force-pushed the clipping-globe-shader-rework branch from c8346e0 to 4b3bd7d Compare July 31, 2026 18:55
@mzschwartz5
mzschwartz5 force-pushed the clipping-texture-plumbing branch from e044831 to 3ec33e6 Compare July 31, 2026 22:24
@mzschwartz5
mzschwartz5 force-pushed the clipping-globe-shader-rework branch from 4b3bd7d to 512656d Compare July 31, 2026 22:25
@mzschwartz5
mzschwartz5 force-pushed the clipping-texture-plumbing branch from 3ec33e6 to 05ce087 Compare August 3, 2026 01:07
@mzschwartz5
mzschwartz5 force-pushed the clipping-globe-shader-rework branch from 512656d to 453391f Compare August 3, 2026 01:07
@mzschwartz5
mzschwartz5 force-pushed the clipping-texture-plumbing branch from 05ce087 to 29f0964 Compare August 3, 2026 01:14
@mzschwartz5
mzschwartz5 force-pushed the clipping-globe-shader-rework branch from 453391f to 27cbc04 Compare August 3, 2026 01:14
@mzschwartz5 mzschwartz5 mentioned this pull request Aug 3, 2026
8 tasks
@mzschwartz5
mzschwartz5 force-pushed the clipping-texture-plumbing branch from 29f0964 to 6431186 Compare August 3, 2026 19:32
@mzschwartz5
mzschwartz5 force-pushed the clipping-globe-shader-rework branch from 27cbc04 to 027db9d Compare August 3, 2026 19:32
@mzschwartz5
mzschwartz5 force-pushed the clipping-texture-plumbing branch from 6431186 to b9abfb8 Compare August 10, 2026 19:39
@mzschwartz5
mzschwartz5 force-pushed the clipping-globe-shader-rework branch from 027db9d to 455e445 Compare August 10, 2026 19:39
@mzschwartz5
mzschwartz5 force-pushed the clipping-texture-plumbing branch from b9abfb8 to 83888d6 Compare August 18, 2026 17:20
@mzschwartz5
mzschwartz5 force-pushed the clipping-globe-shader-rework branch from 455e445 to 4430325 Compare August 18, 2026 17:20
@mzschwartz5
mzschwartz5 force-pushed the clipping-texture-plumbing branch from 83888d6 to 058325c Compare August 19, 2026 17:08
@mzschwartz5
mzschwartz5 force-pushed the clipping-globe-shader-rework branch from 4430325 to 01ee56a Compare August 19, 2026 17:08
@mzschwartz5
mzschwartz5 force-pushed the clipping-texture-plumbing branch from 058325c to 00e0a0b Compare August 19, 2026 19:38
@mzschwartz5
mzschwartz5 force-pushed the clipping-globe-shader-rework branch from 01ee56a to fe9d895 Compare August 19, 2026 19:38
@mzschwartz5
mzschwartz5 force-pushed the clipping-texture-plumbing branch from 00e0a0b to 91f077b Compare August 20, 2026 14:17
@mzschwartz5
mzschwartz5 force-pushed the clipping-globe-shader-rework branch from fe9d895 to 6386ffa Compare August 20, 2026 14:17
@mzschwartz5
mzschwartz5 force-pushed the clipping-texture-plumbing branch from 91f077b to ea4ba28 Compare August 20, 2026 14:33
@mzschwartz5
mzschwartz5 force-pushed the clipping-globe-shader-rework branch from 6386ffa to b1d302e Compare August 20, 2026 14:33
@@ -457,9 +457,16 @@ void main()
#endif

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the meat of this PR: here, we actually switch over from the old SDF-based clipping function, to the new vector-based clipping function.

@mzschwartz5
mzschwartz5 force-pushed the clipping-texture-plumbing branch from ea4ba28 to a326f98 Compare August 21, 2026 16:14
@mzschwartz5
mzschwartz5 force-pushed the clipping-globe-shader-rework branch from b1d302e to 7f92ee6 Compare August 21, 2026 16:14
@mzschwartz5
mzschwartz5 force-pushed the clipping-texture-plumbing branch from a326f98 to 79c8b25 Compare August 21, 2026 16:16
@mzschwartz5
mzschwartz5 force-pushed the clipping-globe-shader-rework branch from 7f92ee6 to 1a42e12 Compare August 21, 2026 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant