Class GpuPicker
Answers "what is under this screen point" from the rendered frame rather than from physics: a pass draws every mesh's id instead of its colour, and the pixel asked about is read back. No collider is needed, and the answer is per pixel - an instanced flock, a procedural model, a skinned character, all pickable. The answer arrives two frames after the request.
public sealed class GpuPicker : IDisposable
- Inheritance
-
GpuPicker
- Implements
Remarks
Ask with Request(Vector2) once, or set Continuous to follow the mouse every frame, and read Result; its Sequence says when there is a new one. The pass runs only on frames with a request, and costs the draw submission of the meshes in view once more, scissored to a single pixel on the GPU.
Limits: meshes only - sprites, UI, particles and shapes are not picked; a cut-out material's transparent pixels pick as solid, because only the pixel stage is swapped; the picker reads the main camera, so a feed drawn into a texture needs its own.
Properties
Continuous
Whether to pick at the mouse on every frame that has no explicit request, so Result follows the pointer for hover effects. Off by default.
public bool Continuous { get; set; }
Property Value
Pickable
Which render groups are pickable. Everything by default; narrow it to keep decorative geometry out of the pass.
public RenderGroupMask Pickable { get; set; }
Property Value
Renderer
The renderer doing the pass, for anyone who wants to move it in the compositor.
public GpuPickingSceneRenderer Renderer { get; }
Property Value
Result
The last answer, or null before the first request has been answered.
public PickResult? Result { get; }
Property Value
Methods
Dispose()
Takes the pass out of the compositor and the mesh feature.
public void Dispose()
Request(Vector2)
Asks what is under a screen point. The answer lands in Result two frames later. One request per frame; a second in the same frame replaces the first.
public void Request(Vector2 screenPosition)
Parameters
screenPositionVector2The point, normalised over the viewport with (0, 0) at the top left and (1, 1) at the bottom right, as
Input.MousePositiongives it.