Share on Facebook Tweet on Twitter Share on LinkedIn Share by email
Symbolic Differentiation in HLSL

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:

  1. 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.
  2. 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.
  3. 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.




Technical paper:

The symbolic differentiation extension to DirectX HLSL is described in this paper. We further describe current limitations and workarounds, and provide in depth descriptions of several practical examples of the use of symbolic derivatives to simplify surface evaluation.  




Sample Code 

Sample Code:  

Sample code is supplied demonstrating the use of symbolic derivatives in a number of practical graphics scenarios. Procedural geometry is facilitated with automatic computation of surface normals. Dynamic bump maps are also generated using derivatives. Finally, those dynamic procedural textures are anti-aliased. Also provided is a simple geometry modeling program for generating procedural geometry shaders.