Instanced-based VR rendering in OpenGL












1















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?










share|improve this question























  • 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 8 '15 at 6: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 8 '15 at 12:44











  • I saw that regarding the geometry stage, but it's probably gonna negatively impact my performance...

    – Tuxer
    Apr 8 '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 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 8 '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
















1















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?










share|improve this question























  • 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 8 '15 at 6: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 8 '15 at 12:44











  • I saw that regarding the geometry stage, but it's probably gonna negatively impact my performance...

    – Tuxer
    Apr 8 '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 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 8 '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














1












1








1








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?










share|improve this question














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?







opengl virtual-reality geometry-instancing






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Apr 8 '15 at 6:33









TuxerTuxer

4531519




4531519













  • 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 8 '15 at 6: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 8 '15 at 12:44











  • I saw that regarding the geometry stage, but it's probably gonna negatively impact my performance...

    – Tuxer
    Apr 8 '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 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 8 '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



















  • 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 8 '15 at 6: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 8 '15 at 12:44











  • I saw that regarding the geometry stage, but it's probably gonna negatively impact my performance...

    – Tuxer
    Apr 8 '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 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 8 '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

















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 8 '15 at 6:48





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 8 '15 at 6:48




1




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 8 '15 at 12:44





@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 8 '15 at 12:44













I saw that regarding the geometry stage, but it's probably gonna negatively impact my performance...

– Tuxer
Apr 8 '15 at 15:25





I saw that regarding the geometry stage, but it's probably gonna negatively impact my performance...

– Tuxer
Apr 8 '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 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 8 '15 at 18:14







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 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 8 '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





That would be perfect actually, if I wasn't running on an NVIDIA chip :-'

– Tuxer
Apr 10 '15 at 21:25












1 Answer
1






active

oldest

votes


















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






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f29507534%2finstanced-based-vr-rendering-in-opengl%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    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






    share|improve this answer






























      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






      share|improve this answer




























        0












        0








        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






        share|improve this answer















        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







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 20 '18 at 9:31









        Moritz

        57.6k19131184




        57.6k19131184










        answered Nov 20 '18 at 9:24









        ImQ009ImQ009

        120312




        120312






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f29507534%2finstanced-based-vr-rendering-in-opengl%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

            SQL update select statement

            'app-layout' is not a known element: how to share Component with different Modules