Reflections in GeeXLab



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:


INIT script:

  1. Create a perpective camera
  2. Create a render target
  3. Create a mirror object (a plane for exemple)
  4. Create the 3D objects (torus, etc.)

FRAME script:

  1. Update the reflection matrix of the camera with the plane equation of the mirror object
  2. Render the scene to the render target
  3. Reset the reflection matrix of the camera
  4. 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:

gh_camera.reset_reflection_matrix(camera)
gh_camera.bind(camera)

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).


GeeXLab - reflections





Leave a Comment

Your email address will not be published. Required fields are marked *