@@ -748,7 +748,10 @@ To do that we need a way to render the objects with ids. We have a few options.
748748
7497492. ## We could render twice, once for color, once for ids
750750
751- I ' m going to choose method for now for reasons that will hopefully become clear.
751+ I ' m going to choose this method for now for reasons that will hopefully become clear after this step. [^render-twice]
752+
753+ [^render-twice]: Method 2 was chosen because we needed a way to selectively render for picking in order to implement cycling
754+ through all objects under the pointer.
752755
753756So, first let' s add the id to our uniforms and create a fragment shader
754757that outputs ids.
@@ -946,7 +949,7 @@ and we need to update the rendering code to include the id
946949
947950 mat4.multiply(viewProjectionMatrix, matrix, matrixValue);
948951 colorValue.set(color);
949- + idValue[0] = objectNdx;
952+ + idValue[0] = objectNdx;
950953
951954 // upload the uniform values to the uniform buffer
952955 device.queue.writeBuffer(uniformBuffer, 0, uniformValues);
@@ -1216,7 +1219,7 @@ we mentioned above.
12161219 // pick from the available meshes
12171220- const id = await pick (clipX, clipY, viewProjectionMatrix);
12181221- if (id > 0 ) {
1219- + let id = await pick (clipX, clipY, viewProjectionMatrix, pickableMeshes);
1222+ + let id = await pick (clipX, clipY, viewProjectionMatrix, pickableMeshes);
12201223+ if (id === 0 ) {
12211224+ // if we didn't find one, try all of them again
12221225+ pickableMeshes = meshes .slice ();
@@ -1295,7 +1298,7 @@ the reader 😛
12951298 pixels since in the end we're only reading a single pixel
12961299 anyway.
12971300
1298- 2. Use frustum culling or other "potential visible set"
1301+ 2. Use frustum culling or other "potential visible set" culling
12991302
13001303 If you can easily determine if an object is definitely not in front of the
13011304 camera then you can skip asking the GPU to look at all of that object's triangles.
0 commit comments