Is GPU Object Picking possible with a single render?

Suppose I render a Mesh with a ShaderMaterial.
Further suppose the fragment shader has the following form:

layout(location = 1) out vec4 gObjectPick;

// ...
// shader code setting gl_FragColor and gObjectPick
// ...

Is it possible to “read the pixels” of gObjectPick without doing another render using THREE.WebGLRenderTarget?

Another question: what is the relationship between “location = 1” and THREE.WebGLRenderTarget? Maybe it’s something that falls outside the three.js API?

yes,but you need to add multiple textures to a render target.

Thanks that was helpful, but I’m still trying to understand how this can be a single render.

Suppose we create a render target with two textures and render our scene. Don’t we need another render e.g. of another scene containing a single full-screen quad?

No, you make this layout like you did just add other outputs. I think I was even able to mix and match different precisions.

Do you have a rough example?

Every example I’ve seen online switches between a renderTarget and null, rendering twice per frame.

I’m looking for an example where the 0th output goes to the canvas, and the 1st is used for object picking.

1 Like