VR Shaders

From Virtools Wiki

Jump to: navigation, search


Special care has to be taken when writing a composition that uses shaders for the VR Library. The shaders in themselves don't need any specific attention, but the composition that uses them must make some accomodations. If you have any feedback on this topic or this article please let us know!

Contents

Cubemaps

The VR Set Stereo Texture BB will simply assign a different texture to a material depending on which eye is being rendered. It works in active or passive stereo. It does nothing more than that.

Generally when you create a cube map used for reflections, you only need to render it once. As the stereo camera is offset automatically to render left and right eyes, the effect of the cube map should be correct automatically : 1 cube map, two different eye positions > two different correct renderings with correct reflections based on the offset viewpoints.

But if you want to use a real stereo cube map, you simply have to assign the two textures to the cube map material with the VR Set Stereo Texture BB.

As the BB only changes the texture of a material it won't change any shader parameter.

Notes on VR Cameras

If you use the model view matrix or the projection matrix in your shader, you will have the correct camera position and orientation, modified to have the correct stereo effect. Virtools cameras in themselves are not aware that they are stereo cameras, nor that their frustum should be constrained to the projection referential. So when scripting you ask for the camera position or orientation, you will have the *uncorrected* position and orientation.

The modification is done just before rendering, and it's those modified matrices that are passed on to the shaders. That's why you should get the correct camera position, orientation and asymmetric projection matrix in the shaders.

Position dependant shaders

Shaders like reflection shaders that render the reflection texture by mirroring the camera need to be computed correctly for each eye. If you do only one render for both eyes, the reflections will be wrong for at least one eye, probably two.

You have to do two Render-to-texture, one for each eye. For each render, you have to offset manually the reflection camera by half the interpupillary distance to match the stereo offset.

In a monoscopic composition, you would simply apply the texture from the Render-to-texture to the reflection material.

In a stereoscopic composition, you get two different textures to apply to the same material, a different one for each eye. You can achieve this by using the VR Set Stereo texture BB that applies a different texture to a material depending on which eye is being rendered.

NB: It should also be noted that the orientation of a camera that has a ProjRef isn't taken into account when doing its rendering. The frustum will always be aligned with the ProjRef independantly of the camera orientation. This should only be a scripting problem, not directly a shader problem. The shader should get the correct matrices, camera position and orientation.

Post-processing shaders

Post-processing shaders like a Bloom shader compute their effect based on the size of the viewport. In a multi-screen environment, this would cause the effect to be non-contiguous at the screen seams.

Thus you need to create the effect based on a bigger viewport than the real viewport, then only display the part that fits the viewport rectangle.

This will help reduce the seams artifacts.

Personal tools
The Swap-Meet