Light caching (called "light mapping" in older versions of V-Ray) is a technique for approximating the global illumination in a scene. This method was developed originally by Chaos Group specifically for the V-Ray renderer. It is very similar to photon mapping, but without many of its limitations.
The light cache is built by tracing many many eye paths from the camera. Each of the bounces in the path stores the illumination from the rest of the path into a 3d structure, very similar to the photon map. On the other hand, in a sense, it is the exact opposite of the photon map, which traces paths from the lights, and stores the accumulated energy from the beginning of the path into the photon map.
Although very simple, the light-caching approach has many advantages over the photon map:
- It is easier to set up. Rays are only traced from the camera, as opposed to the photon map, which must process each light in the scene and usually requires separate setup for each light.
- The light-caching approach works efficiently with any lights - including skylight, self-illuminated objects, non-physical lights, photometric lights etc. In contrast, the photon map is limited in the lighting effects it can reproduce - for example, the photon map cannot reproduce the illumination from skylight or from standard omni lights without inverse-square falloff.
- The light cache produces correct results in corners and around small objects. The photon map, on the other hand, relies on tricky density estimation schemes, which often produce wrong results in these cases, either darkening or brightening those areas.
- In many cases the light cache can be visualized directly for very fast and smooth previews of the lighting in the scene.
Even with these advantages, light caching is similar in speed to the photon map and can produce approximations to the global lighting in a scene very quickly. In addition, the light cache can be used successfully for adding GI effects to animations.
Of course, the light cache has some limitations:
- Like the irradiance map, it is view-dependent and is generated for a particular position of the camera.
- Like the photon map, the light cache is not adaptive. The illumination is computed at a fixed resolution, which is determined by the user.
- The light cache does not work very well with bump maps.
The following diagram shows the way the Light Cache is being generated. To get the lighting from the environment V-Ray traces many rays from the camera into the scene. Each bounce of light creates a sample in the light cache that can be used during the rendering. If one ray hits a sample that was created by another ray the tracing is stopped and the information from the sample is read instead. This speeds up the process a lot.
These parameters affect the calculation phase of the light cache; they do not affect the final rendering.
Subdivs – Determines how many paths are traced from the camera. The actual number of paths is the square of the subdivisions (the default 1000 subdivs mean that 1 000 000 paths will be traced from the camera).
Sample Size – Determines the spacing of the samples in the light cache. Smaller numbers mean that the samples will be closer to each other, the light cache will preserve sharp details in lighting, but it will be more noisy and will take more memory. Larger numbers will smooth out the light cache but will loose detail.
Screen Space – The units are fractions of the final image (a value of 1.0 means the samples will be as large as the whole image). Samples that are closer to the camera will be smaller, and samples that are far away will be larger. Note that the units do not depend on the image resolution. This value is best suited for stills or animations where the light cache needs to be computed at each frame.
World Units– The sizes are fixed in world units everywhere. This can affect the quality of the samples - samples that are close to the camera will be sampled more often and will appear smoother, while samples that are far away will be noisier. This value might work better for fly-through animations, since it will force constant sample density everywhere.
Retrace – When enabled, this option improves the precision of the global illumination in cases where the light cache will produce too large an error. This is especially obvious with the Use light cache for glossy rays option, or near corners where light leaks might be possible because of the light cache interpolation. For glossy reflections and refractions, V-Ray dynamically decides whether to use the light cache or not based on the surface glossiness and the distance from it so that the errors due to the light cache are minimized. Note that this options may increase the render time.
Example: The Subdivisions Parameter
The Subdivs parameter controls the number of rays that are shot into the scene and the "noise" quality of the light cache samples.
Here is a scene rendered with different settings for the Subdivs parameter (all other settings are the same). As we more samples are added, the noise is reduced, but the render times increase. When the Subdivs parameter is increased twice, the light cache takes approximately 4 times as long to calculate.
Subdivisions = 500
Subdivisions = 1000
Subdivisions = 2000
Example: The Sample Size Parameter
The Sample size parameter controls the size of the individual light cache samples. Smaller values produce a more detailed lighting solution, but are noisier and take more RAM. Larger values produce less detail, but take less RAM and may be faster to calculate.
Here is a scene rendered with different values for the Sample size parameter. All other values are the same. Note the light leak from the wall on the right in the last image - this is because samples from the other side of the wall are quite large (because of the Screen Scale) and end up being used on the side facing the camera (compare this with the World Scale in the above example). Note the difference in the noise level between the samples as well.
Sample size = 0.01
Sample size = 0.02
Sample size = 0.0
Example: The Scale Parameter
The Scale parameter determines whether the Sample size and Filter size parameters are in screen space or world space.
In the table below, the Screen scale was used, and the scene was rendered with different image and world sizes. The Sample size was constant for all images - the default 0.02. As you can see, we always get the same number of light cache samples for all cases, regardless of resolution or scene size - in fact, when scaled to the same size, the images look identical. This is why the Screen Scale is applicable to the large variety of scenes.
Scene scaled down to 50%
Scene scaled up to 200%
In the table below, the World Scale mode was used. Again, the scene is rendered at three different resolutions and scales, but with the same light cache parameters. The sample size was set to be 1/5th of the sphere radius in the scene at normal scale.
You will notice that the number of samples again does not depend on the image resolution, but it does depend on the scene size. Also notice how the samples near the camera appear larger because of the perspective - unlike the Screen Scale mode which compensates for this effect and tries to make the samples with more or less equal size on the image. Another thing to note is that we don't get light leaks (compare with sample size example), even when the samples are relatively large - this is because the World Scale forces a uniform sample size on both sides of the right wall.
Scene scaled down to 50%
Scene scaled up to 200%
Example: The Retrace Parameter
The first set of images shows how the Retrace parameter can be used to reduce light leaks due to the light cache interpolation. The scene is an interior scene with parts of the exterior visible. The bright light cache samples from the exterior blend with the darker samples from the interior causing light leaks when the irradiance map is calculated. The Retrace option (with the default value of 1.0) successfully resolves the problem at the expense of slightly increased calculation time for the irradiance map.
Without retracing, light cache samples from the bright exterior are mixed with the dark samples in the exterior causing light leaks.
With light cache retracing enabled, the light leaks are successfully eliminated at the expense of slightly longer irradiance map calculation time.
The second scene in this example shows how the Retrace option can be used to improve the appearance of glossy reflections and refraction with the Use for glossy rays option. In this case, V-Ray dynamically decides whether to use the light cache or not, based on the glossiness of the surface and the distance from it.
Without retracing, the light cache samples are clearly visible in the glossy reflections and refractions.
With light cache retracing enabled, V-Ray is able to dynamically decide whether to use the light cache or not, leading to a much better result.
Single Frame Mode
From File Mode
Mode – Determines the rendering mode of the light cache:
Single frame – Computes a new light cache for each frame of an animation.
From file – The light cache is loaded from a file. The light cache file does not include the pre-filtering of the light cache; pre-filtering is performed after the light cache is loaded, so that it can be adjusted without the need to recompute the light cache.
Keep File – When enabled, the last GI map calculated will remain in the memory after the rendering has finished. Disable this option to automatically remove the map and save some memory space.
Save – Allows the light cache to be saved as a file on disk, for later re-use.
Auto-Save/ File – When enabled, the light cache will be automatically written to the specified file. Note that the light cache will be written as soon as it is calculated, rather than at the actual end of the rendering. Specifies where to save the light cache when Auto save is enabled.
Source File – Specifies the file name to load the light cache from, when the mode is set to From File.
- Do not apply perfectly white or very close to white materials to a majority of the objects in the scene, as this will cause excessive render times. This is because the amount of reflected light in the scene will decrease very gradually and the light cache will have to trace longer paths. Also avoid materials that have one of their RGB components set to maximum (255) or above.
- If you want to use the light cache for animation, you should choose a large enough value for the Filter size in order to remove the flickering in the GI.
- There is no difference between light caches computed for primary bounces (direct visualization) and for secondary bounces. You can safely use light caches computed in one of these modes for the other.
- Similar to the photon map, you can get "light leaks" with the light cache around very thin surfaces with substantially different illumination on both sides. The effect can be reduced by decreasing the Sample size and/or the filtering.