Fast Rendering of Caustics using Photon Mapping and Texture Maps

D. Narayan Brooks - nbrooks@cse.ucsc.edu

Computer Science Department, UC Santa Cruz

CS 260 - Prof. Alex Pang

June 4th, 2002

 

 

Abstract

 

There is a lot of momentum behind fast generation of realistic and highly detailed 3D computer scenes.  As the scenes grow in complexity, the lighting of the scene seems to fall behind due to its computationally intensive nature.  As more algorithms are being implemented in hardware, fast rendering of different lighting models is becoming more feasible.  Caustics are a valuable technique in adding realism to the lighting in a scene.  The very nature of caustics makes them amenable to ray tracing techniques.  Capturing the caustics in a view independent manner becomes important for fast scene rendering.  This paper presents a hybrid approach to caustic generation and rendering that results in efficient and accurate results.

 

1.      Introduction

 

The visual impact of a computer-generated scene is highly dependent on the lighting used in the scene.  Approximating realistic lighting phenomenon in computer graphics scenes creates a more compelling and engrossing viewing experience.  The human eye is very adept at pinpointing visual discrepancies from what we see on a daily basis, especially when it comes to lighting.  Visual discrepancies in lighting may be very subtle but will play an important role in how a scene is perceived.  The perception that something is amiss may even be subconscious.  Lighting plays a very dramatic role in the mood and believability of a scene, which is why lighting discrepancies can cause the viewer to lose their current suspension of disbelief when viewing computer-generated scenes.   Many of the lighting cues we perceive can be rather subtle.

Approximating the intricate play between lights and the 3D surfaces in a scene is a computationally intensive process.   The lighting process needs to be efficient while maintaining an acceptable depiction of lighting phenomena.  The basic computer lighting model can be broken down into three components: diffuse, specular, and ambient.  The ambient component of the light is just a constant intensity.  It keeps areas from being completely dark in the absence of direct light.  The diffuse component represents the view independent surface color of the object, the base color of the object without any shininess.  Both the diffuse and ambient components are fairly straightforward to implement in computer graphics and are thoroughly covered in most graphics texts.  There has been research in global illumination to try and achieve more accurate diffuse lighting models, the most successful approach being radiosity.

The specular term is a little trickier to compute because it involves reflections, secondary illumination and view dependence.  Most graphics APIs provide a very basic view dependent approach to handling specular, where the light intensity increases around the incident light point.  This approach only accounts for the view dependence of shiny surfaces.  Reflections and secondary illumination are not covered by this approach, leading researchers to create new techniques for capturing the specular component of lighting.  The basic premise is ray tracing: shoot rays from light sources or the eye, and then trace these rays as they are reflected, refracted and absorbed in the scene. 

Caustics are an indirect specular lighting phenomenon that adds realism to the lighting in the scene.  Visually caustics are distinct areas of high light intensity that appear much brighter than the neighboring areas.  This is caused by light refraction focusing the light into certain areas.   Like most specular phenomena, caustics can be computationally expensive to calculate.  The traditional method of shooting rays from the eye into a scene will not accurately capture caustics, because caustics are dependent on light bending.  For this reason, caustics are usually computed by tracing rays from the light source to objects, known as backwards ray tracing.  Photon Mapping is a method that has proven successful capturing caustics [Jensen95].  In its full implementation, photon mapping is a very good approximation of both specular and diffuse lighting components.  Photon mapping can efficiently capture lighting in general, and caustics in particular.  The rendering stage of photon mapping is usually implemented with a distributed or Monte Carlo ray tracer.

In this paper I present a hybrid method of photon mapping and texture mapping to efficiently capture and render caustics.  I use the particle tracing and density estimation strategies of photon mapping combined with a standard z-buffer renderer.  The key idea is that caustics are view independent, they only depend on the relationship between the objects and the light.  This allows them to be pre-computed before the scene is rendered, as long as the light is stationary.  If the relationship between the light and the object changes, then the caustics need to be updated, resulting in latency in the rendering.  To leverage the view independence of caustics, I capture them in an object specific illumination texture map.  The resulting textures are then used during the standard z-buffer rendering method, which can be accelerated by general graphics hardware.


2.      Previous Work


There has been a lot of research in global illumination with the end goal of creating realistic lighting depictions in complex scenes in the most efficient manner.  There have been many techniques and modifications of techniques to optimize and capture all different types of lighting. 

 

Whitted ray tracing was introduced in the 80’s as a more realistic approximation of light interacting with surfaces, capturing reflections and specular components well, but lacking in diffuse approximation.  Ray tracing is recursive by nature so it can be very expensive.  Backwards ray tracing was introduced later by Arvo to deal with shadows and indirect illumination.  Radiosity was developed as an alternative to the sharp images created by ray tracing and dealt exclusively with the diffuse components of the lighting model.  Many hybrids of the two major techniques, ray tracing and radiosity, have been developed to compensate for the failings of each technique.  Jensen used photon mapping in ’96 to achieve global illumination capturing diffuse and specular aspects, especially caustics.  Jensen’s photon mapping method is a two-pass method.  The first pass determines the view independent caustics and illumination and is used to augment the second rendering stage.  The rendering stage is usually a ray tracing stage, which can be expensive.  The method that I am proposing uses Jensen’s photon mapping first stage and then renders using the z-buffer method.  This is a little less general than Jensen’s method but is more efficient to render.  The method I am proposing is useful mostly for polygonal representations.


Fig 1. 512 x 512 Caustic texture on a Fournier-Reeves surface


3.      Caustics

 

The interaction between lights and surfaces creates interesting patterns of light intensity.  Caustics are a result of secondary illumination where light is focused into areas of high intensity.   Caustics usually occur when light passes through translucent liquid media.  An example of caustics is the sinusoidal patterns seen on an object when it is submerged under water.   Caustics are caused by light refraction and specular reflection.  In refraction light bends when it encounters different mediums, focusing the transmitted light.  Specular reflection causes caustics by light reflecting from specular surfaces and illuminating diffuse surfaces.  Caustics play an important role in conveying the realism of the lighting in a scene, but they are usually subtler than shadows and reflections.  When two mediums intersect, light will refract based on Snell's Law:


 
N1   =    sin(q1)

N2         sin(q2)

N1 is the index of refraction for the medium that the ray is coming from and N2 is the index of refraction for the medium that the ray is entering.  q1 is the incident light angle in reference to the surface normal at the intersection point and q2 is the transmitted angle of refraction.



Fig 2. Ray refraction


4.      Photon Mapping


One approach to global illumination is Photon mapping [Jensen95] which can capture the specular and the diffuse components of the lighting model.  The idea behind photon mapping is to efficiently store light intensity on surfaces as incoming flux.  Photon mapping is a two-stage process where the first phase emits photons from a light source and records where these photons hit the surfaces in the scene.  The second stage renders the scene using the captured photon’s information.  The stored photons are used to approximate light flux on a surface based on the density of photons present on the surface.

The first stage of photon mapping involves particle tracing.  Particles of energy photons are emitted from a light source along a ray.  Each photon carries some of the lights energy, as well the direction the photon was emitted from.  When the photon intersects a polygon or surface the photon is inserted into a photon map.  The photon is then absorbed, reflected or refracted based on some random distribution.  If the photon is not absorbed, then it is emitted from the surface based on the normal and bi-directional reflectance distribution function (BRDF).

The photon map is a 3D spatial structure that records photon hits based on location.  The information that it stores is the location of the hit, the energy of the photon, and the direction it was incident upon the surface.  The common data structure used is the KD tree [Weiss00].  A balanced KD tree will speed up search times in the later rendering phase.  There are usually two photon maps used for global illumination.  One is a high-resolution map, used for directly visualizing the caustics, and another is a lower resolution map used to augment the rendering stage.

The second stage of photon mapping is the rendering stage.  In this stage the recorded photons in the tree are used to augment the rendering.  When rendering caustics, the high-resolution photon map is visualized directly.  The low-resolution map is used to limit the recursion depth of ray tracers by substituting the photon energy at a point that would have a secondary reflection.


5.      Description


In this paper I present a method for efficiently visualizing caustics that result from refraction.  Traditionally photon mapping has involved ray tracing in the rendering stage, which can be a computationally expensive process.  To make the rendering stage more efficient I use hardware z-buffer rendering with texture mapping.  To do this the caustics need to be stored in a texture map and then applied to the objects that they affect.  This limits the algorithm to handling polygonal models that can be texture mapped.  The photon tracing stage is performed as Light Path Tracing as in previous photon mapping implementations.


5.1.   Setup


For this paper a scene consists of a group of 3D objects.  Each object is a collection of polygons, called elements, which share vertices.  The elements contain color (irradiance energy) and normal information, which is obtained from the vertices.  Each element also has a refraction index, which is constant per object, but does not have to be.  The light in the scene is a directional light that is represented by a grid of rays.  Each photon carries the energy of the light it came from so it has a red, green, and blue component.  The lights could be point lights as well, but directional lights emphasize the caustic effect the most.   The sample scene I used consisted of a water surface and a textured sea floor.  The water surface was computed procedurally using the Fournier-Reeves wave model.  This led to rather regular caustic patterns due to the regularity of the model.  Future work would use more irregular water surfaces to capture different caustic effects.



Fig 3. Initial setup before rendering caustics


5.2.   Path Tracing


Photons are emitted along rays from the lights.  The photon can intersect with many elements (polygons) along the path.  Each light ray is tested against every element in the scene to see if a photon traveling along that ray would intersect the current element.  When an intersection occurs the photon hit is recorded by inserting a node into a multidimensional search tree such as the KD tree.  The nodes can be thought of as photons, with each node having a position, direction, and energy.  The nodes are inserted into the tree based on position.  The algorithm is not dependent on the lights being directional as long as starting points and directions can be specified for the light rays.  I found that ~400 directional rays grouped in a grid produce acceptable results.

The ray-element intersection requires two steps.  Assuming that the elements are planar polygons, the first step determines if the ray will intersect the plane that contains the element.  The rays are parameterized by a value t that represents the distance along the ray.  If the t value returned by the plane intersection test is valid (i.e. between 0 and 1) then the test proceeds.  If t is not valid then the element is discarded and the algorithm moves on to the next element to test.  If the ray intersects the plane with a valid t, then we have to test whether or not the intersection point is within polygon.

The intersection point of the ray and the plane is determined by evaluating the ray at the parameter t.  Once this position is determined the element is projected from 3D into 2D with the projection occurring along the dominant normal axis, to minimize the loss of area during projection.  This 2D projection converts 3D space into an XY space.  A ray is the traced form the hit point along the “X” axis and is tested against each edge [Moeller99, Badouel].  The number of edge intersections is counted and if they the number of crossings is odd, then we are inside the polygon.  Other wise we are outside the polygon and we have a miss, so we move onto the next element.


5.3.   Photon Mapping

 

On a ray polygon hit we have the location of the intersection point, so we could insert the photon at this point.  Since we are only using the photons to visualize caustics we do not insert the photon into the KD tree unless the hit is a result of a refraction or reflection.  If the ray intersection was a result of a direct illumination light ray (i.e. first hit), then we refract the light ray.  The refracted light ray sends the photon on another path direction based on Snell’s law.  After refraction, we need to see if the refracted ray is intersects with any elements in the scene.  If we find a hit then we insert the photon into the KD tree, keeping track of the ray direction and the current energy. 





Fig 4. A photon mapped illumination map with refracted rays

5.4.   Texturing

            After all of the light rays and refracted rays are tested for intersections, we can build a caustic texture based on the photons in the KD tree.  The texturing algorithms must be able to know the extents of the object that is being textured because of coordinate transformations.  For each texel in the texture we determine the world coordinate of the texel by transforming texture coordinates into world coordinates based on the objects extents.  This is assuming that you are texture mapping the whole object with one non-repeating texture.  You texture each element as well, with lots of little textures, barring the texture memory limits.

            Once the world coordinates X is obtained, the N nearest photons to X need to be found.  The nearest neighbors are found by filling an array with the first N photons, keeping track of the photon, Pd, with the maximum Euclidean distance r.  For each photon P in the tree, if the distance between X and P is < r, replace Pd with P and find the new Pd.  When this process is complete we have the N nearest neighbor photons, which will contribute the most energy.  The maximum distance r will be used in calculating the intensity at the point X.  This is a form of density estimation.   I found 8-20 neighbors gave good performance.  The N nearest neighbor photons contribute to the light intensity at the current location.  The intensity is determined by using the equation:


E(X) = c*Σ( f(X, Yp, Yn ) * Ei /πr2)

The constant c can be thought of as an attenuation factor dependent on N, both user defined values.  f(X, Yp, Yn) is any BRDF supplied by the user.  I used a BRDF for Lambertian surfaces:


f(X, Yp, Yn ) = cos(Yp)

 

Yp is the photon direction and Yn is the normal of the surface [Sturzlinger97].  The calculated intensity is then added to the current base texture of the object at the texture index.

 


Fig 5. A low attenuation factor               Fig 6. A high attenuation factor


 The resolution of the texture plays a role in the efficiency of the algorithm.  A 512x512 texture can still be constructed in an efficient manner ~10 – 20 seconds.  This time is affected by the number of photons in the KD tree as well the number of neighbors need for the nearest neighbor search.  Varying the texture resolution gives different results, with a 512x512 texture producing caustics with the fewest artifacts.



Fig 7. Texture at 128x128 resolution



Fig 8. 256x256 resolution


Fig 9. 512x512 resolution


6.      Conclusion and Future Work

 

            Caustics help add realism to a computer generated scene.  Implementing them as pre-processed textures opens up a lot real-time uses.   Rendering caustics using photon mapping is an accurate and efficient technique.  The space required is smaller than the space needed to hold the geometry itself, because there will be fewer photon hits than elements. Converting the caustics to textures and rendering using the z-buffer renderer provides a very efficient, view independent alternative to the ray tracing secondary stage.  The algorithm is not real-time put it is still fast.  There are a few optimizations that could be made to make it more efficient.   Like most ray tracing algorithms the bottleneck is the intersection tests.  Using hierarchical bounding volumes or importance sampling would speed up the photon mapping part of the algorithm.  Filling the texture will still take some time unless the nearest neighbor search is sped up or am algorithm is used that can cache the neighbors found and use spatial locality of the points.  A group of texels should share the same nearest neighbor photons.  Future test scenes will be more complex, and less regular, to examine the full power of the techniques used.

 

References

[Jensen95] H. Jensen, N. Christensen. “Photon Maps in Bidirectional Monte Carlo Ray Tracing of Complex Objects”. Computing and Graphics. Vol. 19, No. 2, pp. 215-224, 1995, Elsevier Science Ltd., Great Britain.

[Jensen96] Henrik Wann Jensen. “Global Illumination using Photon Maps”. Rendering Techniques ’96 Proceedings of the Seventh Eurographics Workshop on Rendering. pp. 21-30, 1996, Springer-Verlag.

[JensenNon96] Henrik Wann Jensen "Rendering Caustics on Non-Lambertian Surfaces". In Proceedings of Graphics Interface '96, pp. 116-121, Toronto 1996.

[Jensen98] Henrik Wann Jensen and Per. Christensen, "Efficient Simulation of Light Transport in Scenes with Participating Media using Photon Maps" , Siggraph'98, pp. 311-320.

[Jensen/Cooper98] Presentation by S. Cooper based on "Efficient Simulation of Light Transport in Scenes with Participating Media using Photon Maps", 2000. http://www.cs.unc.edu/~scooper/ comp238/photonmaps.ppt

[Sturzlinger97] Sturzlinger W, Bastos R. “Interactive Rendering of Globally Illuminated Glossy Scenes”. Rendering Techniques '97. Proceedings of the Eurographics Workshop. Eurographics. Springer-Verlag. 1997, pp.93-102, 331. Wien, Austria

[Badouel] Didier Badouel. “An Efficient Ray-Polygon Intersection” Graphics Gems I

[Weiss00] M. A. Weiss, Data Structures, and Problem Solving with C++, Addison Wesley, Reading, MA.,  Second edition, 2000.

[Moeller99] Moeller, T, Haines E. Real-Time Rendering. AK Peters, LTD. Natick, MA., 1999

User's Guide