Ditte scene © Olivier Boscournu, calculated with photon mapping.
Understanding Photon Mapping
© Alvaro Luna Bautista, 2013
Optimising the flow of diffuse photons
Case 1. Background IBL in semi-enclosed scenes. Area light.
Case 2. Background IBL in semi-enclosed scenes. Portal light.
Case 3. Sunlight in semi-enclosed scenes. Scene bounding box.
Case 4. Sunlight in semi-enclosed scenes. Spot light.
Case 5. Diffuse photon mapping in open scenes.
Search Radius and Search Count
Diffuse Photon mapping for animation
Photon mapping is a global illumination technique invented by Henrik Wann Jensen during the 90’. The proposition is as follows:
In an era dominated by observer-dependent path tracing algorithms, he proposed computing illumination from the light sources standpoint which is better for calculating certain GI problems. There is an issue though with this proposition. Taking into account that ray tracing is done using random paths to get an even variation, observer’s rays will never land on the very same spot that “light rays” thus the render engine can never connect both ends.
This problem is solved using a density estimation algorithm of nearby photons for each “eye ray” hit. For this to happen, photon bounces need to be stored in RAM memory in render time with data about their incoming intensity, direction, color, etc. This data structure is called the photon map.
The main obstacle of photon mapping is connecting the eye ray hit (x’) with the light ray hit (photon) as they are never going to meet using random shooting algorithms. The solution is to average several photons hits within a circumference about x’.
The main advantage of photon mapping is that you can easily solve many global illumination problems that are very hard to solve from the observer’s standpoint. Imagine you have to find small light sources with random bounces or you have to calculate lighting going through meshes with an IOR factor whose result depends on the light source you are looking for!
In these cases, global illumination becomes casino betting and a huge computation problem for all kinds of hardware, since global illumination complexity usually follows geometric progression.
The main disadvantages of photon mapping are:
Photon mapping has evolved into a new family of algorithms that average several photon “passes” instead of only one. In this way the render engine can make very consistent estimations with low bias without hitting RAM memory limits. These algorithms are called progressive photon mapping.
Photon mapping is about the power of statistics: you don’t need to inquiry the behaviour of every possible path in the scene in the same way you don’t have to ask everyone about their political views to anticipate a poll result. With photon mapping you basically take statistical samples in every area of the scene to form an accurate map of incoming lighting. The result is a less than perfect yet very good approximation achieved in much less time than path tracing.
Several photon mapping types have been developed for each medium and they are independently traced and RAM-stored in render time. YafaRay at the moment supports independent caustic maps in direct lighting and a global map which includes diffuse and caustic photons. There are several settings which are common to all types though, such as number of photons to shoot and bounces. For instance, in case 4 - Volume photon mapping, 3 bounces are needed for photons to reach again the volume surface.
As per the image above, photon mapping types are:
In YafaRay, there are at least three light types with controls to switch photons emission on or off. These light types are Sunsky 2, Portal light and Spot light. Besides, in Portal light we can decide whether it is sampled for direct lighting as well. The main idea behind these controls is to improve the photons flow over areas actually seen by the camera’s point of view.
Note: these tools could be the source of human bias and error in a method that otherwise should be physically correct without using any kind of portal lights, photons lamps or any other trick like the ones explained here. In a perfect photon mapper there would not exist portal lights and that should be the aim of the YafaRay engine, which always has combined biased solutions with physical correctness and simplicity. The problem of using tricks and portals is that you never know when to stop adding them as there are many cases, and then the engine becomes much more complex. You could end losing physical correctness because of light or/and photon sources duplication. Importance photons shooting should be the main feature YafaRay should add in the future to improve all photon mapping cases at once: diffuse photon mapping in open and semi enclosed scenes, caustic photons, SSS i volume rendering: restricting the photon emission to areas relevant to the problem at hand. |
.
While these kind of tools could be helpful to get a denser photon map in many cases, it is worth noting that this is one of the main sources of human bias in the photon mapping method, since we could change the contribution of different lighting components based on our preferences and needs as opposed of using physical correctness.
The diffuse photon map tries to reproduce the transference of color and light between objects with a diffuse component. The most important aspect of diffuse photon mapping is that it is a non-focused low resolution map if we compare it with other photon mapping types:
Photon mapping main point is that you can achieve a less than perfect yet high quality fast global illumination approximation in still scenes. A correct diffuse photon map setup can produce very good images in a fraction of time used by other methods. Besides, it is not affected by light sources size, visibility and intensity like path tracing like algorithms.
As depicted in the image above, photons are emitted from the light source(s) and they bounce off diffuse components till any of the following three things happen, as per the image above:
Whether the photon is absorbed by a diffuse component or continues bouncing on is decided by a montecarlo algorithm called ‘russian roulette’. Diffuse photon mapping is better suited for indoor scenes since photon hits are recorded in the second and subsequent bounces and enclosure allows for more bouncing therefore more photon hits are recorded on the photon map, though progressive photon mapping has somewhat solved this limitation.
There is a problem with diffuse photon mapping though: since it is an observer-independent method, many times photons bounce on surfaces with little relevance to the camera point of view. This could produce a low density of hits in the photon map in areas seen from the camera.
To appreciate density, size and coherence of diffuse photon patches, all photon mappers include an option to visualise directly the radiance map produced by photon hits without interpolation. This option is useful to detect and solve deficiencies that would not be so apparent after the final gathering interpolation pass. In YafaRay this option is enabled using the “Show radiance map” button. This option will be used through this document to compare, optimise and improve diffuse photon mapping results:
Another question to take into account is that the number of photons to shoot is shared between all scene light sources equally, but not all sources contribute to the photon map density in the same way.
To understand this fact, users should be aware about how light sources actually shot photons (and direct lighting for that matter). Each light type shots photons in a different way. The main point here is that most of them shoot photons around in an uncontrolled manner while spotlight can keep them within a beam and with directional control.
All light types work very well, particularly in enclosed scenes. However, there are two light types where a semi-enclosed or open scene is needed for them to work: sun light and background IBL. In the next sections we will see how to optimise the flow of photons in those cases.
Users should also take into account that in photon mapping, light sources emit photons and are sampled for direct lighting as well, both at the same time. However, as we have seen in previous sections, in certain cases we can disable light photon emission or/and direct lighting sampling for certain light types, so we concentrate the photon emission on one light source, as in case 2.
Let’s start with the use cases !
Background IBL is a spherical arealight shooting direct lighting and photons inside. When we work in an interior scene with light coming in through a windows (left), most of the photons shot by the background are bouncing in areas with little relevance to the camera view. Before the introduction of portal lights, users would use an arealight in front of the windows shooting photons inside (right). This arealight would use a similar color to the background.
In this solution, the number of photons to shoot (photons count) is shared between the IBL background, which would produce a low density of hits, and the arealight, which would produce a higher number of photon hits on the photon map. The overall result improves compared to the photon map produced only with IBL background photons, as shown in the comparison below:
Background IBL is a spherical arealight shooting light and photons inside. When we work in an interior scene with light coming in through a windows, most of the photons shot by the background are bouncing in areas with little relevance to the camera view. The solution depicted in the image above uses a portal light placed in front of the windows to shoot photons according to background colors.
Comparison between a photons map produced by IBL background (left) and a map produced by a portal light (right) using the same photon count in both cases. On the right, the background does not emit photons and the portal light is not sampled for direct lighting, therefore the portal light is shooting all the photons count.
Sun light is a light type that shoots photons in a parallel direction yet circumscribed to the scene bounding box limits. The bigger the scene, the more area needs to be covered with the same amount of diffuse photons. Therefore it is always a good idea to keep the scene bounding box to a minimum size when using sun light.
Comparison between a photons map produced by a scene with a smaller bounding limit (right) than the same scene on the left. This is done by removing objects which are not relevant to the camera view yet contribute to enlarge the scene bounding box limit.
Sun light is a light type that shoots photons in a parallel direction yet circumscribed to the scene bounding box limits. Many times sun light photons bounce on areas with no relevance to the camera view. One solution could be using a far away powerful spot light whose narrow beam is sized according to the windows size so most of the photons produced by the spot land on the inside.
Using the same amount of photons to shoot, a very narrow and distant spot light (right) is able to land most of the photons on the room, compared to a sun light (left). In this case, spot light angle is 1,5º and power is 250.
In order to compute only indirect lighting, photons hits are recorded in the second and subsequent bounces (yellow dots) since the first bounce would account for direct lighting. In open scenes it is very difficult to achieve a high density of hits on the photons map since many if not most of the photons will fly away to the background after the first bounce.
Besides, in many open scenes the indirect lighting component is negligible since background lighting is already providing incoming light from all directions. Not only that, also in open scenes with low contrast IBL lighting, path tracing could deliver very good results with low quality settings. Therefore the solution could be considering photon mapping not a good solution for this case.
The basic working premise of diffuse photon mapping is to get as many photon hits as possible within the smallest radius. In other words, the more photons hits the less search radius and the more search count, taking always into account that the number of photons hits on the photon map depends on the number of photons to be shot and how the flow of photons is optimised, as we have seen in the previous sections.
Search radius and Search count are limit parameters to search for and average nearby photons. The first limit to be reached is used as more photons are inscribed in the circumference, so an image could have count-limited patches and radius-limited patches at the same time. Usually count-limited patches will be in areas with lot of photons and radius-limited patches will be in areas with few photons to average.
Photon mapping is mainly a statistical problem: the more photons we inscribe in each patch and the smaller these patches are, the more correct. In practice, in scenes modelled in meters we need a photons hits density enough to work with Search Radius = 0.10 and lower, in order to obtain an accurate global illumination result. On the contrary, in scenes with a low density of photons hits it is not recommended to use a low Search Radius since many patches won’t have any photons to average at all.
If we decrease Search radius without increasing the number of photons hits, each circumference will have less photons to average and some of them will not inscribe any photon at all.
Comparison between Search radius = 1 (left) and Search radius = 0.10 (right), shooting the same amount of photons (50.000). Less photons in each patch means more divergence between nearby patches. Black areas are patches that were not able to average any photons at all.
Radiance photons map rendered with 10 million photons, Search Radius = 0.05 and Search Count = 250
This parameter sets a maximum amount of times a photon can bounce off diffuse surfaces. Not all photons might reach this limit, some of them can be absorbed in previous hits or fly to the background. The most important are the first three or four bounces, that’s why a limit of 6-8 bounces will do for all scenes.
More bounces increase the amount of hits in the photons map but it is not the main factor driving photons map density. Maybe the most significant change is increasing the exposure of the indirect lighting component.
Comparison between Bounces = 5 (left) and Bounces = 20 (right). The number of hits on the photon map has increased from 1.9 million to 3.4 million. Render time increased from 11 seconds to 15 seconds.
Once the photon map is constructed, a common eye-ray pass is performed from the camera standpoint. In every diffuse intersection reached by eye rays (x’), final gather points are created. From there, Final Gather samples are shot in random directions which will hit other surfaces. At the end of these samples with path = 1, radiance data is retrieved from the photon map.
Final Gather paths longer than 1 are only generated to overcome lack of local radiance detail produced by too close radiance points. These samples will keep on bouncing on diffuse surfaces until the FG bounce limit or the background is reached. At every path end, radiance data is retrieved from the photon map.
The result of each FG path is recursively computed and averaged with the other final gather samples on x’ to compute incoming indirect lighting.
Final Gather makes a massive interpolation of the low-res estimation produced by diffuse photon mapping. The number of FG bounces will be reached only for a fraction of FG samples in the scene and it does not have a significant impact in render times. In practice FG bounces = 4 is enough for all cases.
The most important setting is FG samples, which has got a directly proportional impact on render times. Users might need to increase the amount of samples if noise coming from the Final Gather algorithm is detected, through montecarlo noise produced by Final Gather is very efficiently removed using adaptive anti-aliasing sampling.
Lista by Paweł Łyczkowski, rendered with YafaRay photon mapping.
The main issue of diffuse photon mapping for animations is the random low-resolution non-focused nature of this method, which could lead to an effect known as “shadow flickering”. Areas on the photon map with a poor indirect lighting estimation are able to “trespass” the interpolation produced by Final Gather. Since each Final Gather pass uses a new random seed for shooting paths, the result is that in each frame of an animation some areas could show a slightly different GI estimation than the previous frames, producing a slight flickering of shadows.
The main precondition for using diffuse photon mapping for animations is generating good smooth photon maps free of black patches and in general areas with insufficient density of photon hits. The better the photon map the less amount of shadows flickering.
The main source of shadow flickering in animation is a photon map with black areas and lack of smooth transitions between patches (left). A dense photon map with no black areas and smooth gradients (right) will produce almost no flickering.
Click to play animation. Scene rendered with “Show radiance map” enabled, diffuse photons = 6M, search radius = 0.10 and search count =250.
Click to play animation. Same scene as previous video but rendered with “Show radiance map” disabled.
A caustic is an optical effect consisting in light streaks produced by the concentration of the light beam after a refractive event produced by reflective or refractive surfaces. For instance, on the render below light refracted on the glass is producing caustics on the horizontal plane.
(work in progress)