Terragen 4 Global Illumination

From Terragen Documentation from Planetside Software
Revision as of 02:55, 24 August 2019 by JavaJones (talk | contribs)
Jump to: navigation, search

Global Illumination in Computer Graphics[edit]

Global illumination is a general name for a group of algorithms used in 3D computer graphics that are meant to add more realistic lighting to 3D scenes. Such algorithms take into account not only the light which comes directly from a light source (direct illumination), but also subsequent cases in which light rays from the same source are reflected by other surfaces in the scene, whether reflective or not (indirect illumination). http://en.wikipedia.org/wiki/Global_illumination


Global Illumination in Terragen[edit]

GI garden 760x240.jpg

(Scene by Ulco Glimmerveen)

Direct illumination in Terragen is the lighting coming directly from the sun or other specific light sources, but not from luminous objects. Global illumination (GI) in Terragen means the lighting from everywhere else, including indirect illumination as well as illumination caused by bright, luminous objects that aren't specifically light sources. Beginning in version 4.4, there are now two methods for calculating Global Illumination, a faster but less accurate cache-based method and a more modern and accurate but more time-intensive "Path Tracing" mode. In a standard cache-based render the intensity of GI is controlled using a single Enviro Light node.

In Terragen, GI is:

  • The reason shadows are not black.
  • Lighting from the sky.
  • Lighting caused by light bouncing off other objects.
  • Lighting caused by light emitted from glowing, luminous objects, e.g. lava, fire, bioluminescence.
  • "Multiple scattering" in clouds and atmospheres. "Multiple scattering" in volumes is often thought of as a separate phenomenon from global illumination, but in fact it can be treated as a form of global illumination if the scattering is rendered as a lighting effect upon the volume. In Terragen, multiple scattering in the atmosphere (and some cloud layers) is approximated using the global illumination cache. Clouds and atmospheres will illuminate themselves in a way that simulates multiple scattering. Being part of the global illumination system, GI in volumes completely integrates with GI from surfaces. Light bouncing off or emitted from surfaces will light up clouds and atmospheres, and light scattering through clouds and atmospheres will light up surfaces.

In Terragen 4, the new cloud types "Cloud Layer V3" and "Easy Cloud" use a separate GI system with quality controls separate from the global illumination cache, but they visually integrate into the rest of the GI system just as well as the older cloud type "Cloud Layer V2".

When using the Path Tracer, the GI cache is still used, but only for lighting contributions from the atmosphere (including clouds). Please reference the Path Tracing page for more details on this method of rendering GI.

Rendering with GI[edit]

Rendering without saving a GI cache file[edit]

To render an image with Global Illumination in Terragen without saving GI cache files, you need the following:

  1. An Enviro Light in the scene, enabled, with its mode set to "Global Illumination"
  2. In Render GI Settings, 'GI relative detail' set to 1 or higher.

A GI cache will be dynamically generated at render time in this configuration, but that data will not be saved for potential later re-use in other renders.

You can turn off global illumination by disabling the Enviro Light, but Terragen might still waste time on the pre-pass. To completely turn off GI, edit the Render GI settings and set 'GI relative detail' to 0. All other GI settings can be left how they are.

Performance note: Do not enable more than one Enviro Light in the scene unless you really need to. If you wish to brighten the effect of the Enviro Light, increase the 'strength' settings in a single Enviro Light. Multiple Enviro Lights can increase GI quality, but they are not the best way to do that and they increase render time unnecessarily. You can achieve a more efficient increase in quality by increasing 'GI sample quality' in Render GI Settings. This will give a higher quality in a shorter render time than would enabling multiple Enviro Lights. The only good use for more than one enabled Enviro Light is to have one Enviro Light in Global Illumination mode and another in Ambient Occlusion mode, if you want that effect. Of course you can have as many disabled Enviro Lights in your project as you like.

Normally when you render an image with Global Illumination, Terragen renders the image in two passes. A pre-pass is rendered which calculates the Global Illumination for the image and stores it in a spatial data structure called a GI cache. When you see lots of tiny dots filling the image before the real rendering begins, you're seeing the pre-pass generating the GI cache. Once the pre-pass is done, rendering of the final pass begins. Global Illumination in the final image depends on the GI cache that was generated in the pre-pass.


Rendering with saving GI cache files[edit]

A new feature in Terragen 2.4 (not in the Free Non-Commercial Edition) is the ability to read and write GI cache files. These allow you to write the results of the pre-pass to disk or file network and to read them back in when rendering an image. Using GI caches files is a two step process. First you render a pre-pass which calculates the Global Illumination for the image (or sequence of images), and writes the resulting GI cache to your disk or network in the form of a GI cache file (or sequence of GI cache files). After you have created those GI cache files, you can render final images using the GI in the cache files instead of recalculating the GI every time you render an image.

You don't need to use GI cache files to enjoy Global Illumination. However, GI caches have many uses, such as:

  • Eliminating GI flicker in animations. To do this, read a single cache file or interpolate between cache files in a sequence.
  • Matching the GI in separately rendered tiles that you want to combine into a larger image, panorama, skybox or skydome. This is achieved by reading a single cache file or blending multiple cache files rendered with different cameras.
  • Rendering a GI pass (indirect illumination pass), by disabling all lights and reading the GI from a GI cache file.
  • Rendering special effects using GI that was generated with different lighting or other changes to the scene, e.g. some objects added or removed. You could write to a GI cache file using the scene that generates the GI you want, then render your final image with that GI cache file.
  • In Terragen 2, more control over the level of detail in your GI pre-pass than is possible with the GI relative detail setting, which only allows whole number values (Terragen 3 does not have this limitation). When writing to the GI cache, you can choose a different image size to render or a different value for 'detail'. Normally, 'detail' affects many things in your rendered image, but if you render the GI cache separately then you can choose a different detail for your GI. Image size and (in Terragen 2) detail both have the same effect on the detail of your GI solution as 'GI relative detail' -- they are all linear multipliers -- but you can change the detail more precisely with image size or the detail slider than you can with GI relative detail. (Terragen 3 uses a setting called 'GI cache detail' which is not affected by the detail setting.)


Generating a GI cache file sequence for animation

  1. Setup the lighting how you want it, doing test renders with "No GI cache file" checked in Render GI Settings (this is the default).
  2. Switch to "Write to GI cache file" in Render GI Settings. Specify a location and filename for your GI cache file. Include a frame formatter such as '%04d' (not including quotes) somewhere in the filename. This formatter will be replaced by the frame number, so that you can render a sequence of cache files. One file will be generated for each frame that you render.
  3. Generate the GI cache files by rendering a sequence, just like you would render a sequence of images. Final images will not be rendered or saved while "Write to GI cache file" is checked. You do not have to render every frame. "Time-sparse" caches, where cache files are separate by more than one frame, are useful to allow the final images to gradually blend between GI solutions instead of flickering from frame to frame. You can either render the sequence on your computer using the "Render Sequence" button or distribute it on a render farm like you would for final images. Generating caches for an animation can be distributed across many machines because each frame generates a different GI cache file.

Using the "time-sparse" technique is simply a matter of generating fewer files using a sequence where the frame step is greater than 1. For example, you might choose to render frames 10, 20, 30, etc. by setting the step to 10. However, if you change the step, it's especially important to be aware that any old files that exist from previous renders will be deleted only if they are overwritten by your latest render. They are not automatically deleted when you start rendering a new sequence. When reading the caches for your final image pass, Terragen simply looks at whatever files exist that match the file sequence you tell it to read.


Rendering a final animation

  1. Switch to "Read GI cache file(s)" in Render GI Settings. Specify the filename of one of the GI cache files that you generated. Any file in the sequence will do.
  2. Set blend mode to "Interpolate (for animation)". In most cases this is the best mode for animations. It is designed to work with time-sparse caches and gradually blend between sets of files according to the frame number. It will also work when there is a cache file for every frame, but in that situation it is equivalent to "Equal blend within range" mode except that it will blend one fewer cache files due to the nature of the interpolation algorithm. The various blend modes are explained in more detail in the Render GI Settings section.
  3. Choose the number of cache files to blend together to produce the GI solution for each frame. The higher this number, the higher the quality of the GI and the smaller the fluctuations will be while playing the sequence. If you have a GI cache file on every frame then it is even more important because it affects how much the GI flicker is reduced. However, higher numbers increase render time of the final images. If the GI cache files are quite large, especially if they were generated with a high GI sample quality setting, then this effect on render time may be significant.
  4. If there is too much fluctuation in the GI you have three options. A) You can slow down the fluctuations by moving some of the GI files out of the folder to make the caches even more sparse. However, this uses files that are farther away in time from the current frame, and if your camera is moving too rapidly you may see areas of inadequate GI coverage or reduced quality. B) Increase the "number of files to blend". Usually this will decrease fluctuations or flicker, but it may affect render times. If the camera is moving rapidly so that the extra files do not cover the region 3D space being rendered then the extra files may not even help. If all else fails you may need to re-generate GI cache files with a higher GI sample quality, but this might also increase render times for the final images.

If in doubt, a good starting point is to generate GI cache files with quality settings that work for still images you're happy with, generate every 10th GI cache file and set it to blend 3, 4 or 5 files for the final sequence.


Render GI Settings[edit]

Please note: all of these settings primarily apply to the "standard", non path tracing method of handling GI. When path tracing is used, these settings only affect GI quality for the atmospheric contribution to lighting information and thus tend to have a less significant impact on resulting lighting accuracy.

Prepass[edit]

GI cache detail: The GI cache records the lighting at many points across the image. These are the dots you see in the pre pass; each dot corresponds to one sample. Each sample stores light from many directions. GI cache detail affects the spacing of the samples in image space during the pre pass. Then, in the final pass the lighting at any part of the scene is a weighted average of nearby samples, or in other words a filtered interpolation. The lower the detail, the coarser the approximation. If the detail is too low, this usually shows itself as a blurriness or lack of clarity in the GI. Low GI cache detail can also cause some parts of the scene to be completely missed in the pre pass, and this could result in no GI (black) in those areas. This is more likely to be a problem with vegetation or objects that are small and sparse in the image. (This can happen even at high GI cache detail too, but is less likely.) GI cache detail affects the size of the GI cache in memory (and on disk if saving to a GI cache file) and it affects the amount of time taken to render the pre pass. It can also affect render time for the final pass, but much less so than "GI sample quality".

GI sample quality: At each sample point in the GI cache, many rays are cast outwards in a sphere to capture the lighting at that point. GI sample quality affects how many rays are cast outwards from each sample point. The actual number of rays is much greater than the setting (usually at least 6x), but in general a higher setting for GI sample quality results in more rays. If there's a lot of contrast with respect to the direction the GI is received from, higher sample quality may be needed to avoid what might be described as "blotchiness" or sometimes completely missing important sources of light. The default value of 2 may be enough for some landscape renders, but for high quality final renders you may wish to increase this and for architectural renders we recommend at least 6. GI sample quality also affects how much data is stored at each sample. Therefore both GI cache detail and GI sample quality affect the size of the GI in memory and the amount of time taken to render the pre pass. GI sample quality also affects render time for the final pass much more than GI cache detail does, as that primarily affects the pre pass time.

GI blur radius: Each GI sample point affects a spherical region of space in the final image, and where multiple sample spheres overlap they are averaged together. The radius of these spheres depends on various things that are decided by the renderer, but you can control a minimum radius that is enforced to ensure that enough samples overlap on every part of the image. GI blur radius affects this minimum radius in image space. Although it is in image space it is not measure in pixels. It is relative to the spacing of the GI prepass samples that you see in the prepass, but not including the extra samples created by "Supersample prepass". The default value is 8. Lower values may give the impression of greater detail in GI but can lead to increased blotchiness in images and flickering in animations. Increased GI blur radius can lead to smoother GI but apparent detail will likely be reduced. We believe that 8 is a good compromise for most renders.

In Terragen 3 & 4: Because the radius is relative to the spacing of the prepass samples, if you increase "GI cache detail" then the blur area in image space will be reduced. It works this way so that "GI cache detail" changes overall detail without affecting the quality of the interpolation.

In Terragen 2: Because the radius is relative to the spacing of the prepass samples, if you increase "Detail" (Render settings) or "GI relative detail" then the blur area in image space will be reduced. It works this way so that "Detail" and "GI relative detail" change overall detail without affecting the quality of the interpolation.

Supersample prepass: Supersample prepass takes more closely-packed samples in the prepass so that it is less likely to miss small or narrow objects that don't have any other objects nearby. If you can see that the prepass is missing objects and there are no other objects nearby (e.g. blades of grass in the foreground, or narrow tree trunks), you should probably enable this. Missed objects in the prepass can result in the shadows (areas where GI is important) being too dark. However, supersample prepass reduces the quality of each sample, which can reduce the overall quality of the GI, so it is turned off by default.


GI Cache File[edit]

No GI cache file: Renders the image normally. A prepass generates the GI and an image pass renders the final image.

Write to GI cache file: Renders only the prepass to generate the GI cache, then saves the GI cache to a file.

Read GI cache file(s): Renders only the final image. GI is read from a previously generated GI cache file or GI cache files.

Blend mode: Applies only when "Read GI cache file(s)" is selected. Blend mode can be set to one of the options below. "One file (exact filename)" reads a single cache file, but the other 3 modes work with sequences of files. If the base filename contains a number and other files in the same folder have similar names which differ only by this number, then they will be assumed to be part of the same sequence and the number will be interpreted as a frame number. The current frame number and the blend mode determine which file(s) in the sequence will be read.

  • One file (exact filename): Reads only one cache file, with the filename given to the right of "Read GI cache file(s)". This can be an exact filename, or if the filename contains '%04d' (without quotes) then that string will be replaced by a 4 digit frame number representing the current frame. Different numbers of digits are supported by replacing the '4' with a different number. If the file is not found then the renderer will report an error; sequences are not detected in this mode.
  • Nearest file in sequence: Beginning with the base filename (given to the right of "Read GI cache files"), this mode looks for files that belong to same sequence as the base filename. The renderer will read only one cache file, choosing the file whose frame number is nearest to the current frame number. You can choose any file in the sequence for the base filename.
  • Equal blend within range: Beginning with the base filename (given to the right of "Read GI cache files"), this mode looks for files that belong to same sequence as the base filename. The renderer will try to read as many files as the "Number of files to blend" parameter below, choosing the files whose frame numbers are nearest to the current frame number. Where the GI solutions overlap in 3D space, the results are averaged together, and wherever there are gaps in one file's solution (e.g. outside the camera's view) the other files can fill in data. You can choose any file in the sequence for the base filename.
  • Interpolate (for animation): This is simillar to "Equal blend within range" except that the files are weighted differently depending on the current frame number, to produce steady blends during animations. This mode becomes useful if your caches are 'sparse' in time. 'Sparse caches' are sequences of GI cache files where not every frame has a cache file. For example you might have a GI cache file on frames 10, 20, 30, and so on. If you do this, and you set the blend mode to "Interpolate (for animation)", a smooth blend will occur between the different sets of GI caches that are selected over the course of an animation. The more frames between cache files, the more gradual the blend will be. A ramp up/down weighting is applied to the first and last files that are used, giving you a linear interpolation between the results of different sets of files so that you don't see any pops between frames where the sets change. (Pops may still occur in places in 3D space where there is insufficient coverage by the cache files.) "Number of files to blend" should be set to 2 or more to allow the blending to work. This mode will also work when there is a cache file for every frame, but in that situation it is equivalent to "Equal blend within range" mode except that it will blend one fewer cache files due to the nature of the interpolation algorithm.

Number of files to blend: When the blend mode is "Equal blend within range" or "Interpolate (for animation)", this is the maximum number of GI cache files that will be read and blended together to render a frame. If the blend mode is "Interpolate (for animation)" then on some frames it will read one fewer files. This is because the linear interpolation sometimes causes the first or last file within range to have a weight of zero.


Advanced[edit]

GI prepass padding: This specifes how much to enlarge the area of image calculated during the prepass, which may be useful to avoid mismatched lighting between adjacent cropped renders or pieces of a panorama when not using GI cache files (GI cache files effectively solve this problem). A value of 0 means no padding. A value of 1 adds a border to each side of the frustum which is equivalent to the width or height of the image or crop region, which makes the frustum 3 times as wide and 3 times as tall. Negative values shrink the area/frustum instead of enlarging it.


Image Pass[edit]

GI surface details: GI surface details is designed to try to compensate for the lack of detail in the GI cache. Different versions of Terragen do this differently. It is a separate process that happens either at shading time (while the image is being rendered), or as a combination of post processes on the final image and on the buckets (tiles) during the render. You can use GI surface details either with a GI cache file or simply in a normal render where the GI cache is calculated in the pre pass.

In Terragen 3 and 4, GI surface details enhances the detail in shadows and adds light bouncing between surfaces that are quite close in image space. It consists of two processes, but both are designed to add detail that isn't already present in the GI cache. While the image is being rendered, every time a bucket (tile) finishes rendering it applies a post-process on the sub-pixel samples to capture extremely fine details in the surface and enhance them. Then when the whole image has finished rendering it applies another post-process on the final pixels to capture more details in the surface and enhance those. It only affects indirect light (GI) and some soft reflections, depending on how the reflections were rendered. It does not affect direct lighting. The post-process may take a few seconds for most typical renders (e.g. up to Full HD) or a few minutes for very large images (e.g. more than 10k). During this time the user interface might not respond, but should return when the process finishes.

In Terragen 2, GI surface details changes how points are shaded while the image is being rendered. It adds shadow detail that isn't already present in the GI cache by tracing rays a short distance from the shading point. It only affects indirect light (GI) and some soft reflections, depending on how the reflections are rendered. It does not affect direct lighting. This feature can significantly increase render times in Terragen 2.


GI in Clouds[edit]

The following settings affect the rendering of all cloud layers that are "Cloud Layer V3" or "Easy Cloud", which are new in Terragen 4. "Cloud Layer V2" nodes are not affected by these settings.

Cloud GI quality: This affects the accuracy of the background/indirect lighting component of Cloud Layer V3 and Easy Cloud (but not Cloud Layer V2). The background/indirect lighting component is light received from other parts of the scene, except for direct lights such as the sun. It includes light received from things like terrain, other cloud layers, and anything else in the sky that is not part of the same cloud layer. It does not include scattering within the same cloud layer, as that is handled separately. Cloud GI is most visible in the shaded parts of a cloud.

Cloud GI quality affects how accurately this light is calculated. Low quality settings tend to produce flicker in animations or sometimes blotchy looking lighting in the clouds, but render faster. Each step down in the menu represents an increase in the quality by doubling the number of light samples, but also an increase in render time.

Cloud GI max ray depth: Terragen 4.1 and higher. Like Cloud GI quality, this setting affects the accuracy of the background/indirect lighting component of Cloud Layer V3 and Easy Cloud (but not Cloud Layer V2). It limits the maximum ray depth at which to include light from other parts of the scene. You can think of this as the number of times light can bounce between different cloud layers. It does not limit how many times light can scatter within a single cloud layer, as that is handled separately. It only affects bounces between layers created by different nodes in the scene. If you have many cloud layers in the scene it's especially important to keep this number low (e.g. 1 or 2) to prevent long render times due to light interactions between cloud layers. This part of the renderer may be improved in future to allow higher ray depths without excessive render times.

Voxel scattering quality: Terragen 4.1 and higher. This affects all cloud layers of type Cloud Layer V3 and Easy Cloud, but not Cloud Layer V2. Light that is scattered many times through a cloud is calculated using a Monte Carlo technique that samples many different scatter paths through a voxel buffer. For every pixel that contains some cloud, many scatter paths may be calculated and averaged together. The render engine and shaders decide how many scatter paths are calculated at each image sample (ray from the camera), but you can increase or decrease this amount with Voxel scattering quality. This setting acts as a multiplier, so 100 will cause the renderer to calculate twice as many paths as it would at 50.

In most cases we recommend that you use the default value of 50. Scenes which are quite noisy can usually be smoothed using higher anti-aliasing (which will improve the whole image, not just the cloud), and you can leave the voxel scattering quality at 50. However, it may be possible to optimise the rendering of some scenes by changing this value up or down.

A single object or device in the node network which generates or modifies data and may accept input data or create output data or both, depending on its function. Nodes usually have their own settings which control the data they create or how they modify data passing through them. Nodes are connected together in a network to perform work in a network-based user interface. In Terragen 2 nodes are connected together to describe a scene.

A sample refers to a value or set of values at a point in time and/or space. The defining point of a sample is that it is a chosen value out of a continuous signal. In Terragen 2 it is usually a mathematical (procedural) function that is being sampled.

A parameter is an individual setting in a node parameter view which controls some aspect of the node.

When Terragen renders, it divides the image up into buckets or tiles. Each bucket is rendered separately, allowing multiple buckets to be rendered at once. It also allows memory to be used more efficiently.

A single element of an image which describes values for color and/or intensity, depending on the color system which the image uses. Groups of ordered pixels together form a raster image.