User Tools

Site Tools


The SpeedTree SDK employs a bank of pre-compiled shaders, generated and compiled by the SpeedTree Compiler application. Using the Compiler, users import a series of tree & grass models and, by settting various LOD and effects parameters, generate a bank of shaders shared by the imported trees. Because each group of geometry and/or LOD may be unique, it's not uncommon for six to twelve shaders to be associated with a single tree model: one for each material for each LOD. This ensures that the minimal number of shader instructions are always being used to render the tree at any LOD stage. Our measurements shows that, generally, this outweighs the shader switch cost, though there are shader generation modes in the Compiler that favor fewer, longer shaders.

Information on how to control draw call counts and performance are on the Compiler settings page and the GPU Performance page.

The shader source is firmly rooted in HLSL/Cg syntax, which is portable across the DX11, DX9, PlayStation 4, Xbox One, PlayStation 3, Xbox 360, and platforms. The source also successfully compiles using a GLSL compiler (although some extra macros are needed [and provided]), which is better suited for OpenGL-based platforms (Mac, Linux, and Windows).

General Compilation

The SpeedTree Compiler application will generate tree models and assets for use in a real-time environment. These assets can include:

  • SRT (SpeedTree Run-Time) files correspond one-to-one to artist-created SPM (SpeedTree Procedural Model) files. SRT files contain all of the vertex and index buffer data for each LOD, materials, wind parameters, collision volumes, and various other rendering data. The vertex and index buffer blocks are designed to be serialized directly into a targeted graphics API's native vertex and index buffers.
  • Pre-compiled vertex and pixel shaders for the 3D geometry, grass, and lowest-LOD billboards, for either a forward or deferred rendering engine. Depth-only shaders are also generated, but take the full vertex decl of their lit counterparts so that the VBs can be reused. Note that GLSL shaders, used with OpenGL, are not precompiled, but must be compiled on load.
  • Texture atlases for 3D geometry. Leaf, frond, and cap textures are combined into a single atlas to reduce draw calls. Diffuse, normal, specular masks, and transmission masks may be generated. Branch geometry is still kept separate due to backface culling and texture wrapping.
  • Texture atlases for billboards. Diffuse and normal maps are created using Compiler-generated images of the tree at its lowest LOD level. Multiple views are generated (configurable) so that a tree can effectively fade to a billboard from 3D from any angle. Normal maps are also included so that dynamic lighting can be applied.
  • Textures that are not atlased (normally branch diffuse, normal, and detail textures) are copied into the destination folder in a user-designated format.

Details on the controls and settings available in the SRT Exporter are here.

Compiled Shader Filenames

Depending on the compilation mode, the filenames of the generated shaders are like string hash keys, they're based on the render state that drove the shader generation (e.g. whether specular was enabled, LOD smoothing, transmission, per-pixel lighting, etc). It's nearly impossible for a user to read the shader filename and determine what the render state was, but if the Compiler option “Leave source” is enabled, users can open the corresponding FX shader source file and examine the #defines at the top of the file to determine the render state.