Over in the GameDev forums, a user has posted some code and a nice technical paper on coding up a Torrance-Sparrow shader for BRDF lighting calculation.  Many people opt for the simple Lambertian models due to their speed and simplicity, but the Torrance-Sparrow model has some nice features that make it attractive.

Many game developers fail at getting their implementation to behave well because the model has some nasty divisions by terms which tend toward zero. In the theoretical model this is not supposed to happen but in computer graphics it does for various reasons. For instance the GPU will back-face cull a primitive in a way which gives results similar to using the face normal for culling. However, we don’t shade using the face normal. This means v_dot_n in the denominator will in practice become zero when using normal maps (and even interpolated vertex normals). Simply checking if the term is close to zero and then setting it to something else isn’t going to work either because this makes the lighting behave in a discontinuous fashion which is bad too. So care must be taken to get the right limit value.

via Finally nailing the Torrance-Sparrow shader once and for all. – GameDev.net.