Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Your preferred or desired BRDF?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
51 replies to this topic

#1 Promit   Moderators   -  Reputation: 7560

Like
2Likes
Like

Posted 22 February 2013 - 04:30 PM

I'm just curious what everyone's using nowadays, or what you'd like to investigate looking forward. I guess Normalized Blinn Phong is the easy starter choice, and Cook-Torrance is a popular model amongst the more expensive ones. But I'm wondering what else is out there and what the advantages and disadvantages of those models are.

 

Also, what BRDF do you want to use that is currently near feasible? What would you choose if your min spec was 3x SLI GTX Titans? ;)



Sponsor:

#2 Matias Goldberg   Crossbones+   -  Reputation: 3694

Like
3Likes
Like

Posted 22 February 2013 - 06:25 PM

You may want to check:

Disney Slides
Beyond a Simple Physically Based Blinn-Phong Model in Real-Time (+ slides)
Calibrating Lighting and Materials in Far Cry 3

As you can see, brdf was a a hot topic last year in SIGGRAPH 2012.

PS: There's more.

Cheers.

#3 L. Spiro   Crossbones+   -  Reputation: 14196

Like
5Likes
Like

Posted 22 February 2013 - 07:10 PM

I personally like how Ashikhmin-Shirley looks since the diffuse term changes with the view angle.  This is true for Oren-Nayar as well but it is less noticeable.

We presented a more accurate and more efficient Oren-Nayar last year at SIGGRAPH (see links provided by Matias Goldberg: “Beyond a Simple Physically Based Blinn-Phong Model in Real-Time (+ slides)”)

 

I am not so much into Cook-Torrance as it seems to result in overpowering speculars, at least for me.  Since I don’t have a way to actually specify reflectance at normal incidence on my models for my engine yet it could be that I just don’t have a very good conversion of specular power to reflectance at normal incidence.  But checking images online they do also seem to have much wider and area-encompassing speculars.

 

 

I would use our improved Oren-Nayar model by default for low-end devices.

If computing power is removed from the equation I would stick with Ashikhmin-Shirley coupled with the layered material system that was also presented in the same link as above (of course, only when appropriate—not all surfaces need a layered-material system).

 

Here are results of Ashikhmin-Shirley:

LSBRDF19.png

This shot in particular sold me on Ashikhmin-Shirley with the nice transition of oranges over the hood of the car.

 

LSBRDF20.png

No ambient-occlusion was used on the bumper.  It is just the natural result of Ashikhmin-Shirley.

 

More…

 

 

L. Spiro


Edited by L. Spiro, 22 February 2013 - 07:12 PM.

It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#4 Jason Z   Crossbones+   -  Reputation: 5282

Like
4Likes
Like

Posted 22 February 2013 - 07:35 PM

If you are interested in a good overview of the semi-standard lighting models, take a look in the Lighting section of Programming Vertex, Geometry, and Pixel shaders.  Jack wrote a good, in-depth discussion of each of them individually, and the shader code should be at least a good starting point for your work (assuming HLSL of course...).

 

P.S.: My preference is: all of them!  Make your material system flexible enough to swap them in and out with data definitions!



#5 Chris_F   Members   -  Reputation: 2459

Like
7Likes
Like

Posted 22 February 2013 - 08:18 PM

I've taken to Cook-Torrance with the GGX distribution and Smith geometry factor (thanks CryZe) for specular, and the qualitative version of Oren-Nayar for diffuse.

 

analytic

::begin parameters
color Diffuse 1 0 0
color Specular 1 1 1
float DiffuseScale 0 1 0.5
float SpecularScale 0 0.999 .028
float Roughness 0.005 2 0.2
::end parameters

::begin shader

vec3 BRDF( vec3 L, vec3 V, vec3 N, vec3 X, vec3 Y )
{
    vec3 Kd = Diffuse * DiffuseScale;
    vec3 Ks = Specular * SpecularScale;

    vec3 H = normalize(L + V);
    float NdotL = clamp(dot(N, L), 0, 1);
    float NdotV = dot(N, V);
    float NdotH = dot(N, H);
    float LdotH = dot(L, H);

    float a_2 = Roughness * Roughness;
    float NdotL_2 = NdotL * NdotL;
    float NdotV_2 = NdotV * NdotV;
    float NdotH_2 = NdotH * NdotH;
    float OneMinusNdotL_2 = 1.0 - NdotL_2;
    float OneMinusNdotV_2 = 1.0 - NdotV_2;

    vec3 Fd = 1.0 - Ks;

    float gamma = clamp(dot(V - N * NdotV, L - N * NdotL), 0, 1);
    float A = 1.0 - 0.5 * (a_2 / (a_2 + 0.33));
    float B = 0.45 * (a_2 / (a_2 + 0.09));
    float C = sqrt(OneMinusNdotL_2 * OneMinusNdotV_2) / max(NdotL, NdotV);

    vec3 Rd = Kd * Fd * (A + B * gamma * C) * NdotL;

    float D = NdotH_2 * (a_2 - 1.0) + 1.0;

    vec3 Fs = Ks + Fd * exp(-6 * LdotH);

    float G1_1 = 1.0 + sqrt(1.0 + a_2 * (OneMinusNdotL_2 / NdotL_2));
    float G1_2 = 1.0 + sqrt(1.0 + a_2 * (OneMinusNdotV_2 / NdotV_2));
    float G = G1_1 * G1_2;

    vec3 Rs = (a_2 * Fs) / (D * D * G * NdotV);

    return Rd + Rs;
}

::end shader


#6 Promit   Moderators   -  Reputation: 7560

Like
2Likes
Like

Posted 22 February 2013 - 08:20 PM

If you are interested in a good overview of the semi-standard lighting models, take a look in the Lighting section of Programming Vertex, Geometry, and Pixel shaders.  Jack wrote a good, in-depth discussion of each of them individually, and the shader code should be at least a good starting point for your work (assuming HLSL of course...).

 

P.S.: My preference is: all of them!  Make your material system flexible enough to swap them in and out with data definitions!

Naturally -- this isn't an engineering thread. I'm just a bit tired of seeing the same four or so BRDFs over and over again and I was hoping for a wider view of the subject.

 

L.Spiro -- it looks interesting and I like a couple things about it. Something about the look of the brighter specular areas really goes down poorly with me though. I'm not sure it's the BRDF though; the highlights are very blown and I'm wondering if maybe I'm just not happy with the choice of tonemap in those shots. The roof of the orange car looks very odd to me, and the specular on the blue one is awfully wide. 


Edited by Promit, 22 February 2013 - 08:23 PM.


#7 L. Spiro   Crossbones+   -  Reputation: 14196

Like
0Likes
Like

Posted 22 February 2013 - 09:29 PM

I went over my shader again and found 2—count them—2 places where I used wrong dot products.

One should have been HdotL but was HdotN and the other should have been HdotN but was HdotL.

 

I also realized a way to remove a sqrt().

 

 

float Nu = fAnisotropy.x;
float Nv = fAnisotropy.y;
float Ps_num = sqrt( (Nu + 1) * (Nv + 1) );
 

Ps_num can be calculated ahead of time and sent to the shader.

 

I will post my results later but the crap specular you noticed is fixed.  I have been wondering about that for a long time too but every time I went over my shader I missed those little letters.

 

 

L. Spiro


It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#8 L. Spiro   Crossbones+   -  Reputation: 14196

Like
6Likes
Like

Posted 23 February 2013 - 02:27 AM

After fixing the above and also changing my formula for converting specular power to the anisotropy values, here are better results of Ashikhmin-Shirley.

 

Ash2.png

Ash3.png

Ash0.png

 

 

L. Spiro


It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#9 Hodgman   Moderators   -  Reputation: 31768

Like
5Likes
Like

Posted 23 February 2013 - 02:58 AM

Those new screens look great, L.S.!

I've taken to Cook-Torrance with the GGX distribution and Smith geometry factor (thanks CryZe) for specular, and the qualitative version of Oren-Nayar for diffuse.

Thumbs up for the BRDF explorer format so I can see exactly what it looks like biggrin.png

Also, what BRDF do you want to use that is currently near feasible?

I'm trying to nail down the BRDF's for my current project at the moment, and I'd like to come up with a single one to simplify deferred shading...

The features that I think I need so far are: Non-lambertian diffuse, IOR/F(0º)/spec-mask, anisotropic roughness, metal/non-metal, retro-reflectiveness and translucency.

So far, I've got multiple options for implementing these features, but I've not yet researched retro-reflective BRDF's yet, and just have my own hacks based on intuition. Can anyone recommend me any existing models that support retro-reflection?



#10 Jason Z   Crossbones+   -  Reputation: 5282

Like
1Likes
Like

Posted 23 February 2013 - 10:12 AM

Naturally -- this isn't an engineering thread. I'm just a bit tired of seeing the same four or so BRDFs over and over again and I was hoping for a wider view of the subject.

There are pictures too - just pretend those ugly equations aren't there :P



#11 Promit   Moderators   -  Reputation: 7560

Like
2Likes
Like

Posted 23 February 2013 - 10:18 AM

After fixing the above and also changing my formula for converting specular power to the anisotropy values, here are better results of Ashikhmin-Shirley.

 

attachicon.gifAsh2.png

attachicon.gifAsh3.png

attachicon.gifAsh0.png

 

 

L. Spiro

The new highlights are much better smile.png



#12 MJP   Moderators   -  Reputation: 11736

Like
2Likes
Like

Posted 23 February 2013 - 12:06 PM

If I had to pick one, it would be GGX. But for any non-trivial application you'll typically need more than one. At the very least you'll need dedicated skin and hair BRDF's to go with it, and you'll want anisotropy for a lot of materials as well.

Either way the BRDF itself isn't usually the tricky or expensive part for real-time graphics, it's...

A. Coming up with a good overall shading model and toolset that allows your artists to understand the parameters they're authoring and efficiently author many many materials using those parameters


B. Figuring out how to apply your BRDF to more than just point lights and directional lights

and

 

C. Making it not alias like crazy without ruining your BRDF



#13 Hodgman   Moderators   -  Reputation: 31768

Like
2Likes
Like

Posted 23 February 2013 - 11:31 PM

I've taken to Cook-Torrance with the GGX distribution and Smith geometry factor (thanks CryZe) for specular, and the qualitative version of Oren-Nayar for diffuse.

I was mucking about with this in the BRDF explorer, and the fresnel factor didn't seem to be behaving right; even at front-on angles (L==V) there would always be a highlight, even when Ks was 0. I replaced your exp(-6 * LdotH) with pow(1-LdotH, 5) and it seems more correct now.

To help me compare it with the other BRDF's that come with BRDF explorer, I also divided everything by PI, which I'm not sure is correct, but seemed to make it behave more like the other BRDF's, and I divided the final result by NdotL, so that I could let BRDF explorer multiply by NdotL itself.

http://pastebin.com/c36FtdX5



#14 Chris_F   Members   -  Reputation: 2459

Like
1Likes
Like

Posted 24 February 2013 - 02:04 AM


I've taken to Cook-Torrance with the GGX distribution and Smith geometry factor (thanks CryZe) for specular, and the qualitative version of Oren-Nayar for diffuse.

I was mucking about with this in the BRDF explorer, and the fresnel factor didn't seem to be behaving right; even at front-on angles (L==V) there would always be a highlight, even when Ks was 0. I replaced your exp(-6 * LdotH) with pow(1-LdotH, 5) and it seems more correct now.

To help me compare it with the other BRDF's that come with BRDF explorer, I also divided everything by PI, which I'm not sure is correct, but seemed to make it behave more like the other BRDF's, and I divided the final result by NdotL, so that I could let BRDF explorer multiply by NdotL itself.

http://pastebin.com/c36FtdX5

 

There's really not a lot of difference between the two fresnel approximations. I graphed the two side-by-side here:

 

fresnel.png

 

The one that uses exp() essentially kicks in slightly sooner and is more gradual. For materials with an IOR value of ~1.4 (average dialectics) this seems to be slightly closer to the full fresnel equation, and I'm guessing it's not any more expensive to evaluate on modern GPUs.

 

As for PI and NdotL, I went ahead and rewrote the unoptimized version of the shader:

 

 

analytic

::begin parameters
color Diffuse 1 0 0
color Specular 1 1 1
float DiffuseScale 0 1 0.5
float SpecularScale 0 0.999 .028
float Roughness 0.005 2 0.2
::end parameters

::begin shader

vec3 BRDF( vec3 L, vec3 V, vec3 N, vec3 X, vec3 Y )
{
    float PI = 3.14159265358979323846;
    vec3 Kd = Diffuse * DiffuseScale;
    vec3 Ks = Specular * SpecularScale;

    vec3 H = normalize(L + V);
    float NdotL = clamp(dot(N, L), 0, 1);
    float NdotV = dot(N, V);
    float NdotH = dot(N, H);
    float LdotH = dot(L, H);

    float a_2 = Roughness * Roughness;
    float NdotL_2 = NdotL * NdotL;
    float NdotV_2 = NdotV * NdotV;
    float NdotH_2 = NdotH * NdotH;
    float OneMinusNdotL_2 = 1.0 - NdotL_2;
    float OneMinusNdotV_2 = 1.0 - NdotV_2;

    vec3 Fd = 1.0 - Ks;

    float gamma = clamp(dot(V - N * NdotV, L - N * NdotL), 0, 1);
    float A = 1.0 - 0.5 * (a_2 / (a_2 + 0.33));
    float B = 0.45 * (a_2 / (a_2 + 0.09));
    float C = sqrt(OneMinusNdotL_2 * OneMinusNdotV_2) / max(NdotL, NdotV);

    vec3 Rd = Kd / PI * Fd * (A + B * gamma * C);

    float D = a_2 / (PI * pow(NdotH_2 * (a_2 - 1.0) + 1.0, 2.0));

    vec3 Fs = Ks + Fd * exp(-6 * LdotH);

    float G1_1 = 2.0 / (1.0 + sqrt(1.0 + a_2 * (OneMinusNdotL_2 / NdotL_2)));
    float G1_2 = 2.0 / (1.0 + sqrt(1.0 + a_2 * (OneMinusNdotV_2 / NdotV_2)));
    float G = G1_1 * G1_2;

    vec3 Rs = (D * Fs * G) / (4 * NdotL * NdotV);

    return (Rd + Rs) * NdotL; //remove NdotL and let BRDF Explorer handle that
}

::end shader

 

You can see there is a factor of PI located in the calculation of Rd. Kd over PI is essentially the Lambert BRDF. The factor of PI is necessary for energy conservation. A factor of PI also shows up in the calculating of D. This is part of the normalization of the GGX distribution. When calculating Rs you see the familiar Cook-Torrance equation. Finally, Rd and Rs are summed and then multiplied by NdotL. This NdotL is not a part of either the specular or diffuse BRDFs, but the lighting equation. The version I posted before is identical to this, only I have removes terms that cancel out in order to get rid of unnecessary shader instructions. I also removed PI from both diffuse and specular BRDFs, since it's not really necessary for video games. The only affect it has is that your lights appear to be PI times brighter.

 

At least that is my current understanding. I'm still very new to the concepts behind lighting.

 

Edit: So I suppose it would make sense to remove the final NdotL, since this shader represents only the BRDF and not the final pixel color. Presumably BRDF Explorer is automatically multiplying the result by NdotL.


Edited by Chris_F, 24 February 2013 - 02:10 AM.


#15 Chris_F   Members   -  Reputation: 2459

Like
2Likes
Like

Posted 24 February 2013 - 04:20 AM

If you want to compare fresnel approximations you can use this:

 

 

analytic

::begin parameters
color Specular 1 1 1
float SpecularScale 0 0.999 .028
bool Schlick 0
::end parameters

::begin shader

vec3 Fresnel(float CosTheta, vec3 Ks)
{
    vec3 n2 = (1.0 + sqrt(Ks)) / (1.0 - sqrt(Ks));
    vec3 SinTheta = sqrt(1 - CosTheta * CosTheta);

    vec3 SinThetaT = SinTheta / n2;
    vec3 CosThetaT = sqrt(1 - SinThetaT * SinThetaT);

    vec3 n2CosThetaT = n2 * CosThetaT;
    vec3 n2CosTheta = n2 * CosTheta;

    vec3 RsSqrt = (CosTheta - n2CosThetaT) / (CosTheta + n2CosThetaT);
    vec3 Rs = RsSqrt * RsSqrt;

    vec3 RpSqrt = (n2CosTheta - CosThetaT) / (n2CosTheta + CosThetaT);
    vec3 Rp = RpSqrt * RpSqrt;

    return (Rs + Rp) / 2;
}

vec3 BRDF( vec3 L, vec3 V, vec3 N, vec3 X, vec3 Y )
{
    vec3 Ks = Specular * SpecularScale;

    float NdotV = dot(N, V);

    vec3 Full = Fresnel(NdotV, Ks);

    vec3 Fs;

    if(Schlick)
        Fs = Ks + (1 - Ks) * pow(1.0 - NdotV, 5);
    else
        Fs = Ks + (1 - Ks) * exp(-6 * NdotV);

    return abs(Full - Fs);
}

::end shader

Edited by Chris_F, 24 February 2013 - 04:22 AM.


#16 CryZe   Members   -  Reputation: 768

Like
1Likes
Like

Posted 24 February 2013 - 12:14 PM

Edit: So I suppose it would make sense to remove the final NdotL, since this shader represents only the BRDF and not the final pixel color. Presumably BRDF Explorer is automatically multiplying the result by NdotL.

 

Yep, the BRDF needs both the PI and the division by NDotL, while the implementation in a standard shader doesn't need those.



#17 Promit   Moderators   -  Reputation: 7560

Like
1Likes
Like

Posted 24 February 2013 - 12:58 PM

What's the computation for the X and Y parameters that BRDF Explorer uses for aniso distributions? Are they tangent/bitangent vectors?



#18 L. Spiro   Crossbones+   -  Reputation: 14196

Like
1Likes
Like

Posted 24 February 2013 - 05:09 PM

Yep, the BRDF needs both the PI and the division by NDotL, while the implementation in a standard shader doesn't need those.

Shaders do need NdotL.  Division by PI should be precalculated and sent to the shader—IE the light values the shader receives should already have been divided by PI.
 
 

What's the computation for the X and Y parameters that BRDF Explorer uses for aniso distributions? Are they tangent/bitangent vectors?

Yes, but in screen space (in pixel shaders) they often resolve to the directions [1,0,0] and [0,1,0].  Remember, they depend on your eyes, not the orientation of the object.

 

 

L. Spiro


Edited by L. Spiro, 24 February 2013 - 05:19 PM.

It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#19 Promit   Moderators   -  Reputation: 7560

Like
0Likes
Like

Posted 24 February 2013 - 07:24 PM

Yes, but in screen space (in pixel shaders) they often resolve to the directions [1,0,0] and [0,1,0].  Remember, they depend on your eyes, not the orientation of the object.

What's the computation for the X and Y parameters that BRDF Explorer uses for aniso distributions? Are they tangent/bitangent vectors?

I don't quite understand what you mean. Are you saying that the X and Y parameters are down to artistic choice, or that they actually mathematically resolve to those vectors?



#20 Hodgman   Moderators   -  Reputation: 31768

Like
1Likes
Like

Posted 24 February 2013 - 07:32 PM

What's the computation for the X and Y parameters that BRDF Explorer uses for aniso distributions? Are they tangent/bitangent vectors?

Yeah, you can peek into their "shaderTemplates" files:

   vec3 normal = normalize( gl_TexCoord[0].xyz );
    vec3 tangent = normalize( cross( vec3(0,1,0), normal ) );
    vec3 bitangent = normalize( cross( normal, tangent ) );

These are then passed into your BRDF function as N, X and Y.

 

[edit]Oh man this new IPB text box is screwing up hardcore lately... It just deleted half my post that proceeded a code block, again...

 

Shaders do need NdotL

He was talking about dividing by NdotL.

BRDF explorer will multiply by NdotL outside of the BRDF, so if you've included NdotL inside your BRDF (as we usually do in games), then you need to divide by NdotL at the end to cancel it out.


Edited by Hodgman, 24 February 2013 - 07:36 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS