User Tools

Site Tools


GLSL

GLSL cannot be precompiled, which makes OpenGL the only SpeedTree-supported graphics API where precompiled shaders cannot be used. The biggest impact with this is that the SpeedTree Compiler can generate a pretty large bank of shaders for a given forest. As such, it may take much longer for OpenGL to load a bank of shaders (e.g. many seconds), than for a platform that supports precompiled shaders (e.g. just a couple hundred milliseconds).

Note: The SpeedTree OpenGL renderer employs a mechanism to save off the compiled shader using a platform-specific format. This will result in much faster shader loading on subsequent runs, but the generated files are videocard vendor-specific.

Two operations are necessary for GLSL to behave similarly to its HLSL counterpart to be portable in the SpeedTree SDK:

  1. The vertex shader incoming vertex attributes must be manually bound. When a vertex attribute is declared, an OpenGL driver's GLSL compiler is free to bind it to any of the attribute slots 0 to 15, and consistency between compilers is not required. To gain reliable consistency, the SpeedTree SDK will lookup the vertex attributes by sequential name (e.g. in_vSlot0, in_vSlot1, etc.), and assign them to attribute locations 0, 1, etc. respectively. This is handled in BindVertexAttributes() in Shaders_inl.h of the OpenGL renderer library.

  2. Textures must be bound to their samplers, and bound consistently across all shaders (more on what that means here: http://www.opengl.org/wiki/GLSL_Sampler#Binding_textures_to_samplers). This is handled in BindTextureSamplers() in Shaders_inl.h of the OpenGL renderer library, and note that it will need to be updated if more samplers/textures are added to the system.