Reflective Sphere

Analytical reflections in OpenGL

Articles

This renders non-reflective objects in a first pass, then uses reverse reflection mapping to transform objects to their reflected positions inside the sphere for a second rendering pass. There is no closed formula for working out the reverse reflection (this involves solving a quartic) so an iterative aproximation is used instead.

The floor is reflected using a different method, by raycasting reflected rays at each vertex of the sphere mesh and finding the co-ordinates of intersection with the ground plane, then using that to map the ground texture directly onto the sphere.

Here is a short clip of the code in action:

Flash, played by Ruffle. demo.swf

Source 19 files