Skip to content

Fix: polyline material batching to prevent unnecessary re-renders#13157

Open
MohammadShujaullah wants to merge 2 commits intoCesiumGS:mainfrom
MohammadShujaullah:fix-polyline-material-batching-issue-13136
Open

Fix: polyline material batching to prevent unnecessary re-renders#13157
MohammadShujaullah wants to merge 2 commits intoCesiumGS:mainfrom
MohammadShujaullah:fix-polyline-material-batching-issue-13136

Conversation

@MohammadShujaullah
Copy link
Contributor

Fixes #13136

Description--
When processing a single polyline through CZML, all polylines with the same material were re-rendering due to overly aggressive batch invalidation. This fix enhances the material change detection to be more intelligent.

Changes Made--
Enhanced Batch.prototype.onMaterialChanged to check if material values actually changed
Added material value comparison logic to prevent unnecessary batch invalidation
Specifically handles color materials by comparing actual color values
Stores last material value for comparison
Only invalidates batches when materials truly change functionally

Root Cause--
The issue occurred because:
CZML creates new material property instances even when data is identical
This triggers definitionChanged events
Previous code blindly invalidated entire batches
All polylines in the batch would re-render, causing widespread "blinking"

Solution--
Now the system:
Captures current material values when change events occur
Compares with previously stored values
Only invalidates batches when actual value changes are detected
Preserves existing batch structures when materials are functionally identical

Testing--
Build passes successfully
Logic correctly identifies when materials haven't actually changed
Prevents widespread re-rendering while maintaining proper update behavior

When processing a single polyline through CZML, all polylines with the same material were re-rendering due to overly aggressive batch invalidation. This fix:

- Enhances onMaterialChanged to check if material values actually changed
- Compares actual material values instead of blindly invalidating batches
- Specifically handles color materials by comparing color values
- Prevents widespread 'blinking' effect when processing individual polylines

Fixes CesiumGS#13136
@github-actions
Copy link

Thank you for the pull request, @MohammadShujaullah!

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

Comment on lines +76 to +87
// Simple comparison for now - in practice, we'd need a deep equality check
// For color materials, we can compare the color values
if (currentMaterial.type === this._lastMaterialValue.type) {
if (currentMaterial.type === "Color") {
const currentColor = currentMaterial.uniforms.color;
const lastColor = this._lastMaterialValue.uniforms.color;
if (Color.equals(currentColor, lastColor)) {
// Colors are the same, don't invalidate
return;
}
}
// For other material types, we might need more sophisticated comparison
Copy link
Member

Choose a reason for hiding this comment

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

In a recent PR (for a different performance issue), I added deepMaterialsEqual(a, b): boolean

That might be helpful here, too? Or if it's not helpful here, I'd like to improve that in the other PR. :)

@mzschwartz5
Copy link
Contributor

mzschwartz5 commented Jan 28, 2026

There are a handful of Static*Batch classes in CesiumJS. It's quite unfortunate, really - they're complex and buggy, and all very similar with small differences. We have an issue about that here.

Anyway, I'd like to avoid making more differences between these classes if possible. I'm guilty of this myself, though - #12722 fixed some flickering / flashing issues with materials due to aggressive batching. I only ever applied the fix to the static ground geometry variant class, but I wonder if applying the same changes to the StaticGeometry... variant would fix your issue.

If so, that would be preferable as it would mean keeping these similar classes in sync better.

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.

Processing a single polyline re-renders all polylines with the same material

3 participants