Wed, 07 Nov 2012 08:25:56 +0000 en-US hourly 1 Real-time Environment Mapping in OpenGL Tue, 09 Aug 2011 16:43:27 +0000 Environment Mapping, also known as Reflection Mapping is an efficient technique for simulating realistic reflections. In many cases a precomputed texture is rendered on the object which represents the environment surrounding scene.

The following image is an example from Wikipedia:


And the next is an environment mapped teapot it a room which “matches” the reflection texture:


While the classic static environment mapping looks awesome in a scene, perhaps with a rotating object as the reflective target, it is sightly lacking in challenge as with OpenGL it can be done rather easily. A common example will include a skybox and an object with the reflection cube-mapped onto the focal object.

For my prototype I wanted to create a reflective cube that in real-time could demonstrate environmental reflection. With such a system it would be fairly trivial to use the dynamically generated texture to make many simple objects appear reflective using cube mapping.

For those who just want to see the video, it is embedded below:

For others who want details, read on…

The small cubes and the ‘room’ surrounding the cube rotate at different speeds and distances to demonstrate the reflection. The yellow sphere represents the light source which is applied using a basic per-pixel fragment Shader. From some angles the reflection clearly shows the lighting application and the reflected faces of the orbiting cubes move from shadow to light.

The texture for each face of the cube is generated and applied independently. For each frame all movement calculations are carried out once, then the scene is rendered to a Frame Buffer Object (FBO) 6 times, once for each face of the cube. It is then rendered once more from the point of view of the observer, this time to the screen. The camera is positioned at the centre of the cube looking though a specific face and the scene is rendered. The camera uses a 90 degree field of view to capture the image the cube face should reflect whereas the camera used to observe the scene has a 45 degree field of view.

Currently for each frame the textures for all 6 sides are generated and rendered at quite a high resolution. If performance became an issue then only the sides visible to the camera could be considered and a lower resolution texture could be generated.

I also made a variation where the Shader mixes the result of the lighting calculations on the main cube with the texture to give the appearance of a slightly matted reflection.

]]> 0
Network Based Scene in OpenGL Sun, 07 Aug 2011 08:25:00 +0000

This scene is rendered identically on two computers with a TCP server sharing the scene data. A cube created on any client is shared with all other clients.

More details coming soon…

]]> 0
Rescue from ‘execution expired’ in Ruby Thu, 04 Aug 2011 21:55:26 +0000 e # This will NOT catch 'execution expired' !! puts "Rescue : #{e}" rescue Timeout::Error => te # […]]]> Today I was trying to rescue from an ‘execution expired’ error when using another colleagues gem (which interfaces with an XML RPC API).

Thankfully I found this snippet at

        # do something involving Net:HTTP
      rescue => e
        # This will NOT catch 'execution expired' !!
        puts "Rescue : #{e}"
      rescue Timeout::Error => te
        # This explicit rescue will work
        puts "Rescued from timeout : #{te}"

Hopefully this will save someone a bit of time :).

]]> 0
Continuous Terrain Generation Wed, 03 Aug 2011 08:07:29 +0000

I saw this done for a dissertation and decided to try it for myself. The height map is generated on the fly based on the last data known to create a smooth variation.

More details coming soon…

]]> 0
Hierarchical Quadratic Mesh Mon, 01 Aug 2011 08:03:55 +0000

Taking the Hierarchical Triangular Mesh prototype further, with a quadratic version texturing is easier using a skybox-like texture.

More details coming soon…

]]> 0
Hierarchical Triangular Mesh Thu, 28 Jul 2011 08:00:00 +0000  


A HTM based sphere generation prototype, each primitive is approximately the same size and therefore it does not suffer from any singularities.

More details coming soon…

]]> 0
OpenGL World Generation Mon, 25 Jul 2011 07:56:00 +0000

This prototype procedurally generates and textures a sphere to that it looks like the earth. Unfortunately it suffers from polar singularities, where the vertices for all the longitudinal slices meet and cause a dithering artefact on the screen.

More details coming soon…

]]> 0