User Tools

Site Tools


User Interpolants

Due to the way shaders are generated from templates in the SpeedTree system, it's difficult to modify the templates to add extra interpolants (those values passed from the vertex to the pixel shaders). A straightforward system exists to facilitate this.

Users have the option of adding up to four additional float4 interpolants by modifying the source contained in the shader template file Include_UserInterpolants.fx. By setting ST_USER_INTERPOLANT to 1 (default value is 0) at the end of this file, an extra float4 will be passed from the vertex shader to the pixel shader. If #define'd, float4 v2p_vUserInterpolant (“v2p” = vertex-to-pixel) will be created. It must be fully assigned in the vertex shader (that is, all components, .xyzw, must be assigned), else the compilation is likely to fail. Search for “ST_USER_INTERPOLANT0” in Template_3dGeometry_Vertex.fx or Template_3dGeometry_Vertex_Deferred.fx) to find where this should be done.

Keep in mind that users may put conditions on when the user interpolants are active. That is, interpolants don't have to be active for every generated shader. If, for example, you're passing a new value to be used with specular lighting, you can check for the presence of specular lighting by using code like:

#if (ST_WIND_IS_ACTIVE) // defined by the Compiler when generating each shader
    #define USER_INTERPOLANT0 1
#endif

Then, within the vertex shader, only assign the interpolant when present:

#if (ST_USER_INTERPOLANT0)
    v2p_vUserInterpolant0 = float4(<your_values_here>);
#endif

Be sure to only access the v2p_vUserInterpolant[N] variables in the pixel shader when they're defined.

Note: This system applies only to the forward- and deferred-render templates used for the 3D tree geometry. Billboard templates are not affected since they do not use dynamic interpolants. Users are free to modify the less complex billboard templates as needed.