YafRay Lighting
By Alejandro Conty and Fernando Arroba
PDF version of this document:
YafRayLighting.pdf
In this talk we are going to study how YafRay rendering behaves and how we can get it to work from Blender. To do so, we are always going to render in
full mode and using the settings available. Taking into account that in
full mode both direct and indirect light is considered, we're going to examine the two blocks of settings we've got to adjust in that mode: Irradiance
Cache and
Photons. We're going to focus our study on those two.
For better understanding on how YafRay works, we will examine how YafRay lights are configured and particularly how problems related to lighting arise. Of course, we will see to how to solve those kinds of issues and the best options to achieve good results within an acceptable time frame.
Let there be light!
When rendering, a raytracer tries to simulate light conditions that exists in real life. That simulation must take into account not only image quality but render times as well. Therefore, render times are proportional to computer performance. In raytracing, it would be impractical to shoot rays from light sources in every direction and to expect some of them to eventually reach the camera position after bouncing around and interacting . Therefore, the raytracing simulation takes the opposite approach: to examine which intensity and contrast a given point must have if seen from the camera position. Each type of light uses a different kind of algorithm and has its own share of advantages and disadvantages.
When the source is a point light, local algorithms are used which are fast to compute and also predictable. However, this type of light is not realistic because it produces hard-edge shadows and continuous shading because of lack of interaction.
Other types of lights such as arealight are more realistic and produce soft shadows and penumbra areas. However, lighting produced by this type of lights is difficult to calculate. They use a
stochastic method, also called a
montecarlo because of its randomness. This method is slow because it shoots random rays around and then calculates an average of the color and the lighting observed.
|
|
Figure 1. Montecarlo method application in CG
|
As you can see in the previous image, a ray is shot from the camera and the montecarlo method randomly samples the scene from the bounce point of that ray. It's similar to Ambient Occlusion, which calculates ambient light bounces and how they are occluded by objects.
Light sources can not be reduced only to direct light. In fact we can find many other kinds of light such as:
- Skylight, which can be simulated by an image background (HDRI or not).
- Emitting objects.
- Light bounced back by other objects surface.
In YafRay case, these kind of lights are considered as
non-point lighting and calculated by the montecarlo method.
|
|
Figure 2. Skylight from the background.
|
As you can see in Fig. 2, lighting that is coming from everywhere in the sky may produce a very exposed scene with almost no variation in shadows. In this case the whole sky is one big light source.
|
|
Figure 3. Emitting object
|
In Fig. 3 case we can see that there is more variation in the shadows than in the previous case. There is more contrast between surfaces in shadow and lit ones, and there are penumbra areas with shadow gradient. There is also color bleeding between objects.
|
|
Figure 4. Light bounced back by an object surface
|
In the last case, which is depicted in Fig. 4, we can see that, like in the previous example, lighting is not coming from a point but from a whole area. In this case however, unlike the previous example, lighting is coming from an area in the room intensively lit. Therefore, there is actually a light source, but lighting is actually indirect because it is coming from a bounce on another surface.
Noise
Noise is a problem which tends to appear in certain scenes depending on the lighting conditions. It consist of patterns and light leaks which are more likely to appear under certain conditions. That condition is small and powerful light sources. Why those leaks tend to appear is easy to understand: if the light source is small, the random rays of the montecarlo method have more difficulty finding it. If in a given point the raytracer doesn't find a light source but finds it in a contiguous point, the contrast between them will be more accentuated the more powerful the light source is.
The smaller the light source, the lesser the probability of being found by the
montecarlo method is. The lesser the probability, the more noise there will be.
Three are the typical cases:
- Small light source, as mentioned before.
- Small windows, based on the same premises.
- A HDRI image with concentrated areas of light.
|
|
Figure 5. Visibility: the key problem.
|
In fact the problem is not the light size but its visibility from any point in the scene. A far away light source is more difficult to find if rays are shot randomly, it is less visible; in other words, the angle of probability is smaller, as you can see at first glance in Fig. 5.
We are going to see how the light source visibility is noise related. We are going to start with an hypothetical case in which any ray is likely to find the main light source, the sky.
|
|
Figure 6. Left: The sky is completely visible. It is easy for a ray to eventually find the light source. Right: There is not strong shadows nor contrast; there are no leaks nor noise in the image.
|
Now we are going to cover half the sky. The result is that only half the rays shot from the camera will eventually reach the light source.
|
|
Figure 7. a) The sky is partially covered. b) Noise is starting to be noticeable.
|
Certain noise is visible in the image because of the contrast between rays that actually find the light source (sky) and rays that do not, which are half the calculated rays more or less.
If we reduce the proportion of visible sky, for instance, by using a windows, lighting is likely to decrease, because we have reduced the number of rays that actually reach the light source.
|
|
Figure 8. a) The sky is only just visible. b) There is a lot of noise
|
To counteract the decrease in light, the power of the light has been multiplied 8 times.
Noise in this scene arises because the light source is small. As we have increased the power of the light to get enough light, the noise increases as well. Moreover, areas that are directly lit by the light source are overexposed.
Reducing noise
When this noise appears, we usually solve this problem by increasing the GI Quality Level, in YafRay render panel. This may solve some cases, since that setting increases the number of samples. More samples mean that there is more probability of finding a light source when it is a small one, although there is a problem: render times increase. While render time increase is lineal, the noise reduction is equal to 1/sqrt(samples). Therefore, this method should be used carefully and we should make use of photons and Cache refinement as well.
What we should do when lights are small.
Usually the small lights problem is likely to happen in indoor scenes, where lighting is coming from artificial sources or windows. To sort this problem out we may use photons. Don't mistake photons in the render panel for specialized photons used to produce caustics.
Basically what we do by using a photonmap is to give the Montecarlo method extra information about where the direct light is coming from and an indirect light estimation, which will reduce the bounces the montecarlo method has to calculate.
|
|
Figure 9. Photons are shot from light sources and they bounce around leaving marks that will produce the photon map.
|
You can see the photonmap if the
Tune Photons button is enabled, in the
GI panel. This map is a rough estimation about how the final render is going to look like. It is recommended to get used to enabling this button every time we have an scene to light with photons, because it provides a valuable information in order to achieve the lighting distribution we want.
|
|
Figure 10. Photonmap example.
|
Tuning photons.
The steps we should follow to configure photons are very easy. First of all, we must enable the
Photons button in the YafRay panel. The next step is to choose photon
Count and a
Radius.
At this point some things must be considered, because the more photons shot, the more accurate the photonmap will be, although the render time will increase too. Higher photoncount means less noise. Regarding
radius, the larger the smoother the photonmap will be, but at the same time the photonmap will be less accurate and the render will lose sharpness.
¿How many photons and which radius?
It mainly depends on two factors: scene physical size and precision needed.
As we've said, optimal parameters depends on the scene specifics, therefore magical rules can not be precepted. However, at least we know how a good photon map should look like. It should have two characteristics easy to understand:
1. There should be no light leaks. Light leaks are bright areas that tend to appear in dark and shadowed places. It is likely to happen when radius is so big that it might be actually going beyond objects size and it is gathering photons over that objects.
2. As smooth as possible. Remember that if we use a relatively big radius, we are losing lighting sharpness. A good example of a smooth photonmap is in figure 10.
In other words, we should use a radius as big as possible for smoothing, but we must avoid producing light leaks.
A good photonmap is essential to reduce render times. When YafRay starts to shot random rays, it realizes that there is actually a photon map. Instead of calculating further bounces to find the light sources, YafRay reads the photon map in which there is already calculated the lighting and color. With the data provided by the photon map, the montecarlo method doesn't need to carry on with new calculations nor finding where the light sources are.
|
|
Figure 12. Previous photon map result.
|
Blend file:
http://www.coala.uniovi.es/~jandro/noname/examples/whitenight.blend
The wood texture for the floor:
Typical cases in which Photons are useful.
We can find several cases in which photons can be useful. For instance, when we need small lit areas in the scene, we can use Spotlights and Pointlights as photons emitters. When lighting is coming from an object, we can use arealights as photon emitters. In addition, we can use arealights to simulate light coming in through a windows.
Small lit areas: studying two cases.
The first case is when we have a windows where the sunlight is coming through. In this case, only a small area will get direct light, while most of the scene will receive indirect light.
|
|
Figura 13. Sun coming in through a windows.
|
The figure 13 illustrates an example of this case. To simulate it we can follow the method described in figure 14.
|
|
Figura 14. Using a spot light to simulate the sun.
|
Another possibility is indoor lighting. In this case the problem is similar: only a small area receives direct light.
|
|
Figure 15. Indoor lighting.
|
As in the previous case, we can use spotlights and pointlights as well since photons can get away from the scene.
|
|
Figure 16. Indoor lighting with spots.
|
Like in the previous examples, photon emitters must be placed in natural locations for that purpose. If we have lights with reflectors like in fig. 16, it is advisable to use spotlights to simulate them. On the other hand, it is better to use point lights when the light source is not placed inside a reflecting area.
Emitting objects.
Not only can we find objects that are actual light sources, but some of them might also have a complicated geometry. These kinds of objects varies from simple light boxes to neon ads. Simulating them can be easy or challenging depending of those factors.
To use an object to illuminate they must have 'emit' enabled. To simulate light coming from that kind of objects, we can use both a single arealight or several. Ideally, arealights must cover the emit object as best as possible : if the 'emit' object is square, a single arealight will be enough, if the object geometry has certain complexity, we must use several arealights to cover as best as possible the entire object surface.
Of course, the arealight color must match the objects color. Last but not least, the arealight power must be equal to
1.0. People tend to increase arealight power when there is not light enough in the scene. This will overexpose the areas next to the light and the scene is likely to remain the same. The arealight intensity must be controlled with 'EmitPwr' in the GI panel. If when photons are used, lighting doesn't improve with more bounces, we should check that the light source is not blocked by another object. You can use fill lights in addition.
|
|
Figure 17. Arealight covering an emit object.
|
Emit objects must be paired with at least one arealight placed as close as possible to the 'emit' object, but not overlapping. If overlapping, weird lighting effects might appear or no lighting at all if the photons get totally blocked by the emit object.
Diffuse skylight coming in through a windows.
Yet another similar case is diffuse skylight coming in through a windows.
|
|
Figure 18. Window covered with an arealight.
|
As in the previous examples, we are going to use at least one arealight to cover the windows. This arealight acts as photon emitter. If the window shape is regular just one arealight will do. For more complex windows, several arelights might be necessary.
Like in the previous examples, the arealight must be placed as close as possible to the window, pointing towards the inside, covering the window to avoid photons getting away.
The arealight color must be the same as the sky and its power must be equal to
1.0.
So what now?...
Up until now we have seen how to use different kinds of light to simulate sources of photons. Now we are going to think like an average YafRay user. Suppose that we have a scene with small light sources and we want to optimize the rendering. If we follow the previous advice, we decide that photons is the best option. Now we must make sure that every light source in the scene can emit photons by turning on 'emit' on every object and by placing arealights close to the objects and windows, as explained previously.
We now set a good amount of photons and a common radius (
500.000/0.5 for instance). Once we're done, we enable
tune photons to see the photon map. What the next step?
First we compare the photon map we've got with a low quality render (
tune photons button off). If they have the same intensity, we are in the right track. If they differ from each other, we should check every light source to be sure that they have the proper color (it could be a yafray bug as well!). If light leaks keep appearing, it might be due to non-solid modeling (single-faced walls) and we might need to revise the scene-geometry.
Up until now all seems pretty clear but ... can the scene be refined further? This is what we're going to see in the next paragraphs.
Irradiance Cache.
The
irrandiance cache will help us to refine the image a bit more. First, lets see how Irrandiance cache works.
Irrandiance cache spares the render pass to calculate GI in every pixel. Basically it selects some pixels to calculate and then interpolates them. This interpolation will reduce high frequency noise, although it can produce low frequency noise (clouds). In animations it produces annoying shadows flickering, although it works fine and reduce render times in stills.
|
|
Figure 19. Cache configuration.
|
To enable Irradiance cache,
Full GI,
Photons" and =Cache buttons must be enabled to access every setting of the cache configuration. The render steps are as follows:
- Photons shooting from every photon emitter; the photon count is divided between them.
- First render pass (fake pass). The
Prec parameter controls every how many pixels of the lighting that is calculated, although in corners more samples are usually taken.
- Refinement phase (2 more fake passes ). In this step, abrupt changes in lighting higher than
Refinement value are identified. When a higher value is found, a lighting antialiasing is performed by taking more samples.
- Final stage. Interpolation with resulting cache and final image production.
Now that we understand a bit more the render stages, we are going to look at Cache parameters and how they work.
For instance, look at shadows quality.
ShadQu have a range value between 0 an 1, although the default value of
0.90 works for almost every scene. This parameter controls how density of samples grows in corners; the higher the sampling, the higher the definition of shadows in corners. If the default value is used, then shadows will be refinement which improves the result.
|
|
Figure 20. Cache samples distribution.
|
Refinement has a range value between
0 and
1 too. As we mentioned before when explaining the render stages, this threshold determines light-changes to refine. When a lighting-change higher than the refinement value is detected, such as in shadows limits or when there are artifacts due to low sampling, refinement is enabled. In this case, the render pass is repeated two times. If refinement is equal to
1, there is no refinement at all, while if we set a
0.03 value, the refinement will be exhaustive.
|
|
Figure 21. No refinement.
|
|
|
Figure 22. 0,05 Refinement.
|
We have achieved smoother shadows but some patches still remain, although they are not located in shadows boundaries. What can we do to get an even cleaner scene? Well, first of all smoothing out the photon map a bit more, second would be more GI
Quality.
Smoothing out the photon map doesn't work beyond certain values because, with excessive smoothing, lights leaks are more likely to appear
|
|
Figura 23. After a high Quality pass.
|
Caustics.
There are two ways of achieving caustics with YafRay: from a point light or from a non-point light source.
When we want caustics from a point light source, it is necessary to use an explicit
photonlight.
If we are trying to get caustics from non-point light sources, it is not necessary to use a
photonlight since using a photon map as described in previous paragraphs will do, although taking into account some questions. In
GI Full mode we should have no problem with getting caustics. However, it is advisable that light sources are not too small. In addition, we should increase
CDepth (number of bounces inside objects (for caustics))if necessary.
|
|
Figure 24. Caustics from a windows.
|
--
LuisF - 26 Jul 2006
--
ClausA - 14 Aug 2006
to top