Tutorial level: Advanced
Example project: 'samples/rendering/post shading studio'.
In this tutorial we will examine how to collect channel information from the ray tracer in order to evaluate the basic illumination model in the post processing phase. Post processed surface shading has some advantages:
Sampled illumination data can be filtered before the shading. This reduces noise.
Recomputing the post shading after illumination parameter adjustments is often quicker than rendering the image from scratch. The speed advantage is remarkable when the scene geometry is complex and slow to ray trace.
The illumination model of Realsoft 3D - and the rendering pipeline in general - is open and customizable. This means that the parameters of a post shading system are not fixed. The user can any time code a new VSL material, which changes surface illumination in a totally new way. It's impossible to reproduce the functionality of the new shader accurately in a post shading system, which assumes other kind of shading behavior.
A simple post shading system renders very quickly and allows interactive adjusting of parameters. A complex post shading solution which controls the result image in a detailed manner - providing even object or light source specific parameters - is slower to use, but naturally provides much more possibilities to adjust the image. The optimal choice between speed and flexibility depends on each scene.
The standard setup of Realsoft 3D includes a set of example components for post shading. These components allow quite a detailed control over post shading. The components are built using the standard VSL objects and post effects, and therefore they can be modified and tailored to suit all kind of projects. For example, unused elements can be deleted to speed up rendering.
Let's experiment how to use the post shading system, which is included in the program setup.
1. Model first a test scene: a floor and a wall, a table, a glass object, a reflective object, etc. Feel free to use your imagination. Add a large sphere (sky dome) around the scene. Open the property window, go to the Col tab, select Surface Properties/Attribute = Illumination and enter a value 0.5 0.5 0.5. This makes the sky dome self-illuminated. Collect all elements of the environment (the sky dome etc.) under a hierarchy level 'world' and all directly visible surfaces of the room and the furniture under another level 'gi_system'. We will later apply post shading only to the items which are directly visible in the image; this saves some rendering time.
The test scene. Shadows are noisy because of minimal area light sampling.
Add also a rectangular special light source into the room. You can leve the Quality setting of the area light source to the minimal value 0. If you test render an image, shadows will show clearly visible sampling noise. Turn also view's flashlight off, because the post shading system includes its own independent flashlight.
2. Go to the material tab of the select window. Choose New/From Template from the popup menu of the select window. Use the opened file browser to find and load in the material 'realsoft3d/materials/illumination/capture channels'. Select the level 'gi_system' and drag and drop the loaded material 'capture_channels' to the view window. This maps the shader to the selected level. Shading information will be collected only from the objects inluuded in the 'gi_system' level.
3. Switch to the render settings tab of the select window. Drag and drop the render settings object 'GI_rendering' to the view window. GI_rendering does not compute anti-aliasing, which is usually quite important. The post shading system cannot afterwards separate illumination components from antialiased pixels, and therefore ray tracer antialiasing would cause shading errors. Antialiasing must be done after the post processing by down scaling the image resolution.
The channel capture shader mapped to gi_system hierarchy level
4. Go to the post image effects tab of the select window. Open the popup menu and choose Paste from a File. Load in the file 'realsoft3d/posteffects/post_shading'. Drag and drop either post_shading or post_shading_draft from the select window into the view window. The draft version does not use supersampled resolution to antialiase and is therefore 4 times faster.
Set image effects to post_shading_draft using drag and drop, activate Backup Ray Trace and Render
5. Open the popup menu of the view window. Make sure that Backup Ray Trace option is enabled. Then select Ray Trace.
First the ray traced image appears, then, after a while, a post-shaded version. The post shaded version is brighter, because it adds indirect illumination to the image. The dithered shadows are now smooth.
The next step is to experiment with the post shading parameters. Switch to the post image effects tab of the select window, and open the property window.
Shadow quality improved
6. To make reflections softer, select the blur_reflection effect and increase the Blur Level value using the property window. Then select Render/Post Process from the view popup menu. A new image appears much quicker, because ray tracing was not computed.
7. To make shadows even smoother, select the blur_shadows effect. Increase either the Blur Level value or the Iterations value. Then apply Render/Post Process.
8. To remove all reflections from surfaces, select the evaluate_shading effect and set Reflection to black (0,0,0). Then apply Render/Post Process.
9. Change the Flashlight value of the evaluate_shading effect to pale yellow (0.4, 0.4, 0.1). Post process again. The image gets a warm fill light effect
10. Set Specularity to (1.6 1.1 1.1), then Post Process. Specular highlights become brighter and get a red tone around the white brightness maximum.
Post shading parameters
|You can view the source data, from which the image is computed, using the channel menus located at the end of the view's Render popup menu. It is often useful to examine the contents of the deep backup image.|
As the experiments above show, the most important component of the system is the evaluate_shading effect. It is a VSL effect, which weights the stored channels and then recombines them to a new image. The VSL structure of the effect is quite straightforward and easy to customize. By default, all weights are set to the level (1,1,1), which reproduces the original ray traced illumination. Note, that although the weights are presented as RGB colors, their range is not limited to 0..1 interval. The full list of shading parameters is explained below.
Diffuse Illumination: rescales the usual diffuse shading. This is the most common shading component.
Specular Illumination: the weight for all non-diffuse illumination components from light sources. Specular highlights, ambient lighting and user defined Surface Illumination shaders contribute trough this parameter.
Self-Illumination: controls self-illumination of surfaces (usually defined as Surface:Illumination = RGB).
Reflection: controls mirror reflections.
Transparency: controls optical transparency i.e. refracted rays (not faded surfaces).
Flashlight: the fill light from the camera. Replaces (not rescales) the camera flash light.
Fog: the weight for a global fog surrounding the camera.
Other Shading: unusual custom effects which are not included in other post shading parameters.
Reflected GI: global illumination via reflective and transparent objects.
GI contrast: enhances bump maps and other fine details of surfaces.
GI control curve: the gamma correction curve for global illumination.
It should be noted that these parameters control only the first step of the recursive ray tracing. For the sake of speed and memory consumption, the system stores the channel values only from the first step of the ray trace recursion. For example, a self-illuminated surface which is seen in a mirror reflection does not become darker when you decrease the self-illumination parameter. Instead, the reflection weight controls its appearance.
The fog blurring effect, which is part of the post shading system, needs some special attention. With it, you can reduce the sampling noise of volume sampled fog shaders. Applying a pixel accurate fog shader to blurred shading components sometimes creates clearly visible errors. You can compensate this by making fog blurring as large as the maximum of the other blur components, such as the shadow blur effect.
Foggy atmosphere before and after post effect blurring
Let's take a closer look at the channel capture material. Go to the material tab of the select window, make sure that the material capture_channels is selected and open the property window. The material interface displays a large number of switches 'XXX Capture Off'. With these switches, you can turn off collection of unused data and consequently speed up rendering. By default, all channels used by the post effect shading are enabled. Light, Shadow and Distance capture are disabled, because they capture additional channel data which is not needed in post shading.
This material can be used in collecting information for all kinds of post processing purposes. The switches and their relation to underlying channels are:
The channel capture controls
Some important notes:
Specular Shading Capture collects all non-diffuse illumination elements. For example, ambient lights are included here. The name is chosen like this because specular highlights are probably the most common illumination effect in this category.
By enabling Shadow Capture, you can output the shadow channel into a shadow mask file. The shadow channel is not used by the post shading system.
Distance Capture computes a non-linear curve controlled z buffer value to the depth channel. Distances from 0 to infinity are mapped to the 0..1 interval, which means that the z buffer does not overflow or truncate the values regardless of the used datatype (byte, word, float etc.). The depth channel is not used by the post shading system.
The idea behind the capture_channels material is that in includes all surface related shaders. In each shader, the material examines how the total illumination and other relevant channels change and stores the observed changes to a set of additional channels diffuse, ambient, etc. As explained earlier in this tutorial, only the first step of ray trace recursion is stored.