Skip to content

Commit af3fbe9

Browse files
authored
GPUPicker: Fix picking ID precision issues (#17404)
Resolves the issue: https://forum.babylonjs.com/t/missing-doc-for-gpupicker-in-v8-31-3/61295/5 What I found while examining this issue is that when outputting values received as uniform variables in the shader to the screen, the uniform values were displayed completely without error, but values received as attributes exhibited errors. I don't know the exact reason for this, as it is an internal WebGL implementation detail. Through experimentation, I found a safe `MaxPickingId` value usable across WebGL, WebGL2, and WebGPU. I confirmed that adding 0.5 at the point of casting from int resolves this precision issue.
1 parent 1e74617 commit af3fbe9

File tree

5 files changed

+4
-6
lines changed

5 files changed

+4
-6
lines changed

packages/dev/core/src/Collisions/gpuPicker.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,6 @@ export class GPUPicker {
219219
return;
220220
}
221221

222-
this._pickableMeshes = list as Array<AbstractMesh>;
223-
224222
// Prepare target
225223
const scene = ("mesh" in list[0] ? list[0].mesh : list[0]).getScene();
226224
if (!this._cachedScene || this._cachedScene !== scene) {

packages/dev/core/src/Shaders/picking.fragment.fx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
#if defined(INSTANCES)
3-
varying float vMeshID;
3+
flat varying float vMeshID;
44
#else
55
uniform float meshID;
66
#endif

packages/dev/core/src/Shaders/picking.vertex.fx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ uniform mat4 viewProjection;
1616

1717
// Output
1818
#if defined(INSTANCES)
19-
varying float vMeshID;
19+
flat varying float vMeshID;
2020
#endif
2121

2222
void main(void) {

packages/dev/core/src/ShadersWGSL/picking.fragment.fx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
#if defined(INSTANCES)
3-
varying vMeshID: f32;
3+
flat varying vMeshID: f32;
44
#else
55
uniform meshID: f32;
66
#endif

packages/dev/core/src/ShadersWGSL/picking.vertex.fx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ uniform viewProjection: mat4x4f;
1616

1717
// Output
1818
#if defined(INSTANCES)
19-
varying vMeshID: f32;
19+
flat varying vMeshID: f32;
2020
#endif
2121

2222
@vertex

0 commit comments

Comments
 (0)