Introduction to VR Programming with GeeXLab

GeeXLab 0.14+ comes with a very cool feature: the support of Virtual Reality (or VR for the impatient!) via the use of the OpenVR library. OpenVR functionalities are accessible in Lua and Python via the OpenVR plugin of GeeXLab (plugin_gxc_openvr_x32.dll or plugin_gxc_openvr_x64.dll on Windows platforms). Currently only Windows platforms are supported, but I can build the Linux 64-bit version if necessary (and I will certainly build it in the future). I tested the OpenVR plugin with the HTC Vive headset. I don’t know if it will work with the Oculus Rift but according to what I read on the Net, it should work.

Virtual reality… VR is very cool, especially for a graphics programmer. Why? Because for the first time, the graphics programmer can visit the 3D world that he’s programming. Even the simplest 3D object, the triangle, is an amazing spectacle the first time you see it through the VR headset. The RGB triangle (RGB because it’s nicer) is there, in front of you, and you can walk around it, you can almost touch it… like it was really there. You are in the matrix!

Here’s the hello world of VR programming: the RGB triangle:

and just for fun, here is a close-up of the right eye of the HTC Vive headset:

Programming VR in GeeXLab is quite simple. Basically, you need for each eye:
– one perspective camera
– one render target

You also need functions of the gh_vr library that is available in Lua and Python.

The size of the render target for each eye can be get with gh_vr.get_recommended_render_target_size(). For the HTC Vive, the size of a render target is 1512×1680 pixels.

Here are the 4 steps to render a scene in VR:
1/ update the left and right cameras with gh_vr.update_cameras()
2/ render the world from the point of view of the left camera into the render target of the left eye.
3/ render the world from the point of view of the right camera into the render target of the right eye.
4/ send both render targets to the HMD (Head Mounted Display) using gh_vr.submit().

The principle is simple. The practice with GeeXLab too. Here is the INIT code (Lua) for the RGB triangle demo: