# Is GPU Object Picking possible with a single render?

**URL:** <https://discourse.threejs.org/t/is-gpu-object-picking-possible-with-a-single-render/70228>\
**Category:** Questions\
**Tags:** shader, webgl2\
**Created:** [September 3, 2024, 12:40pm UTC](https://discourse.threejs.org/t/is-gpu-object-picking-possible-with-a-single-render/70228 "2024-09-03T12:40:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rob-myers](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/rob-myers/32/17590_2.png) [@rob-myers](https://discourse.threejs.org/u/rob-myers)\
**Post date:** [September 3, 2024, 12:40pm UTC](https://discourse.threejs.org/t/is-gpu-object-picking-possible-with-a-single-render/70228/1 "2024-09-03T12:40:14Z")

</div>

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

```glsl
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?

---

<div class="post-metadata">

**Author:** ![dubois](https://avatars.discourse-cdn.com/v4/letter/d/e9c0ed/32.png) [@dubois](https://discourse.threejs.org/u/dubois)\
**Post date:** [September 3, 2024, 1:32pm UTC](https://discourse.threejs.org/t/is-gpu-object-picking-possible-with-a-single-render/70228/2 "2024-09-03T13:32:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rob-myers](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/rob-myers/32/17590_2.png) [@rob-myers](https://discourse.threejs.org/u/rob-myers)\
**Post date:** [September 3, 2024, 2:34pm UTC](https://discourse.threejs.org/t/is-gpu-object-picking-possible-with-a-single-render/70228/3 "2024-09-03T14:34:42Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![dubois](https://avatars.discourse-cdn.com/v4/letter/d/e9c0ed/32.png) [@dubois](https://discourse.threejs.org/u/dubois)\
**Post date:** [September 3, 2024, 4:37pm UTC](https://discourse.threejs.org/t/is-gpu-object-picking-possible-with-a-single-render/70228/4 "2024-09-03T16:37:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rob-myers](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/rob-myers/32/17590_2.png) [@rob-myers](https://discourse.threejs.org/u/rob-myers)\
**Post date:** [September 3, 2024, 6:38pm UTC](https://discourse.threejs.org/t/is-gpu-object-picking-possible-with-a-single-render/70228/5 "2024-09-03T18:38:51Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dubois](https://avatars.discourse-cdn.com/v4/letter/d/e9c0ed/32.png) [@dubois](https://discourse.threejs.org/u/dubois)\
**Post date:** [September 4, 2024, 1:09am UTC](https://discourse.threejs.org/t/is-gpu-object-picking-possible-with-a-single-render/70228/6 "2024-09-04T01:09:25Z")

</div>

> **[GitHub - pailhead/rsm at 034770b8ad740fafbc619a764ff7cb159c626e90](https://github.com/pailhead/rsm/tree/034770b8ad740fafbc619a764ff7cb159c626e90)**
>
> 034770b8ad740fafbc619a764ff7cb159c626e90
