User Tools

Site Tools

Shader Templates

All of the tree and grass shaders are generated from shader templates included in the SpeedTree Compiler application. These templates hold all of the code necessary for both complex and simple effects and everything in between. Each of the effects are controlled by compile- or run-time flags in the shader source. When a level of effects is chosen, the Compiler will #define a series of macros that describe which effects are employed. The source files are passed into the target platform's off-line compiler utility (e.g. fxc.exe for DirectX/360), ultimately generating short, concise, precisely-fitted shaders for use with the SDK.

Note: The SpeedTree collection of shader templates and associated utility files are designed to compile on all SpeedTree-supported platforms, including OpenGL/GLSL.

The Compiler will also generate custom vertex shader inputs and interpolants based on the active effects (info on adding user-defined interpolants).

The templates are located in the [SpeedTree_Apps_Location]/Bin/Exporters/ShaderTemplates folder where [SpeedTree_Apps_Location] is the SpeedTree Applications (e.g. Modeler or Compiler) installation location. There are four main templates used for a traditional forward-rendering pipeline (details for deferred rendering pipelines):

  • Template_3dGeometry_Vertex.fx: Contains the vertex shader entry point for all tree & grass models rendered in 3D.
  • Template_3dGeometry_Pixel.fx: Contains the pixel shader entry point for all tree & grass models rendered in 3D.
  • Template_Billboard_Vertex.fx: Contains the vertex shader entry point for the 360-degree billboards.
  • Template_Billboard_Pixel.fx: Contains the pixel shader entry point for the 360-degree billboards.

In addition to deferred versions of these templates, there are two other variations of these templates for 3D geometry: Template_3dGeometry_*_ShadowCast.fx and Template_3dGeometry_*_DepthPrepass.fx, and billboard geometry: Template_Billboard_*_ShadowCast.fx and Template_Billboard_*_DepthPrepass.fx.

There are also a series of common FX files shared by all of the shaders, including (not an exhaustive list):

  • Include_Utility.fx: Defines numerous utility functions for unpacking, fading, coordinate system conversions, etc.
  • Include_SetUp.fx: Contains a series of macros and other definitions that help make the shader source portable across SpeedTree's supported platforms.
  • Include_Uniforms.fx: Defines all of the uniform constant buffers shared by all shaders, including specifying their register location so that constant sharing across separate shaders is efficient.