Tweaking the Cook Torrance BRDF

I’m still learning things about physically based shading using my PBRViewer, and this time, I wanted  to be able to experiment the variations of the Cook Torrance BRDF.

The Cook Torrance BRDF looks like this:

Cook Torrance BRDF


This equation is composed of three distinct terms:

  • F: The fresnel, represents how the reflectivity change at grazing angles.
  • G: The Geometry term, represents the probability that a microfacet will be visible from the light and view directions.
  • D The normal distribution term, defines the distribution of the orientation of the microfacets.

For more infomations you can read the very interesting “Physics and math of shading” by Naty Hoffman. For each term there is more than one possibility, and you can choose according to your need, and your budget the terms of your BRDF. Even if GGX is becoming the new standard, I wanted to experiment the other possibilities.

Brian Karis, while he was doing research on physically based shading for the Unreal Engine 4, listed all lot of variation for the different terms. This wonderful blog post can be found here. I used this references to implement each term in my viewer, so I can directly see the impact of each functions on the lightning, the shader being recompiled automatically when a term is changed.

I also added some other modifications, like beeing able to change the background color, light position, intensity, ambient light and reflection intensity, etc.

If you want to try it, you can download it here.

As always, if you see an error or if you have any feedback, please contact me, as I’m doing this to learn I would be happy to hear from you.

I also made my first step with substance designer, trying to do a marble texture.



6 thoughts on “Tweaking the Cook Torrance BRDF

  1. Nice !
    Reading shader code seems to miss a linear to rgb final color output, ?
    (or it’s done in a separate post proc)

    What’s the license ? for shader and for assets ?
    (would like to reuse at least the sphere pedestal)

    1. Thanks !

      The final gamma correction is done by the final sRGB buffer, but it would be better if I had sRGB inputs as well. I need to find the time to work on that.
      There isn’t really any licence, or restrictions, my goal is to learn and share, so feel free to use it. I’d be happy to be mentionned if my code is used, but you don’t have to.

      For the mesh I used this scene:
      You’ll find a .max scene, where you can rework on the geometry/UV, because the one I’m using is not very optimized. Again, it’s something I’ll have to work on. But if you prefer to use my obj file, you can.

        1. Very nice !
          It’s funny, because I’m also working on a WebGL port, i would like to do something for people to be able to experiment and share materials online.

          It’s perfect for the mentions, thank you !

    1. I think the best resource you can find is the Physics and math of shading linked in the post. You’ll find all the math needed !
      You can also read the book Real Time Rendering.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.