• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Chris_F

Cook-Torrance / BRDF General

11 posts in this topic

I decided to test out Cook-Torrance in place of normalized Blinn-Phong, and while it's not difficult to implement, it's difficult to know if I'm doing it right, mostly because there is some variation depending on what sources you look at. For instance, I've seen three versions for the Cook-Torrance equation:

 

[attachment=13494:eqn1.png]

 

I saw PI in the denominator in Cook's paper, I believe I saw nothing in the version in a publication by Wolfgang Engel and in gpwiki.org's D3DBook (probably copied), and on wikipedia there apears a 4, as well as on a video I saw from UC Davis.

 

Then there is the NDF:

 

[attachment=13495:eqn2.png]

 

This is how it apeared in Cook's paper, but I've also seen:

 

[attachment=13496:eqn3.png]

 

Someplace I saw that PI was a normilization factor. I'm not sure if this is correct, and if it is why it was not present in Cook's paper or other papers for that matter. I want to be sure that everything is normalized and energy conserving.

 

Maybe as one last question, I'd like to know the propper way for ensuring that there is energy concervation between specular and diffuse.

0

Share this post


Link to post
Share on other sites

Here you go (slide 58)

To ensure energy conservation between specular and diffuse:


fresnelDiffuse = FSchlick(cSpec, light, normal);
fresnelSpecular = FSchlick(cSpec, light, halfway vector);
finalColor = specularColor*fresnelSpecular + diffuseColor*(1-fresnelDiffuse)

You can even approximate the diffuse fresnel (according to tri-Ace):

finalColor = specularColor*fresnelSpecular + diffuseColor*(1-cSpec)

 

 

You can use the Schlick Fresnel approximation (in slide 44) to calculate the fresnel.

 

EDIT: Distinction between diffuse and specular fresnel.

Edited by TiagoCosta
0

Share this post


Link to post
Share on other sites
Tiago, that's an approximation, even with the real Fresnel equations, but is not really correct.

Fresnel is dependent on the microfacets oriented towards the halfway vector, but diffuse actually is all the light that is not being reflected, not being absorbed and scattered back out, independent of the microfacets oriented towards the halfway vector. So simply the complement of a single fresnel value won't do it. You would need to solve the integral over all the microfacet orientations with a modified microfacet model:

eqn1.png

Your approximation might actually be worse than not having a factor for diffuse at all. If anything I'd use the macro surface normal instead of the halfway vector (just for diffuse though, for specular you should use the microfacet normal):

eqn2.png Edited by CryZe
2

Share this post


Link to post
Share on other sites

Tiago, that's an approximation, even with the real Fresnel equations, but is not really correct.

Isn't real-time graphics programming all about approximations? rolleyes.gif
 

This is simply the way I've been doing it (that I learned from papers/presentations).

 

Your approximation might actually be worse than not having a factor for diffuse at all. If anything I'd use the macro surface normal instead of the halfway vector (just for diffuse though, for specular you should use the microfacet normal):

 

You're right! I just checked my shaders and there's indeed a (1-Fdiffuse) calculated using the macro surface normal and Fspec using the halfway vector).

 

I just checked a tri-Ace paper and they even approximate the diffuse term like this:

diffuse = (diffuseColor/PI) * (1-f0)
//where f0 is the reflectance at normal incidence

 

 

 

P.S: Could you fix the equations in you're post?

0

Share this post


Link to post
Share on other sites
As an employee of tri-Ace I can confirm that we use the Fresnel approximation.  In the world of graphics, “approximation” always means “less accurate, but faster.”
 
But to use the Fresnel term to modify the diffuse is not always correct.
Imagine if the specular color is [0, 0, 0].  It is the same as there being no specular term.  Which means if you try to balance the energy between the specular and diffuse by just using the Fresnel term, and if the Fresnel term is close to 1, you would have multiplied the diffuse by almost 0 and yet added almost nothing from the specular term.  Since energy conservation depends on how much gets reflected directly as the specular term vs. how much gets reflected as the diffuse term, the balance depends on the specular term itself as well as other factors (such as microfacets).
 
But I am not the originator of those papers, my boss is.  And I am still learning from him the wonderful world of physically based rendering.
I don’t know yet myself how to balance the terms for every rendering equation, but I am learning, and I know enough to at least say that the Fresnel term alone is not enough.
To be quite frank, I would love it if anyone could post how to go about balancing these terms for any rendering equation.  Not to be spoon-fed the way for just one equation, but to be taught the method I could use to determine a solution for any equation.
 
 
L. Spiro Edited by L. Spiro
2

Share this post


Link to post
Share on other sites

So here is the implementation I'm ussing at the moment:

 

float3 H = normalize(L + V);
float NdotL = max(0, dot(N, L));
float NdotH = dot(N, H);
float NdotV = dot(N, V);
float VdotH = dot(V, H);

float NdotH_2 = NdotH * NdotH;
float NdotH_4 = NdotH_2 * NdotH_2;
float m_2 = m * m;
float D = exp((NdotH_2 - 1.0) / (NdotH_2 * m_2)) / (PI * m_2 * NdotH_4);

float3 F = R0 + (1.0 - R0) * pow(1.0 - VdotH, 5.0);

float geo_a = (2.0 * NdotH * NdotV) / VdotH;
float geo_b = (2.0 * NdotH * NdotL) / VdotH;
float G = min(1.0, max(0, min(geo_a, geo_b)));

float3 Rs = (D * F * G) / (4 * NdotV * NdotL);
float3 Rd = Cdiff * NdotL;
float3 R = Rs * NdotL + Rd * (1.0 - R0);

 

Is this correct?

0

Share this post


Link to post
Share on other sites

I've approximated the diffuse transmittance integral and created a BRDF which is pretty lightweight but also pretty physically accurate. Use this instead of Lambert if you want to have proper energy conservation. It's based on GGX roughness though, so you might need to convert your roughness to GGX roughness:

 

eqn5.png

 

It's actually just a single MAD instruction per light if you implement it, the rest can be done on a per pixel basis.

Edited by CryZe
2

Share this post


Link to post
Share on other sites

Ok, so I've been giving GGX a look. Unfortunately I haven't been able to find much information on it, at least not nearly as much as Beckmann's.

 

I gather this is the correct normalized version?

 

[attachment=13573:eqn.png]

 

Currently I've only evaluated the Blinn-Phong NDF, Beckmann and what I think is the correct GGX NDF. One thing that I noticed right away is that Blinn-Phong and Beckmann are nearly identical for roughness values below 0.3 or so. From 0.3 to 0.5 they are still pretty similar. GGX on the other hand is substantially different across the board, and that was with the Cook-Torrance G function. Next I tried your BRDF and the differences grew even further. I'm not sure which is more physically correct, but to my eyes I think I might prefer Beckmann + Cook-Torrance.

 

Here is a graph of theta H for a roughness of about 1.2:

 

[attachment=13574:Untitled.png]

 

Blue is Beckmann and C-T G. Red is GGX and C-T G. Green is your BRDF.

Edited by Chris_F
0

Share this post


Link to post
Share on other sites

The only difference between mine and your GGX, is that I'm using the Walter GGX geometric term which is specifically calculated using Smith's "blackbox" function to convert any distribution function into a perfectly matching geometric term. The thing is, that the cook torrance geometric term is more or less completely absurd and unrealistic, because the shadowing and masking should be dependent on the microfacet distribution, but the cook torrance geometric term completely ignores that. That's why you get that unrealistic cut at 45 degrees. I'd recommend you take a look at Naty Hoffmann's presentation and Disney's presentation at http://blog.selfshadow.com/publications/s2012-shading-course/. You should also check out Disney's BRDF Explorer and the MERL database. With the BRDF explorer, you can validate how well your BRDF matches actual materials from the MERL database. 

 

Also, your GGX is the correctly normalized version ;)

Edited by CryZe
0

Share this post


Link to post
Share on other sites

Looking through one of Disney's papers, I came across what they refer to as "Generalized Trowbridge-Reitz."

 

[attachment=13595:Untitled.png]

 

The one in the middle is supposedly Trowbridge-Reitz/GGX, and the one on the bottom is the generalized version, but I don't understand the way they have their equations set up.

 

Edit:

 

Ok, after looking at a more detailed paper, it looks like the normalized version of their Generalized Trowbridge-Reitz is this:

 

[attachment=13596:eqn.png]

 

This is interesting because by altering gamma you can adjust the size of the specular tail. Adjusting it doesn't seem very intuitive though. Adjusting gamma not only changes the size of the specular tail, but also changes the point at which it peaks. Is there a way to make alpha and gamma independent?

Edited by Chris_F
0

Share this post


Link to post
Share on other sites

Hello !

(1 - f0) is really bad for larger than 0 Roughness values.

You should integrate the fresnel with GGX or some other microfacet models.

But I know a good approximation, u can just simply integrate fresnel from 0 to Roughness then divide by Roughness
Assume Fresnel(0, SpecularColor) gives you SpecularColor
Assume Fresnel(1, SpecularColor) gives you 1

finalcolor = specular + someNonFresnelDiffuseModel * integrate( (1 - Fresnel) / R , from 0 to R )

R division needed because the same amount of microfacets should lie between 0 and R

FGD / ( 4 * NoV * NoL) is the good Cook Torrance equation. I checked it numerically and analitically, It's perfect for geometrical behavior. Diffraction is another question

Edited by HSDXPRO
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0