Skip to content

Commit ed6f310

Browse files
authored
Merge pull request #12978 from Beilinson/fix-clamped-polygon-picking
Fix clamped polygon picking
2 parents 8104a64 + 5fd0b7c commit ed6f310

File tree

3 files changed

+51
-15
lines changed

3 files changed

+51
-15
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- Improved performance of `scene.drillPick`. [#12916](https://github.com/CesiumGS/cesium/pull/12916)
1818
- Improved performance when removing primitives. [#3018](https://github.com/CesiumGS/cesium/pull/3018)
1919
- Improved performance of terrain Quadtree handling of custom data [#12907](https://github.com/CesiumGS/cesium/pull/12907)
20+
- Fixed picking of `GroundPrimitive` with multiple `PolygonGeometry` instances selecting the wrong instance. [#12978](https://github.com/CesiumGS/cesium/pull/12978)
2021

2122
## 1.134.1 - 2025-10-10
2223

packages/engine/Source/Shaders/ShadowVolumeAppearanceFS.glsl

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,6 @@ void main(void)
6565
#endif // SPHERICAL
6666
#endif // TEXTURE_COORDINATES
6767

68-
#ifdef PICK
69-
#ifdef CULL_FRAGMENTS
70-
// When classifying translucent geometry, logDepthOrDepth == 0.0
71-
// indicates a region that should not be classified, possibly due to there
72-
// being opaque pixels there in another buffer.
73-
// Check for logDepthOrDepth != 0.0 to make sure this should be classified.
74-
if (0.0 <= uv.x && uv.x <= 1.0 && 0.0 <= uv.y && uv.y <= 1.0 || logDepthOrDepth != 0.0) {
75-
out_FragColor.a = 1.0; // 0.0 alpha leads to discard from ShaderSource.createPickFragmentShaderSource
76-
czm_writeDepthClamp();
77-
}
78-
#else // CULL_FRAGMENTS
79-
out_FragColor.a = 1.0;
80-
#endif // CULL_FRAGMENTS
81-
#else // PICK
82-
8368
#ifdef CULL_FRAGMENTS
8469
// When classifying translucent geometry, logDepthOrDepth == 0.0
8570
// indicates a region that should not be classified, possibly due to there
@@ -89,6 +74,13 @@ void main(void)
8974
}
9075
#endif
9176

77+
#ifdef PICK
78+
out_FragColor.a = 1.0; // Explicitly set the alpha, otherwise this may be discarded by ShaderSource.createPickFragmentShaderSource
79+
#ifdef CULL_FRAGMENTS
80+
czm_writeDepthClamp();
81+
#endif // CULL_FRAGMENTS
82+
#else // PICK
83+
9284
#ifdef NORMAL_EC
9385
// Compute normal by sampling adjacent pixels in 2x2 block in screen space
9486
vec3 downUp = vectorFromOffset(eyeCoordinate, vec2(0.0, 1.0));

packages/engine/Specs/Scene/GroundPrimitiveSpec.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,49 @@ describe(
11561156
});
11571157
});
11581158

1159+
// Test edge-case from #12978 of geometry instances z-fighting when rendered side-by-side
1160+
it("picks the correct instance", function () {
1161+
if (!GroundPrimitive.isSupported(scene)) {
1162+
return;
1163+
}
1164+
// This edge-case only occurs when the right instance is rendered before the left instance
1165+
const rectangles = [
1166+
{
1167+
rectangle: Rectangle.fromRadians(-1.0001, 0.5, -1.0, 0.5001),
1168+
id: "right",
1169+
},
1170+
{
1171+
rectangle: Rectangle.fromRadians(-1.0002, 0.5, -1.0001, 0.5001),
1172+
id: "left",
1173+
},
1174+
];
1175+
const color = ColorGeometryInstanceAttribute.fromColor(Color.RED);
1176+
primitive = new GroundPrimitive({
1177+
geometryInstances: rectangles.map(
1178+
({ rectangle, id }) =>
1179+
new GeometryInstance({
1180+
geometry: PolygonGeometry.fromPositions({
1181+
positions: Rectangle.subsample(rectangle),
1182+
}),
1183+
id,
1184+
attributes: {
1185+
color,
1186+
},
1187+
}),
1188+
),
1189+
asynchronous: false,
1190+
});
1191+
1192+
// Slightly shift the rectangle such that without the proper discard,
1193+
// the right rectangle will render over the left during the picking pass
1194+
rectangle = Rectangle.fromRadians(-1.000201, 0.5, -1.0, 0.5001);
1195+
verifyGroundPrimitiveRender(primitive, color.value);
1196+
1197+
expect(scene).toPickAndCall(function (result) {
1198+
expect(result.id).toEqual("left");
1199+
});
1200+
});
1201+
11591202
it("picking without depth texture", function () {
11601203
if (!GroundPrimitive.isSupported(scene)) {
11611204
return;

0 commit comments

Comments
 (0)