Tuesday, May 5, 2015

Replacing Blinn-Phong by GGX

When I first started using Unity 5, I had a lot of problems getting specular highlights right with the standard PBR shader. There was a lot of fireflies (very bright pixels that are flashing when moving the camera) and highly visible specular aliasing. This was mostly caused by how Unity compute specular highlights.

The standard Unity 5 shader uses the Blinn-Phong equation to compute the specular part of the lighting while most other modern engines uses GGX. The problem with Blinn-Phong is that it renders a very small and intense specular highlight that accentuate artefacts especially when rendering with HDR. It will cause more visible specular aliasing and it will break intensity based effects like bloom (fireflies).

A more natural way to compute specular highlights is to use a more diffuse equation like GGX. It looks softer and it will attenuate specular aliasing as well as fireflies artefacts. It turns out that you can enable GGX highlights in Unity 5 but it has been disabled by default.

When looking at the deferred PBR shader, I did found that the code to compute GGX is there and that it is possible to modify the source code to get GGX working again.

If you use the deferred renderer, the switch to GGX is painless to make. You only need to replace the deferred shaders in “Edit/Project Settings/Graphics” to the custom GGX deferred shader I uploaded. If you use the forward renderer, you will need to replace all your shaders with the GGX-Standard shader.

You can download the modified shaders here (you need to put all those shaders in the same folder):


  1. Omg, you're AWESOME - do you like space games? PM me and i'll send you a Steam key as thanks...

  2. Hmmmm OK so comments are anonymous and I don't want to self promote shamelessly - oh well, you seriously helped us out anyway thanks!

  3. Thank you very much for sharing this! Works great: http://forum.unity3d.com/threads/unity-5-pbr-weak-spots-example-scene-included.361446/

  4. This is awesome - no more "coated with grease" look for my assets - lol

  5. Hello! I'm sorry for asking a certainly stupid question, but I'm kind of new to Unity shaders and I don't know how to use this? Where do I have to put the shader files? In my unity project? And then what do I have to do? Do I have to plug them into the Project Settings / Graphics instead of the built-in shaders? Thank you!