-1
$\begingroup$

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

$\endgroup$
5
  • 2
    $\begingroup$ "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. $\endgroup$ – Nicol Bolas Mar 11 '18 at 15:16
  • $\begingroup$ can i use "glViewportArrayv(ARB_shader_viewport_layer_array)" to reach the goal? $\endgroup$ – Xin YANG Mar 12 '18 at 0:21
  • $\begingroup$ @NicolBolas in the question 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 $\endgroup$ – Xin YANG Mar 12 '18 at 0:26
  • 1
    $\begingroup$ "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. $\endgroup$ – Nicol Bolas Mar 12 '18 at 1:36
  • $\begingroup$ @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? $\endgroup$ – Xin YANG Mar 12 '18 at 4:51
2
$\begingroup$

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. 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, 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. 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.

$\endgroup$
1
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ can i use "glViewportArrayv(ARB_shader_viewport_layer_array)" to reach the goal? $\endgroup$ – Xin YANG Mar 12 '18 at 0:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.