Who needs Strings when you got magic balls

By Young-Jun Ko

Video

The following topics were implemented:

  1. Multithreading:
    Multithreading using POSIX threads was implemented on a per image basis, i.e. each image is split into blocks of predefined size (e.g. 32x32 pixels) which is supposed to be more cache efficient and then renderered by threads requesting the next chunk from a synchronized data source. Also frand() was replaced by the thread safe random number generator drand48_r() maintaining its state locally for each thread.


    Comparison of rendering times:

    Measured on Intel Core2Duo T7500 2.2 GHz, 2GB RAM, Ubuntu Linux 7.10 (2.6.22-14)
    Threads 320x256 800x600
    1 24 sec 146 sec
    2 14 sec 72 sec


    Source Code:
    ImgChunkManager.hxx Responsible for splitting the image into chunks of predefined size. Acts as synchronized producer
    ImgChunkManager.cxx
    RenderingWorker.hxx Represents a thread that consumes chunks of the image as supplied by the ChunkManager
    RenderingWorker.cxx


  2. Photon Mapping:
    This feature was implemented following the description found in "Realistic Image Sythesis using Photon Mapping" by Hendrik Wann Jensen. In short, a two pass algorithm is used. The first pass samples photons from the light sources into the scene. The surface a photon hits determines how it is treated, e.g. stored in a data structure called photon map or propagated in case of specular surfaces. Compared to other techniques photon mapping can be a very efficient global illumation methodology, especially to capture optically appealing effects such as caustics, which to render was a major goal of this project. In order to achieve high quality caustics, a large number of photons specifically dedicated to caustics are cast towards caustic generating objects (e.g. specular reflection/transmission) and maintained in a separate caustics photon map. The second pass is the rendering pass which applies traditional ray tracing methods. On non specular surfaces the globally induced radiance can be estimated using the photon maps.
    As this is an inherently stochastic process, in some parts of the animation noise becomes obvious which could only be partially removed.
    For the high quality scene 100.000 photons were used for the caustics evenly shared between the caustic generating objects and 200.000 were used globally

    Screenshot: Caustics


    Source Code:
    photonmap.hxx Photon map data structure to store photons and process queries
    photonmap.cxx
    photontracer.hxx Generates the photon maps for the scene
    photontracer.cxx


  3. Reflective and Refractive Transparency:
    The spheres in the scene simulate the refractive and reflective properties of glass. A portion of the light that hits the surface is transmitted and another is reflected depending on the actual composition of the material and the incoming angle. The amount of transmitted and reflected light can be approximated by the Fresnel formula for di-electric materials. The reflection is perfect specular and the resulting direction and is calculated as such. The direction of the refracted light is calculated using Snell's law.
    For photons that pass such materials Russian Roulette was applied parameterized by the Fresnel coefficient to decide whether a photon is transmitted or reflected.

    Screenshot: Fresnel term based reflection


    Source Code:
    FresnelShader.hxx A shader for refractive and reflective materials


  4. Dispersion:
    Depending on material properties and its wavelength light is refracted differently. The refractivity can be determined using the Sellmeier approximation which is a function of wavelength and some material constants([Wilkie]). For photons passing the glass one photon with one of eight wavelengths is generated using Russian Roulette and cast into the respective direction. It is assumed that each wavelength is equally probable to be chosen.
    During the rendering pass each ray hitting such a surface results in sampling the respective wavelength component of three directions for red, green and blue. The refractive index for the sample wavelengths in the rendering pass are determined stochastically by choosing a random offset within the range of the wavelength for one color.

    Screenshot: Dispersion (zoomed in)


    Source Code:
    FresnelShader.hxx A shader for refractive and reflective materials with dispersion


  5. Volume Rendering (Experimental/Incomplete):
    It was attempted to support participating media using a separate volume photon map.
    For this purpose techniques described in [Jensen] and [Pharr] were implemented:
    During the photon tracing pass photons are scattered multiple times once they enter a region of participating media. Scattering is terminated using Russian Roulette parameterized by the extinction coefficient of the medium. To determine the scattered direction Schlick's computationally efficient approximation to the Henyey-Greenstein phase function is used. Only photons scattered more than once are stored as the effect of direct illumination should be computed using traditional ray tracing (casting rays towards the light sources).
    During the rendering pass ray marching is used to probe the density of the medium. At each step an irradiance estimate from the photon map together with direct illumination (which is attenuated according to the distance the light ray travels through the medium) are combined.
    As can be seen there are strange artifacts which I could not get rid of in time.

    Screenshot: Volume Rendering


    Source Code:
    VolumeShader.hxx Responsible for marking rays passing through participating media so that they can be treated accordingly
    VolumeRenderer.hxx Responsible for scattering and storing photons within the volume region and for performing the ray marching during the rendering pass



The grid texture of the floor was taken from the accompanying resources of [Pharr].

References:
[Jensen] - H. Wann Jensen, "Realistic Image Synthesis using Photon Mapping"
[Pharr] - M. Pharr, G. Humphrey, "Physically Based Rendering"
[Wilkie] - A. Wilkie, R. Tobler, W. Purgathofer. "Raytracing of Dispersion Effects in Transparent Materials"
http://www.yolinux.com/TUTORIALS/LinuxTutorialPosixThreads.html