CPU Side

Some management on the CPU side is necessary for the standard SpeedTree shaders to function correctly. In a nutshell, the CPU is used to compute and upload a series of constant buffers shared by the vertex and pixel shaders. In the shader source templates, these constant buffers are defined in Template_Uniforms.fx (this file contains multiple definitions to accomodate various platforms), and ShaderConstantBuffers.h in the C++ source. If the SpeedTree SDK is bypassed but the shaders are used, there are essentially four areas that need to be addressed (some of which can be skipped if the related system is bypassed) in the C++ code:


ShaderConstantBuffers.h

ShaderConstantBuffers.h, in the RenderInterface library, is the central database of uniform shader constants across all platforms. This header file defines a number of structures and platform-independent constant buffers shared by both the vertex and pixel shaders. These are the same constant buffers declared in the shaders, found in Include_Uniforms.fx and their precise agreement is critical.

In the SpeedTree SDK, structres like SFogAndSkyConstBuf are set up from a base class to handle synchronizing with the shader-side constant buffer (see CShaderConstantBufferRI in [SpeedTree SDK 7]\Include\RenderInterface\GraphicsApiAbstractionRI.h for full details). That is, users are free to assign values in the structure, but it will also handle syncing to the shaders. Functions that facilitate this, part of every constant buffer declaration in the SDK, include: