Shader System
The SRT Exporter can also output vertex and pixel shader appropriate for use with a deferred rendering system. In comparison to a traditional forward rendering system, integration of SpeedTree into a given engine is actually greatly simplified. Because lighting is handled after the render targets are written, no agreement has to exist between the two systems. Only the format and content of the G-buffer needs to agree.
The templates are located in the [SpeedTree_Apps_Location]/Bin/Exporters/ShaderTemplates/ folder where [SpeedTree_Apps_Location] is the SpeedTree Apps installation location. There are four main templates used for deferred-rendering pipeline:
The vertex shader templates are set up very much like their forward rendering counterparts, but the pixel shader is very different and less configurable. The forward rendering pixel shaders can a lot of code for efficient effect & lighting LOD (e.g. fading from per-pixel lighting to per-vertex), whereas the deferred pixel shading template contains no lighting code. It does, however, have some LOD behavior like fading or skipping the detail lookup, specular mask lookup, and transmission mask lookup.
Note: When using the SRT exporter to compile a set of deferred shaders, note that there will be other differences in the generated assets aparts from the shaders themselves. The SRT file itself will contain different vertex buffer contents as the vertex declarations will be different from the forward rendering versions. Largely, they will contain less data since lighting is handled later. The hash names for the shaders will also be different. |
---|
The SpeedTree reference application uses an example G-buffer to demonstrate what a complete pipeline might look like with a SpeedTree integration. We fully expect that your G-buffer configuration will not match with our example layout. But, the good news is, it's easy to configure it to match your own format. Specifically, the SpeedTree shader templates refer to Template_Gbuffer.fx, also located in [SpeedTree_Apps_Location]/Bin/Exporters/ShaderTemplates/. It contains a definition similar to the following (HLSL definition, also not including the depth/stencil buffer):
To modify what the deferred shader templates write to the G-buffer, modify the code at the end of Template_3dGeometry_Pixel_Deferred.fx and Template_Billboard_Pixel_Deferred.fx. Currently, each contains the code below. It should be a relatively simple matter to write anything you need, or even adding more render targets.