Keywords: main

Next: 1.25 Global Illumination.1 Up: 1. Functionality Previous: 1.23 Memory-mapped Textures
Subsections

- 1.24.1 Light Sources
- 1.24.2 Objects
- 1.24.3 Material Shaders and Photon Shaders for Caustics
  - 1.24.3.1 Physically Plausible Material Shaders
- 1.24.4 Shader Functions
- 1.24.5 Fine-tuning Caustics

# 1.24 Caustics

Caustics are light patterns that are created when light from a light source illuminates a diffuse surface via one or more specular reflections or transmissions. Examples are:

- The light patterns created on the bottom of a swimming pool as light is refracted by the water surface and reflected by the diffuse pool bottom.

- Light being focused by a glass of water onto a diffuse table cloth.

- The light emanating from the headlights of a car: the light is emitted by the filament of a light bulb, reflected by a parabolic mirror reflector (thereby being focused in the forward direction), and reflected by the diffuse road surface.

Caustics cannot be simulated efficiently using standard ray tracing since predicting the potential specular paths to a light source from any given surface is a difficult (and in many situations impossible) task. To overcome this problem mental ray uses a photon map.1.5 The photon map is generated in a preprocessing step in which photons are emitted from the light sources and traced through the scene using photon tracing.

The emission of photons is controlled using either one of the standard photon emitters for point lights, spot lights, directional lights, and area lights, or by using a user defined photon emitting shader.

A photon leaving the light source can be reflected or transmitted specularly by objects. The photon is traced through the scene until it either hits a diffuse surface or until it has been reflected or transmitted a maximum number of times as indicated by the photon trace depth. When a caustic photon hits a diffuse object it is stored in a caustic photon map and not traced any further.

To control the behavior of photons as they hit objects in the scene, it is necessary to attach photon material shaders to these objects. Photon material shaders are similar to normal material shaders with the main difference being that they trace the light in the opposite direction. Also, a photon shader distributes energy (flux) instead of collecting a color (radiance). Another important difference is the fact that photon material shaders do not need to send light rays to sample the contribution from the light sources in the scene.

In order to use the photon shaders, it is necessary to include the appropriate shader declaration file, such as `physics.mi` for physics-based material shaders and photon shaders from the physics shader library in the standard distribution.

To turn caustics on, specify `caustic on` in the `options` or use the command-line option `-caustic on`.

## 1.24.1 Light Sources

Photons are emitted from the light sources in the scene. It is necessary to attach some extra information to each light source to control the energy being distributed into the scene (and/or the number of photons emitted).

To generate caustics from a particular light source, one must specify the energy emitted by the light source. This is given by the energy keyword. The energy is the flux distributed by the light source and it will be distributed into the scene by each photon which will carry a fraction of the light source energy. If the energy is zero (the default), no photons will be emitted.

Another important factor is the number of photons to be generated by this light source. This can optionally be specified using the caustic photons keyword (10000 photons is the default). This will be the number of photons stored in the photon map and thus a good indication of the quality of the generated caustics. It is also a direct indication of the memory usage which will be proportional to the number of photons in the photon map. For quick, low-quality caustics, `caustic photons 10000` is adequate, for medium quality 100000 is typically needed, and for highly accurate effects, `caustic photons 1000000` can be necessary. It is also possible to specify a second integer, which is the maximum number2.1of photons to be emitted from the light source, or only the number of emitted photons by setting the first integer to zero (mental ray 2.1.37 and up). By default there is no upper limit (indicated by the value 0), in which case emission will continue until the specified number of photons have been stored. Notice that the emitted number of photons and the preprocessing time is most often proportional to the number of photons generated in the photon map.

For most light sources, the distribution of energy using photons will give the natural inverse square fall-off of the energy. This might be an unwanted effect since some light shaders implement a linear fall-off. It can be avoided by using the exponent keyword. If the exponent is p, the fall-off is 1/rp, where r is the distance to the light source. Exponent values between 1 and 2 make the indirect light less dependent on distance. Exponents of less than 1 is not advisable, as it often gives visible noise. Exponent 2 is the default.

The following is an example of a light that uses the `soft_point` light shader and is capable of generating caustics:

         light "caustic-light1" "soft_point" (
               "color"       1.0 1.0 0.95,
               "shadow"      on,
               "factor"      0.6,
               "atten"       on,
               "start"       16.0,
               "stop"        200.0
            )
            origin           20.0 30.0 -40.0
            energy           700 700 700
            caustic photons  100000
            exponent         1.5
         end light

An example of a light source which uses the inverse square fall-off to compute illumination (and the default 10000 photons) is:

         light "point1" "physical_light" (
               "color"       700.0 700.0 700.0
            )
            origin           20.0 30.0 -40.0
            energy           700 700 700
         end light

It is important to note the difference between `color` and `energy`. `color` is the power of the direct illumination, while `energy` will be the power of the caustic. It is therefore possible to tune the brightness of caustics to make them more or less visible.

If area light source information, such as a `rectangle` statement, is added to the light source definition, both the direct and global illumination will be emitted from an area light source. This tends to make caustics more fuzzy.

To emphasize caustics, the energy of the light sources can be higher than their colors (that determine the direct illumination). If, for whatever reason, the user wants to have the sources of caustics to be at different positions than the sources of direct illumination, this is possible too. It might also be that a single light source is sufficient for the caustics, while several light sources are needed to fine-tune the direct illumination.

## 1.24.2 Objects

By default, all objects can cast and receive caustics, that is, photons are emitted in all directions from a point light source (and with all possible origins for a directional light source). For some scenes, this is fine - for example if a point light source is surrounded by specular surfaces. But for some scenes, it is very inefficient - for example a point light far away from a single small specular object.

To generate caustics more efficiently in such scenes, objects can be flagged such that the photons are only emitted towards certain objects and stored only on selected objects. Objects are then divided into caustic-casting (`caustic 1` flag) and caustic-receiving (`caustic 2` flag), or both (`caustic 3` flag), or neither (`caustic 0` flag). For example, caustics on the bottom of a swimming pool require a caustic-casting water surface and a caustic-receiving pool bottom. Objects can also be flagged `caustic off`, which means that caustic photons will not hit them at all (the objects will be ``invisible'' to caustic photons), or flagged `caustic on` which is the same as `caustic 3`. The caustic mode is an object attribute. Photons are emitted only in the direction of caustic-casting objects, and only stored on caustic-receiving objects.

To use this optimization requires that the default object caustic flag (specified in the options) is set to something different than 3 (which is the default value, enabling all objects to cast and receive caustics).

For example, the options can contain

         caustic on
         caustic 0

The definition of a caustic-casting object can for example begin as

         object "revol4"   caustic 1   visible   shadow   trace   tag 13

The material of a caustic-casting object has to be mainly specular (little or no diffuse reflection), and for most materials, the sum of reflection and transparency should be close to or larger than 1. For caustics generated by refraction, the index of refraction has to be different from 1. For example, the index of refraction for water is 1.33, for glass 1.5 to 1.7, and for diamond 2.42.

## 1.24.3 Material Shaders and Photon Shaders for Caustics

mental ray comes with three material shaders that support caustics (and global illumination2.1) soft_material, dgs_material and dielectric_material. Their photon shader equivalents are soft_material_photon, dgs_material_photon and dielectric_material_photon. When defining a material it is necessary to specify both the regular material shader and the photon shader. Most often, however, the photon shader can inherit the parameter setting from the regular material shader. In addition to these six shaders, users can write new material and photon material shaders.

### 1.24.3.1 Physically Plausible Material Shaders

A pair of material shaders that emphasize physical accuracy are `dgs_material` and `dgs_material_photon`. They simulate three types of reflection:

- diffuse (Lambert's cosine law),
- glossy (isotropic or anisotropic),
- specular (mirror),

as well as the corresponding types of refraction and translucency, and any combination of these. Therefore, they can simulate mirrors, glossy paint or plastic, anisotropic glossy materials such as brushed metal, diffuse materials such as paper, translucent materials such as frosted glass, and any combination of these.

Each material declaration using `dgs_material` has to have a `photon "dgs_material_photon" ()` statement. These two shaders should be used together for physical accuracy. An example is:

         material "mirror"  opaque    # ideal mirror material
            "dgs_material" (
               "specular"      1.0 1.0 1.0,
               "lights" ["arealight-i"]
            )
            shadow "dgs_material" ()
            photon "dgs_material_photon" ()
         end material

Another pair of physically based shaders is `dielectric_material` and `dielectric_material_photon`.

For further details on `dgs_material`, `dielectric_material`, and their photon shaders, see the documentation of the Physics Shader Library.

## 1.24.4 Shader Functions

There are two functions that are especially important to writers of photon shaders. The shader interface function mi_choose_scatter_type chooses a scatter type for a photon based on the probabilities for diffuse, glossy, and specular reflection and refraction. It can also choose absorption, that is, that the photon should be traced no further. The function also ensures a correct energy level in the scene by altering the reflection coefficients according to the scatter choice.

During regular ray tracing, material shaders of caustic-receiving objects should call the mi_compute_irradiance function to ``pick up'' the illumination caused by photons reaching the object during preprocessing.

## 1.24.5 Fine-tuning Caustics

The number of photons used to estimate the caustic brightness can be changed with the global option `caustic accuracy`. The accuracy controls how many photons are considered during rendering. The default is 100; larger numbers make the caustic smoother. There is also an optional radius parameter. The radius controls the maximum distance at which mental ray considers photons. For example, to specify that at most 200 photons should be used to compute the caustic brightness, and that only photons within 1 scene unit away should be used, specify:

        caustic accuracy 200 1.0

in the `options`. (Similar accuracy parameters are available for global illumination, volume caustics and global illumination, and final gathering.)

Accuracy parameters can be used to select two fundamentally different sampling policies. If R is relatively large (as is the default) the overall limiting factor becomes N and R only catches runaway situations with very few photons. Since darker areas have fewer photons than brighter areas, the effective radius within which the Nphotons are found is larger in dark areas. The effect is that low intensity areas will have less detail than high intensity areas. Also, increasing the number of photons in the scene will result in the effective radius becoming smaller, so if N is not adjusted to compensate the same amount of noise will be seen, only on a smaller scale.

The other policy is to select R small, on the scale of the detail the user wishes to see. N is then kept high, or even set to 0 (unlimited). In this case, a constant radius is examined which results in the scale of the detail remaining constant between light and dark areas. Increasing the number of photons in the map will have the effect of reducing the error noise. In practice, one will often use a combination of the two, with a small radius to get detail in dark areas, and N set at a moderate value to speed up rendering. Irrespective of the chosen policy, a large effective radius gives less noise, but a more blurred result. To decrease the noise without blurring detail, it is necessary to increase the number of photons in the photon map. It is very instructive to explore the effect of setting these options with the aid of the `diagnostic photon`2.1 option since the false color image it generates shows the difference in estimated density more clearly. For fast previewing of caustics it can be useful to use N=20.

#### Footnotes

... map.1.5
  The concept was introduced by H. Wann Jensen in "Global Illumination using Photon Maps", Rendering Techniques '96, Springer-Verlag, Wien, 1996, pp. 21-30.

Next: 1.25 Global Illumination.1 Up: 1. Functionality Previous: 1.23 Memory-mapped Textures