Difference between revisions of "HowTo:Use radiosity"

From POV-Wiki
Jump to navigation Jump to search
(→‎Radiosity Parameters: fleshed out section, added doc's description with commentary/tips)
m (→‎When to use it: updated images, included link to source file)
Line 12: Line 12:
 
Radiosity should be used when you want a realistic look of indirect lighting.  Indoor scenes frequently use radiosity, but outdoor scenes can greatly benefit from it too.  Since black or uniformly dark shadows are very unrealistic and almost never occur in the real world, radiosity can do a lot to make an image look good.  Here are some images to help compare:
 
Radiosity should be used when you want a realistic look of indirect lighting.  Indoor scenes frequently use radiosity, but outdoor scenes can greatly benefit from it too.  Since black or uniformly dark shadows are very unrealistic and almost never occur in the real world, radiosity can do a lot to make an image look good.  Here are some images to help compare:
 
<gallery>
 
<gallery>
Image:Sa_no_rad_amb_000.jpg|Without Radiosity and finish{ ambient 0.00 }
+
Image:Simplearch_no_rad_ambient_000.png|Without Radiosity and finish{ ambient 0.00 }
Image:Sa_no_rad_amb_025.jpg|Without Radiosity and finish{ ambient 0.25 }
+
Image:Simplearch_no_rad_ambient_025.png|Without Radiosity and finish{ ambient 0.25 }
Image:Simplearch_full_rad.jpg|With Radiosity and finish{ ambient 0.00 }
+
Image:Simplearch_with_rad.png|With Radiosity and finish{ ambient 0.00 }
 
</gallery>
 
</gallery>
 +
Scene source code: [[Media:Simple_arch_demo.pov|Simple_arch_demo.pov]]
  
 
Radiosity can also be used to make glowing objects in a scene cast light onto other objects:
 
Radiosity can also be used to make glowing objects in a scene cast light onto other objects:

Revision as of 01:59, 31 December 2007

Radiosity, also known as global illumination (GI), is one of the two methods POV-ray supports of simulating the inter-reflections of light that occur in the real world.

What radiosity does

We can see objects because light from a light source (such as the sun) is reflected from the surface of the object and picked up by our eyes. However, not all of this light goes into our eyes, but also strikes the other objects around us, likewise, not all of the light coming from an object is directly from a light source. The light we see may have been reflected many times by the surrounding objects. A good example of this is a shadow on a sunny day. The shadow is certainly darker than its surroundings, but will not be pure black because of the reflected light. POV-ray can simulate this in two ways:

  1. Via the ambient property in the finish block of a texture, which gives the color of the object when no light is shining on it.
  2. By using radiosity.


When to use it

Radiosity should be used when you want a realistic look of indirect lighting. Indoor scenes frequently use radiosity, but outdoor scenes can greatly benefit from it too. Since black or uniformly dark shadows are very unrealistic and almost never occur in the real world, radiosity can do a lot to make an image look good. Here are some images to help compare:

Scene source code: Simple_arch_demo.pov

Radiosity can also be used to make glowing objects in a scene cast light onto other objects:

(EXAMPLE IMAGES)

Basic Use of Radiosity

To use radiosity, include a radiosity block in the global_settings. If you are unfamiliar with the settings that control the look and performance of POV’s radiosity algorithm, the easiest way to get started is to use the Rad_Settings macro from rad_def.inc. A description of the parameters and how you can tune them is also covered in this tutorial.

Rad_Settings macro

The Rad_Settings macro allows a user to easily use any of the predefined quality settings from below:

  • Radiosity_Default
  • Radiosity_Debug
  • Radiosity_Fast
  • Radiosity_Normal
  • Radiosity_2Bounce
  • Radiosity_Final
  • Radiosity_OutdoorLQ
  • Radiosity_OutdoorHQ
  • Radiosity_OutdoorLight
  • Radiosity_IndoorLQ
  • Radiosity_IndoorHQ


The macro expects the first parameter to be one of the above quality settings followed by two boolean parameters for normals and medias, respectively.

Example use of Rad_settings macro:

#include rad_def.inc
global_settings {
   radiosity {
      Rad_Settings(Radiosity_Normal,off,off)
   }
}
#default {finish{ambient 0}}

That's it right there! We've just applied to our scene radiosity at a medium quality setting that will not take into account normals or media!

Developing a Better Understanding of Radiosity

The macro works well for most scenes and is very easy to use, but it may not always suit our purposes. What if we tried all of the quality settings, but our scene still isn't rendering correctly? We need a good understanding of the radiosity parameters so we can fine-tune the settings to our needs.

Radiosity Parameters

Below is a description of everything that can be in a radiosity block as defined by the documentation:


pretrace_start
pretrace_end
To control the radiosity pre-trace gathering step, use the keywords pretrace_start and pretrace_end within the radiosity{} block. Each of these is followed by a decimal value between 0.0 and 1.0 which specifies the size of the blocks in the mosaic preview as a percentage of the image size. The defaults are 0.08 for pretrace_start and 0.04 for pretrace_end
pretrace settings can help balance speed vs. quality. Since pretrace helps POVray determine where more radiosity samples are needed, it can help to have a pretrace_start setting around default, but a much smaller than default pretrace_end setting, such as 0.005 for your final trace.


count
The integer number of rays that are sent out whenever a new radiosity value has to be calculated is given by count. A value of 35 is the default, the maximum is 1600
count is probably the main speed/quality parameters. A higher count gives more accurate results, but significantly increases your render times. count needs to be balanced with the error_bound parameter, as smaller error_bound values generally need a higher count.


nearest_count
The nearest_count integer value is the minimum number of old ambient values blended together to create a new interpolated value. The total number blended will vary depending on error_bound. All previous values that fit within the specified error_bound will be used in the average. The default is 5, and the maximum is 20.
Raising nearest_count can significantly reduce or smooth out splotchiness, since more nearby values will be averaged. As always, there is a cooresponding speed penalty, but using higher values like 10 or even 20 for the final trace may help remove artifacts (some artifacts can also be removed by adjusting count also).


error_bound
The error_bound float value is one of the two main speed/quality tuning values (the other is count, the number of rays shot). It is intended to mean the fraction of error tolerated. For example, if it were set to 1 the algorithm would not calculate a new value until the error on the last one was estimated at as high as 100%. Ignoring the error introduced by rotation for the moment, on flat surfaces this is equal to the fraction of the reuse distance, which in turn is the distance to the closest item hit. If you have an old sample on the floor 10 inches from a wall, an error bound of 0.5 will get you a new sample at a distance of about 5 inches from the wall.
The default value of 1.8 is good for a smooth general lighting effect, but may render corners or smaller shadows incorrectly. Using lower values is more accurate, but it will strongly increase the danger of artifacts and therefore require higher count. You can use values even lower than 0.1 but both render time and memory use can become extremely high then.


recursion_limit
The recursion_limit is an integer value which determines how many recursion levels are used to calculate the diffuse inter-reflection. The default value is 3, the upper limit is 20
This represents the number of times light bounces off of objects before reaching your eye. In the real world, this could be a very high number. In POV-ray, higher is not always better! Values between 2 and 4 tend to give very good results for most scenes. Higher values can have a significant speed penalty. It is recommended that you use the lowest value that gets the look you want in your scene. Note that the number of recursions can affect both the brightness and contrast of your indirectly lit objects, which means that test tuning with a significantly different recursion level than what you intend to do the final trace with may have unexpected results.


low_error_factor
If you calculate just enough samples, but no more, you will get an image which has slightly blotchy lighting. What you want is just a few extra interspersed, so that the blending will be nice and smooth. The solution to this is the mosaic preview, controlled by pretrace: it goes over the image one or more times beforehand, calculating radiosity values. To ensure that you get a few extra, the radiosity algorithm lowers the error bound during the pre-final passes, then sets it back just before the final pass. The low_error_factor is a float tuning value which sets the amount that the error bound is dropped during the preliminary image passes. If your low error factor is 0.8 and your error bound is set to 0.4 it will really use an error bound of 0.32 during the first passes and 0.4 on the final pass. The default value is 0.5.


gray_threshold
Diffusely interreflected light is a function of the objects around the point in question. Since this is recursively defined to millions of levels of recursion in any real life scene, every point is illuminated at least in part by every other part of the scene. Since we cannot afford to compute this, if we only do one bounce, the calculated ambient light is very strongly affected by the colors of the objects near it.
This is known as color bleed and it really happens, but not as much as this calculation method would have you believe. The gray_threshold float value desaturates the colored light a little to make your scene more visually correct. A value of .6 means to calculate the ambient value as 60% of the equivalent gray value calculated, plus 40% of the actual value calculated. At 0%, this feature does nothing. At 100%, you always get white/gray ambient light, with no hue.


minimum_reuse


brightness
The brightness keyword specifies a float value that is the degree to which objects are brightened before being returned upwards to the rest of the system. The default value is 1.0
Brightness should be balanced with your ambient and diffuse values as well as your light_source intensity. Remember that brightness doesn't refer directly to the overall scene brightness, it refers to the radiosity calculation which affects the overall scene brightness. This distinction is important, because we can use it to change the contrast of some indirectly lit areas.


adc_bailout


normal
Radiosity estimation can be affected by normals. To enable this feature, add normal on to the radiosity{} block. The default is off


media
Radiosity estimation can be affected by media. To enable this feature, add media on to the radiosity{} block. The default is off


save_file
load_file
You can save the radiosity data using save_file "file_name" and load the same data later using load_file "file_name". In general, it is not a good idea to save and load radiosity data if scene objects are moving. Even if data are loaded, more samples may be taken during rendering (which produces a better approximation). You can disable samples from being taken during the final rendering phase by specifying always_sample off.


always_sample
You can force POV-Ray to only use the data from the pretrace step and not gather any new samples during the final radiosity pass. This may reduce splotchiness. To do this, set always_sample to off (the default value is on). It can also be usefully when reusing previously saved radiosity data.


max_sample
Sometimes there can be problems with splotchiness that is caused by objects that are very bright. This can be sometimes avoided by using the max_sample keyword. max_sample takes a float parameter which specifies the brightest that any gathered sample is allowed to be. Any samples brighter than this will have their brightness decreased (without affecting color). Specifying a non-positive value for max_sample will allow any brightness of samples (which is the default).

Tuning Radiosity

Tuning radiosity for your scene is the longest and arguably the most important part of the process. While we can often apply radiosity settings that worked well in another scene and have good results, the different lighting conditions and geometry means that the perfect settings for your scene will not be found in any guide. Fear not! There are ways to find the settings for your scene:





Pitfalls and Work-arounds

Artifacts

Sometimes radiosity can cause artifacts, one of the most common causes of artifacts is infinite radiosity rays. A good rule is to place any radiosity scene inside a large inverse sphere to avoid any ray colliding with the background or sky_sphere. Another potential cause of artifacts is coincident surfaces, sometimes a radiosity ray leaks through the corners of a box or between CSG seams, one work-around seems to be using a round box with a small radius instead of a box. Non-zero ambient values in textures emit light when radiosity is on. This may be intended, but it makes textures look wrong in test renders without radiosity. Using declared variables to adjust the ambient and diffuse values or turn on/off lights and/or radiosity is recommended

Partial Output

Partial image output will affect radiosity! Partial image output can be a good way of splitting up slow renders across different machines; unfortunately, the radiosity calculations will be adversely affected. If you render a scene with radiosity with full image output, then do a series of re-renders of the same scene using partial output and stitch the pieces together, there will be a visible difference in the two images. A possible workaround is to let a single machine calculate the radiosity on a lower resolution render without anti-aliasing, and use the save_file command to store the radiosity data. When the final version is run, ensure that the radiosity data is available to all machines or processes that need it, set always_sample to off, and both pretrace_start and pretrace_end to 1. This ensures that no radiosity calculations are performed and only the loaded data is used.


Using radiosity with sky_sphere

The sky_sphere is always the exact color you specify as it isn't subject to lighting calculations, therefore it can be thought of as having a finish of ambient 1 diffuse 0. Since radiosity is affected by any luminous object in the scene, the sky will be a light source in your scene.


Notes

  1. Radiosity is slow and requires lots of calculations. Using it requires a lot of patience, but the results are very rewarding.
  1. Radiosity usage will vary from scene to scene and taste of the artist using it.
  1. Radiosity isn't that haaaaaaard...