|[ < ]||[ > ]||[ << ]||[ Up ]||[ >> ]||[Top]||[Contents]||[Index]||[ ? ]||[ Search: ]|
The simplest method to select the deferred render manager is to use the following configuration option:
Engine.RenderManager.Default = crystalspace.rendermanager.deferred
Alternately, the deferred render manager can also be loaded manually as follows:
rm = csLoadPlugin<iRenderManager> (objectRegistry, "crystalspace.rendermanager.deferred");
Note: When loading the deferred render manager manually the 'CS/data/config/engine.cfg' configuration file will not, by default, be present in the configuration manager. This file specifies configuration options used by the deferred render manager. Be sure to define these configurations option prior to loading the deferred render manager.
After being loaded, the engine must be instructed to use the deferred render manager as follows:
Before lighting can be computed the deferred render manager will fill the GBuffer with the current sectors geometry information using the ‘gbuffer fill’ shader type. Each material can specify its own ‘gbuffer fill’ shader type that will be used by the deferred render manager. If no such shader type is specified then a default shader (‘CS/data/shader/deferred/fill_gbuffer.xml’) will be used.
After the GBuffer is filled with the relevant information the deferred render manager will compute lighting information. To do this the render manager will iterate through all visible lights in the sector and draws proxy geometry that approximates the size and shape of the light source. Each light proxy is drawn using a shader that reads data from the GBuffer, computes the lighting equation, and adds it to the accumulation buffer.
The following types of light sources are supported:
Represented as a sphere. The detail of the sphere can be controlled using the ‘RenderManager.Deferred.SphereDetail’ configuration option (defaults to 16). The proxy geometry is drawn using the ‘CS/data/shader/deferred/point_light.xml’ shader.
Represented as a cone. The detail of the sphere can be controlled using the ‘RenderManager.Deferred.ConeDetail’ configuration option (defaults to 16). The proxy geometry is drawn using the ‘CS/data/shader/deferred/spot_light.xml’ shader.
Represented as a cube. The proxy geometry is drawn using the ‘CS/data/shader/deferred/directional_light.xml’ shader.
The deferred render manager will also output ambient light for the entire sector by drawing a single fullscreen quad with the ‘CS/data/shader/deferred/ambient_light.xml’ shader. This shader will modulate the GBuffers ambient and diffuse color at each pixel.
Note: The shader include ‘CS/data/shader/deferred/light_common.cginc’ file contains a number of useful functions for use with light proxy shaders.
The default GBuffer consists of three 16-bit floating-point RGBA color buffers along with one 32-bit depth and stencil buffer.
Note: Depending on hardware support the depth buffer might not contain any stencil bits.
The default data layout is presented in the following table:
+-----+-------+------+--------------+ | Red | Green | Blue | Alpha | +--------------+-----+-------+------+--------------+ | buffer 0 | diffuse (RGB) | specular (R) | +--------------+--------------------+--------------+ | buffer 1 | normal (XYZ) | specular (G) | +--------------+--------------------+--------------+ | buffer 2 | ambient (RGB) | specular (B) | +--------------+--------------------+--------------+ | depth buffer | depth and stencil value | +--------------+-----------------------------------+
The data stored in the GBuffer is described below:
The red, green, and blue components of the geometries diffuse color.
The red, green, and blue components of the geometries specular color.
The red, green, and blue components of the geometries ambient color.
The xyz components of the geometries normal vector in view space. Normalized and mapped into the range [0,1].
depth and stencil value
The nonlinear post projection depth value and an optional stencil value.
The layout of the GBuffer can be changed using the following configuration options:
Controls the number of color buffers present in the GBuffer (defaults to 3).
The maximum number of color buffers can be queried from the
device as follows:
const csGraphics3DCaps *caps = G3D->GetCaps (); int maxColorBuffers = caps->MaxRTColorAttachments;
Controls the format of the color buffers (defaults to
Note: Using 8-bits per color channel to store the view space normals can cause noticeable banding.
Controls if the GBuffers depth buffer is present (defaults to
Note: It is the responsibility of the 'gbuffer fill' and light proxy shaders to account for changes in the GBuffer layout.
The deferred render manager provides additional shader variables that are only available to the light proxy shaders:
tex gbuffer N
Specifies the Nth color buffer where N is between 0 and
RenderManager.Deferred.GBuffer.BufferCount - 1.
tex gbuffer depth
Specifies the GBuffers depth buffer. Only available if the GBuffer has a depth buffer.
light position view
The position of the light in view space. Only available for point lights and spot lights.
light direction view
The direction of the light in view space. Only available for spot lights and directional lights.
The accumulation buffer used by the deferred render manager to store lighting
results is fixed to be the same size as the GBuffer. However, the format of the
accumulation buffer can be controlled through the
‘RenderManager.Deferred.AccumBufferFormat’ configuration options (defaults
rgb16_f). Using a more compact format (
rgb8 for instance) may
be useful if high precision is not needed or memory is an issue.
Note: Each heavy portal (a portal that requires its sector to be rendered to an offscreen buffer) that is visible in the current frame will have its own accumulation buffer. Take this into consideration when choosing the accumulation buffer format.
Due to the limitations of the deferred shading technique it is necessary for the deferred render manager to allow for some objects to be drawn using forward shading. The deferred render manager uses a meshes render priority (see section Render Priorities and Objects in Sectors) to determine if the mesh should be drawn using forward shading. The render priorities that the deferred render manager considers forward shading priorities can be controlled through the ‘RenderManager.Deferred.ForwardPriorities’ configuration option. This configuration option contains a comma separated list of render priority names (defaults to ‘alpha,transp,portal’). Any mesh belonging to one of these render priorities will be drawn using forward shading.
Note: Heavy portals must belong to a render priority that will be drawn using forward shading. Any heavy portal that is not drawn using forward shading will appear as solid black polygons.
In general the use of render layers is unnecessary for deferred shading because there is only one well defined layer. However, the deferred render manager must also support forward shading and, as a result, more complex render layers are needed. The render layers can be controlled through the ‘RenderManager.Deferred.Layers’ configuration option (defaults to ‘/data/renderlayers/lighting_default_deferred.xml’). The deferred render manager expects there to be one render layer that specifies the ‘gbuffer fill’ shader type. This layer is reserved for deferred shading and will not be used during forward shading. All other render layers will be used for forward shading only.
Note: If no render layer is specified with a ‘gbuffer fill’ shader type then a default layer will be added that uses the ‘CS/data/shader/deferred/fill_gbuffer.xml’ shader.
The deferred render manager implements the
iDebugHelper interface and
responds to the following debug commands:
Toggles a display of the GBuffer at the bottom of the screen. The GBuffers color
buffers will be displayed in order from left to right followed by the GBuffers
depth buffer. The debug command can be activated through BugPlug (see section Using the BugPlug Debugging Plugin) using the
Toggles a display of the light proxy geometry drawn for each light. The debug
command can be activated through BugPlug using the command
|[ < ]||[ > ]||[ << ]||[ Up ]||[ >> ]||[Top]||[Contents]||[Index]||[ ? ]|
This document was generated using texi2html 1.76.