<blockquote>
  <p>geometry shader will add the workload of GPU</p>
</blockquote>

<p><em>Everything</em> you're trying to do will "add the workload of GPU". The only question that matters is how much.</p>

<p>Your choices are:</p>

<ol>
<li><p>Redraw everything with different FBOs. You can't just use different <code>glDrawBuffers</code> settings, because you also need to change the depth buffers between the two draws.</p></li>
<li><p>Use <a href="https://www.khronos.org/opengl/wiki/Layered_Rendering" rel="nofollow noreferrer">layered rendering</a>. Your two textures would instead be one texture object with two array layers (the same for the depth texture). There are multiple ways of going about this:</p>

<ol>
<li>Render the scene twice, using a <code>uniform</code> variable of some kind to determine which layer gets rendered to. This means having to read and execute the VS on all of the vertex data twice.</li>
<li>Render the scene once with <a href="https://www.khronos.org/opengl/wiki/Instanced_Rendering" rel="nofollow noreferrer">Instanced Rendering</a>, using <code>gl_InstanceID</code> to determine which layer that particular rendering gets rendered to. This means having to read and execute the VS on all of the vertex data twice.</li>
<li>Render the scene with a Geometry Shader that spits out two triangles for each triangle it gets, one for each layer. This only reads the vertex data and executes the VS on it once.</li>
<li>Render the scene with <a href="https://www.khronos.org/opengl/wiki/Geometry_Shader#Instancing" rel="nofollow noreferrer">Geometry Shader instancing</a>. The GS will be executed twice for each primitive, with a different <code>gl_InvocationID</code> value specifying which instance the GS is being executed for. You use that ID to determine which layer to send the primitive to, as well as how to transform it. This only reads the vertex data and executes the VS on it once.</li>
</ol></li>
</ol>

<p>All of the variations of layered rendering will require either a Geometry Shader or access to the ARB_shader_viewport_layer_array extension or the AMD_vertex_shader_layer &amp; AMD_vertex_shader_viewport_index extensions (equivalent to the ARB version). Obviously, since Options 2.3 and 2.4 already require a GS, there's no downside to using them.</p>

<p>You should profile these options to find out which is faster for your needs. However, despite the fact that GS's are generally not fast things, the fact that 2.3 and 2.4 will eliminate lots of redundant reading and processing of vertex data, it's highly likely that the GS options will be <em>faster</em> than using instanced rendering.</p>

CC BY-SA 3.0
2018-03-14T22:37:54.450Z
2018-03-15T06:08:25.593Z
2018-03-15T06:08:25.593Z
Nicol Bolas
<p>No, this is the opposite of what instancing is for. Instancing lets you have multiple copies of the same geometry in one viewport. In your case, it would let you render into one FBO to have one texture containing multiple rabbits. To generate two separate textures, you need to do two render passes, one for each FBO. If the geometry is the same in both cases and only the transform is different, you don't need to send the geometry to the GPU twice, so it's pretty fast.</p>

CC BY-SA 3.0
2018-03-12T00:21:16.290Z
can i use "glViewportArrayv(ARB_shader_viewport_layer_array)" to reach the goal?
Xin YANG
CC BY-SA 3.0
2018-03-11T12:01:01.020Z
2018-03-11T12:01:01.020Z
Dan Hulme
<p>For example, I have two transform matrix: WVP_Left and WVP_Right.</p>

<p>Can I render geometry (like a rabbit) using instancing to generate left texture and right texture?</p>

<p>The left texture should just have only one rabbit with the WVP_Left effect, and the right texture should just have one rabbit with the WVP_Right effect.</p>

<p>For now, I get two textures which both have 2 rabbit with some overlap part.</p>

<p>How can I fix it?</p>

<p>I don't want to render the left and right scene into one texture, and split it to 2 texture in another pass.</p>

<p>Also, I don't want to use geometry shader to finish the thing, because geometry shader will add the workload of GPU</p>

CC BY-SA 3.0
2018-03-11T15:16:18.537Z
"*I don't want to render the left and right scene into one texture*" "*I don't want to use geometry shader and layered rendering*" This is called "defining yourself into a corner": you've imposed arbitrary limitations on yourself, such that there is no valid solution. Remove one of these restrictions, and you can do what you need.
Nicol Bolas
CC BY-SA 3.0
2018-03-12T00:21:09.797Z
can i use "glViewportArrayv(ARB_shader_viewport_layer_array)" to reach the goal?
Xin YANG
CC BY-SA 3.0
2018-03-12T00:26:26.940Z
@NicolBolas in the question [Multiple viewports with modern OpenGL?](https://computergraphics.stackexchange.com/questions/4513/multiple-viewports-with-modern-opengl),
i have read  answer about similar situation, only the difference is the output. you and Christian_B's answer is give me some hope
Xin YANG
CC BY-SA 3.0
2018-03-12T01:36:10.267Z
"*can i use "glViewportArrayv(ARB_shader_viewport_layer_array)" to reach the goal?*" You specifically said you didn't want to use layered rendering. And viewport arrays are all about doing layered rendering, since each viewport in the array is hooked to the corresponding array layer in the framebuffer. So either you're willing to use layered rendering or you can't use `glViewportArray` or ARB_shader_viewport_layer_array.
Nicol Bolas
CC BY-SA 3.0
2018-03-12T04:51:23.853Z
@NicolBolas maybe my oringnal description is not proper, i can use layered rendering but not want to use geometry shader. Afaik, geometry shader and layered rendering(gl_layer) are bounded. but the new feature ARB_shader_viewport_layer_array may change this situation. i will edit my original description. Then can i make my goal achievement? and how in detail?
Xin YANG
<opengl>
How can I use instancing to generate 2 single different texture?
Xin YANG
# How can I use instancing to generate 2 single different texture?

(Asked by: username_0 on 2018-03-11)

For example, I have two transform matrix: WVP\_Left and WVP\_Right.

Can I render geometry (like a rabbit) using instancing to generate left texture and right texture?

The left texture should just have only one rabbit with the WVP\_Left effect, and the right texture should just have one rabbit with the WVP\_Right effect.

For now, I get two textures which both have 2 rabbit with some overlap part.

How can I fix it?

I don't want to render the left and right scene into one texture, and split it to 2 texture in another pass.

Also, I don't want to use geometry shader to finish the thing, because geometry shader will add the workload of GPU

**Tags:** opengl

> **Comments:**
> **username_1**: "*I don't want to render the left and right scene into one texture*" "*I don't want to use geometry shader and layered rendering*" This is called "defining yourself into a corner": you've imposed arbitrary limitations on yourself, such that there is no valid solution. Remove one of these restrictions, and you can do what you need.  
> **username_0**: can i use "glViewportArrayv(ARB_shader_viewport_layer_array)" to reach the goal?  
> **username_0**: @username_1 in the question [Multiple viewports with modern OpenGL?](https://computergraphics.stackexchange.com/questions/4513/multiple-viewports-with-modern-opengl), i have read  answer about similar situation, only the difference is the output. you and Christian_B's answer is give me some hope  
> **username_1**: "*can i use "glViewportArrayv(ARB_shader_viewport_layer_array)" to reach the goal?*" You specifically said you didn't want to use layered rendering. And viewport arrays are all about doing layered rendering, since each viewport in the array is hooked to the corresponding array layer in the framebuffer. So either you're willing to use layered rendering or you can't use `glViewportArray` or ARB_shader_viewport_layer_array.  
> **username_0**: @username_1 maybe my oringnal description is not proper, i can use layered rendering but not want to use geometry shader. Afaik, geometry shader and layered rendering(gl_layer) are bounded. but the new feature ARB_shader_viewport_layer_array may change this situation. i will edit my original description. Then can i make my goal achievement? and how in detail?  

---

## 2 answers

### Answer by username_1 on 2018-03-14. Score: 2

> geometry shader will add the workload of GPU

*Everything* you're trying to do will "add the workload of GPU". The only question that matters is how much.

Your choices are:

1. Redraw everything with different FBOs. You can't just use different `glDrawBuffers` settings, because you also need to change the depth buffers between the two draws.
2. Use [layered rendering](https://www.khronos.org/opengl/wiki/Layered_Rendering). Your two textures would instead be one texture object with two array layers (the same for the depth texture). There are multiple ways of going about this:

   1. Render the scene twice, using a `uniform` variable of some kind to determine which layer gets rendered to. This means having to read and execute the VS on all of the vertex data twice.
   2. Render the scene once with [Instanced Rendering](https://www.khronos.org/opengl/wiki/Instanced_Rendering), using `gl_InstanceID` to determine which layer that particular rendering gets rendered to. This means having to read and execute the VS on all of the vertex data twice.
   3. Render the scene with a Geometry Shader that spits out two triangles for each triangle it gets, one for each layer. This only reads the vertex data and executes the VS on it once.
   4. Render the scene with [Geometry Shader instancing](https://www.khronos.org/opengl/wiki/Geometry_Shader#Instancing). The GS will be executed twice for each primitive, with a different `gl_InvocationID` value specifying which instance the GS is being executed for. You use that ID to determine which layer to send the primitive to, as well as how to transform it. This only reads the vertex data and executes the VS on it once.

All of the variations of layered rendering will require either a Geometry Shader or access to the ARB\_shader\_viewport\_layer\_array extension or the AMD\_vertex\_shader\_layer & AMD\_vertex\_shader\_viewport\_index extensions (equivalent to the ARB version). Obviously, since Options 2.3 and 2.4 already require a GS, there's no downside to using them.

You should profile these options to find out which is faster for your needs. However, despite the fact that GS's are generally not fast things, the fact that 2.3 and 2.4 will eliminate lots of redundant reading and processing of vertex data, it's highly likely that the GS options will be *faster* than using instanced rendering.


---

### Answer by username_2 on 2018-03-11. Score: 1

No, this is the opposite of what instancing is for. Instancing lets you have multiple copies of the same geometry in one viewport. In your case, it would let you render into one FBO to have one texture containing multiple rabbits. To generate two separate textures, you need to do two render passes, one for each FBO. If the geometry is the same in both cases and only the transform is different, you don't need to send the geometry to the GPU twice, so it's pretty fast.

> **Comments:**
> **username_0**: can i use "glViewportArrayv(ARB_shader_viewport_layer_array)" to reach the goal?  

---

