We describe the new symbolic differentiation feature in HLSL. We provide details of the compiler implementation, along with information relevant to a shader writer wanting to use the feature.
Working with the DirectX product group we have incorporated symbolic differentiation into the HLSL programming language(released in the June 2010 DirectX SDK). This new feature makes it possible to solve problems that would have required either coarse numerical approximations or tedious, error prone manual differentiation.
We have developed fully coded examples and documentation that will help game developers using 3D graphics learn to fully exploit this technology. We will show several of these examples:
- Real time procedural models are described by procedures, so they are very small (hundreds of bytes). The mesh describing the model is generated at runtime on the GPU. This minimizes memory bandwidth use and provides automatic level of detail.
- Computing normals of procedural textures requires computing derivatives. The GPU ddx functions give results showing obvious shading artifacts. Exact derivatives give much better looking results with minimal overhead.
- Anti-aliasing of dynamic procedural textures, where the traditional solution of mip-maps is unavailable, is achieved through the projection of the partial derivatives of screen space position with respect to surface position back onto the instantaneous plane of the surface. This provides a reference scale, to which the frequency content of the texture may be adjusted.