Now, while doing Oren-Nayar (diffuse term) I realized I have to remove the 1/PI parts of the formulae to get the shader to look decent/correct instead of weird/too dark. Which led me to the above, learning that while academically “clean” illumination formulae used in papers use PI in some fashion, in game engines this is either handled differently or outside your lighting function — certainly we can see this is the case in Unity by looking at their “built-in shaders” source for LightingLambert.
So PI is definitely to be removed from the diffuse-term of the BRDF, whether old-school Lambert or very-rough Oren-Nayar.
Now the big question for specular term… — as per Graphic Rants: Specular BRDF Reference, various D functions (normal-distribution term, such as Beckmann, Blinn-Phong, Trowbridge-Reitz) and a few G functions (geometry/visibility term, such as Smith-Schlick) use PI.
As a non-academic, non-mathematician, hobbyist shader-haxor what’s the best heuristic for me to decide as to what PI parts to remove from those formulae and which to keep? Already tried to go by eye with and without the PI parts for all my G and D functions, but while they look different, I can’t tell “by eye” which one is really “correct” as intended by that method, and which one isn’t. Just slightly different sizings of the specular highlight.
Perhaps a better shortcut than a heuristic for modifying equations would be to find GPU implementations of the algorithms you’re after. The D3D Book has most of the ones you mentioned, with source code for all.
Looks like a good read, thanks! Bit old though but nevermind, should still be worthwhile education for me.
But not exactly a “shortcut” ;D as I said I already have written the formulae into Cg code and now whether I remove the PI terms or not, both versions for each of the many geometry-visibility+normal-distribution combinations always both look fine, different but fine, and I can’t tell which one is “correct”… ;))
maybe after studying the lighting chapter of this book I’ll know, seems like this topic just can’t be fast-tracked…
Unless you’re into science… “fine” is “correct”.
You know, phong / ashkmihn and the likes are approximations as well to nature.
And we haven’t even started worrying too much about different color spaces (aside from linear)…
Even if you have a perfect shader, the artist my still abuse and misuse it
I recently wrote a shader for Houdini and came across 4 or 5 different implementations of Cook Torrence.
That being said, I found the implementation from Disney the most trust worthy: http://www.disneyanimation.com/technology/brdf.html
If you download that software, you get nice GLSL code of all the shading models.
I think the idea of using pi in these equations is too ensure that the energy distributed across the hemisphere doesn’t exceed the energy put in (as pi in radians is 180 degrees - i.e. a hemisphere).
I don’t think you really need to bother with it unless you’re really focused on ensuring energy conservation.
To my understanding, there are two important concepts of “energy conserving”.
One is the one pointed out by Farfarer, which is important if you’re doing Global Illumination. So that you don’t get more light the more bounces the light does.
The second is how a specular highlight gets blurred. Ideally it should reflect the same amount no matter what “shininess” you define. Which means it’s a lot stronger if its near mirror like and a lot weaker if its fuzzier. It should peak in a perfect mirror.
I’ve myself done lot of research and experimentaion on that topic.
For diffuse you can remove this part of the equation for sure.
But for specular you shouldn’t remove the “Energy Conserving” part as it is the most needed of it.
Energy conserving means simply that a surface won’t reflect more light than it received.
So if you remove this you’ll loose one of the most benefit of having a physical based shading which is keeping same specular response across any lighting conditions and you’ll have to tweak all the time your lights and shaders if you change your lighting setup.
Thing you can do is simplify those D and G term if you worried about performance, largarde gives pretty good example of that with blinn-phong model.
As danybittel says there’s very nice shading model with the BRDF tool from dysney you can find/test/tweak and see in real time the changes.
I highly recomend you to read those articles :
SHADER X7 An Efficient and Physically Plausible Real-Time Shading Model.
Physically-Based Shading at Disney by Brent Burley.
Real Shading in Unreal Engine 4.
Crafting a Next-Gen Material Pipeline for
The Order: 1886.
Physically Based Shading in Call of Duty: Black Ops.
Getting More Physical In Call Of Duty Black Ops II.
Play with the roughness and you’ll see how it is important.
If my specular term wasn’t energy conserving my specular light would stay strong even with rough surface whith it’s not correct in real world because more a surface is rough more the light is reflected in lot of direction and its energy get lost.
Don’t pay attention to the cubemap the filtering is broken.