In recent versions of GeeXLab, I added the support of reflections (mirror, surface water for example). Here is how to do a reflection with GeeXLab:
- Create a perpective camera
- Create a render target
- Create a mirror object (a plane for exemple)
- Create the 3D objects (torus, etc.)
- Update the reflection matrix of the camera with the plane equation of the mirror object
- Render the scene to the render target
- Reset the reflection matrix of the camera
- Render the scene normally, the mirror object is simply textured with the render target color texture
Reflections are supported by all versions of GeeXLab: Windows, Linux, Mac OS X and Raspberry Pi.
Let’s see some details.
The render target can be created with this code:
local linear_filtering = 1 local clamp_addressing = 1 local samples = 0 local create_depth_texture = 1 local PF_U8_RGBA = 3 local PF_F32_RGBA = 6 rt01 = gh_render_target.create_ex_v4(winW, winH, 1, PF_U8_RGBA, linear_filtering, clamp_addressing, samples, create_depth_texture)
The update the reflection matrix of the camera (in the FRAME script) is done with (where mirror_plane is the mirror object):
local a, b, c, d = gh_object.get_plane_equation(mirror_plane) gh_camera.set_reflection_matrix_v2(camera, a, b, c, d) gh_camera.bind(camera)
The reset of the camera reflection matrix is done with:
A complete demo is available in the host_api/Reflection/ folder of the code sample pack. You can download the code sample pack from THIS PAGE. It’s an OpenGL 3.2 demo and it works on Windows, Linux and OS X. To make it work on the Raspberry Pi, just convert the GL 3.2 shaders to GLES 2.0 shaders (if you really need this, let me know).