I'm trying to use instancing to do VR rendering in OpenGL with 1 draw call, 2 instances (one for left eye, one for right eye). The vertex shader then translates the vertices left for instanceID 0 and right for instanceID 1. The only thing I need more is per-instance viewport for automatic hardware culling/clipping. This is doable in directX but is it in OpenGL?
Asked
Active
Viewed 925 times
1
-
I don't think you can have a per instance viewport (although there are other ways of doing per instance clipping). Out of curiosity, what's your DirectX solution? – Jerem Apr 08 '15 at 06:48
-
1@Jerem: As of OpenGL-4 you can. The geometry shader stage allows to specify the FBO layer or/and viewport toward which a primitive is sent for rasterization. See the section `Layer and Viewport Selection` of any OpenGL-4 specification. – datenwolf Apr 08 '15 at 12:44
-
I saw that regarding the geometry stage, but it's probably gonna negatively impact my performance... – Tuxer Apr 08 '15 at 15:25
-
Well, the actual performance impact that will have in the OP's scenario is quite unclear. Currently, when doing this, there is no way around the geometry shader for stock GL. There is the [GL_AMD_vertex_shader_viewport_index](https://www.opengl.org/registry/specs/AMD/vertex_shader_viewport_index.txt) GL extension which would suit the OP's needs ideally. But it is a vendor-specific extension, currently. Maybe it will be added to core GL later on, but I wouldn't bet on it. – derhass Apr 08 '15 at 18:14
-
That would be perfect actually, if I wasn't running on an NVIDIA chip :-' – Tuxer Apr 10 '15 at 21:25
-
https://docs.google.com/presentation/d/19x9XDjUvkW_9gsfsMQzt3hZbRNziVsoCEHOn4AercAc/edit#slide=id.g5791d9ed1_015 – elect Sep 15 '16 at 13:03
1 Answers
0
Recently I was actually implementing instanced stereo rendering for VR and had the same problem. I had the choice of using geometry shader for instanced viewports but I didn't want the overhead it'd introduce. So, in the end I ended up shifting the perspective for each view and using a clip plane.
So that's probably what you're looking for, a clip plane. It's really simple to implement in a vertex shader too, you just pass the 'x' coord into gl_ClipDistance. https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/gl_ClipDistance.xhtml
Good luck