This allows us to have different camera positions and projections for the different layers, making it possible to render from both eye positions in a VR application with one draw call. The shader takes in an array of view projection matrices (view and projection matrices multiplied together), instead of just one, and selects the matrix to use by indexing with gl_ViewID_OVR which gives the index of the current texture layer being rendered to. This number needs to be the same as the number of views attached to the framebuffer using glFramebufferTextureMultiviewOVR. It enables the GL_OVR_multiview extension and sets the num_views variable in the layout to 2. Only the vertex shader contains multiview specific code.
#Particle illusion matrix code#
The following code shows shaders used for multiview rendering. Using multiview in shaders to render to several layers Similar code can be used for checking for the GL_OVR_multiview2 or GL_OVR_multiview_multisampled_render_to_texture extensions if needed. Setting up a multiview framebuffer objectīefore using the extension, one should check that it is available, this can be done with the following code, which looks for the GL_OVR_multiview extension. Rendering to multiple layers with only one draw call can also potentially be done using layered geometry shaders, but this presents a much larger overhead compared to using the multiview extension as geometry shaders are very demanding on performance and multiview is a fixed function solution which allows many internal optimizations compared to geometry shaders. Using this mechanism, an array of view and projection matrices can be used instead of a single matrix, and the shader can choose the right matrix for each layer using gl_ViewID_OVR, allowing one draw call to render from multiple eye positions with little overhead. The vertex and fragment shaders are then invoked once for each texture layer in the attached array texture, and have access to the variable gl_ViewID_OVR which can be used to select view dependent input for each layer.
The GL_OVR_multiview extension adresses this issue by allowing one draw call to render to multiple texture layers of an array texture, removing the overhead of setting up multiple draw calls. Doing this by simply rendering everything twice with different view and perspective matrices is not optimal, as it requires setting up a mostly identical draw call multiple times. Virtual reality applications need to render all their scenes twice from different view angles in order to create the illusion of depth. What is multiview rendering and why is it useful? Using multiview rendering also restricts you from using geometry and tessellation shaders.
Details on thess extensions can be found here and here. The extension GL_OVR_multiview_multisampled_render_to_texture is also useful as it allows multiview rendering to multisampled textures. Only the GL_OVR_multiview extension is required by this tutorial, as we only change the gl_Position output based on the view index in the sample code.
The extension GL_OVR_multiview2 removes this restriction, making it much more useful as lighting might depend on the position of the camera. This extension is however limited so that only the output gl_Position can depend on the view index. Warning In order to use multiview rendering the GL_OVR_multiview extension is needed.