# Your preferred or desired BRDF?

## Recommended Posts

Promit    13246

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? ;)

#### Share this post

##### Share on other sites
Matias Goldberg    9580
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.

#### Share this post

##### Share on other sites
Promit    13246

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

#### Share this post

##### Share on other sites
L. Spiro    25638

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

#### Share this post

##### Share on other sites
Jason Z    6436

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

#### Share this post

##### Share on other sites
Promit    13246

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

L. Spiro

The new highlights are much better

#### Share this post

##### Share on other sites
MJP    19786

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

#### Share this post

##### Share on other sites
Hodgman    51328

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

#### Share this post

##### Share on other sites
Chris_F    3030

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:

[attachment=13873: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.

[b]Edit:[/b] 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

#### Share this post

##### Share on other sites
Chris_F    3030

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

#### Share this post

##### Share on other sites
CryZe    773

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.

#### Share this post

##### Share on other sites
Promit    13246

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

#### Share this post

##### Share on other sites
L. Spiro    25638

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

#### Share this post

##### Share on other sites
Promit    13246

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?

#### Share this post

##### Share on other sites
Hodgman    51328

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.

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

#### Share this post

##### Share on other sites
MJP    19786

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.

I don't really agree with that as general-case advice...it only makes sense for BRDF's that have a 1/pi term in them which isn't always the case.

Edited by MJP

#### Share this post

##### Share on other sites
Hodgman    51328

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.

I took Chris_F's BRDF containing Cook-Torrence/Schlick/GGX/Smith and Oren-Nayar, and re-implemented it with hacked support for anisotropy (based roughly on Ashikhmin-Shirley) and retroreflectivity.

If both the roughness factors are equal (or if the isotropic bool is true), then the distribution should be the same as GGX, otherwise it behaves a bit like Ashikhmin-Shirley. Also, the distribution isn't properly normalized any more though when using anisotropic roughness.

The retro-reflectivity is a complete hack and won't be energy conserving. When the retro-reflectivity factor is set to 0.5, you get two specular lobes -- a regular reflected one, and one reflected back at the light source -- without any attempt to split the energy between them. At 0 you just get the regular specular lobe, and at 1 you only get the retro-reflected one.

BRDF Explorer file for anyone interested: http://pastebin.com/6ZpQGgpP

Thanks again for sending me on a weekend BRDF exploration quest, Chris and Promit  Edited by Hodgman

#### Share this post

##### Share on other sites
godmodder    828

If there were absolutely no limits I would like to evaluate spatially-varying and measured bidirectional texture functions. They show up a lot in my inverse rendering research and the results can look very realistic. Storing them in wavelet format makes them somewhat tractable and convenient to work with, but the system requirements add up rather quickly.

#### Share this post

##### Share on other sites
belfegor    2835

If you are interested in a good overview of the semi-standard lighting models, take a look in the Lighting section of Programming Vertex...

Sorry for intrusion on this thread. I have a question related to "cook_torrance" shader shown on that link.

float NdotH = saturate( dot( normal, half_vector ) );

...
if( ROUGHNESS_LOOK_UP == roughness_mode )
{
// texture coordinate is:
float2 tc = { NdotH, roughness_value };

// Remap the NdotH value to be 0.0-1.0
// instead of -1.0..+1.0
tc.x += 1.0f;
tc.x /= 2.0f;

// look up the coefficient from the texture:
roughness = texRoughness.Sample( sampRoughness, tc );
}


See author comments in code. Is this a bug? Saturate already clamps value to 0.0 - 1.0 range?

#### Share this post

##### Share on other sites
Chris_F    3030

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.

I took Chris_F's BRDF containing Cook-Torrence/Schlick/GGX/Smith and Oren-Nayar, and re-implemented it with hacked support for anisotropy (based roughly on Ashikhmin-Shirley) and retroreflectivity.

If both the roughness factors are equal (or if the isotropic bool is true), then the distribution should be the same as GGX, otherwise it behaves a bit like Ashikhmin-Shirley. Also, the distribution isn't properly normalized any more though when using anisotropic roughness.

The retro-reflectivity is a complete hack and won't be energy conserving. When the retro-reflectivity factor is set to 0.5, you get two specular lobes -- a regular reflected one, and one reflected back at the light source -- without any attempt to split the energy between them. At 0 you just get the regular specular lobe, and at 1 you only get the retro-reflected one.

BRDF Explorer file for anyone interested: http://pastebin.com/6ZpQGgpP

Thanks again for sending me on a weekend BRDF exploration quest, Chris and Promit

Actually, it's a lot easier to convert it to anisotropic than that.

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 RoughnessX 0.005 2 0.2
float RoughnessY 0.005 2 0.2
bool isotropic 1
::end parameters

::begin shader

float saturate(float x) { return clamp(x,0,1); }

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

float ax = RoughnessX;
float ay = (isotropic) ? RoughnessX : RoughnessY;

vec3 H = normalize(L + V);
float NdotL = saturate(dot(N, L));
float NdotV = dot(N, V);
float NdotH = dot(N, H);
float LdotH = dot(L, H);
float HdotX = dot(H, X);
float HdotY = dot(H, Y);

float ax_2 = ax * ax;
float ay_2 = ay * ay;
float a_2 = (ax_2 + ay_2) / 2;
float NdotL_2 = NdotL * NdotL;
float NdotV_2 = NdotV * NdotV;
float NdotH_2 = NdotH * NdotH;
float HdotX_2 = HdotX * HdotX;
float HdotY_2 = HdotY * HdotY;
float OneMinusNdotL_2 = 1.0 - NdotL_2;
float OneMinusNdotV_2 = 1.0 - NdotV_2;

vec3 Fd = 1.0 - Ks;

float gamma = saturate(dot(V - N * NdotV, L - N * NdotL));
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);
float OrenNayar = A + B * gamma * C;

vec3 Rd = (Kd / PI) * Fd * OrenNayar;

float D = 1.0 / (PI * ax * ay * pow(HdotX_2 / ax_2 + HdotY_2 / ay_2 + NdotH_2, 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 * NdotV * NdotL);

return Rd + Rs;
}

::end shader


I left out the retro-reflection hack because this BRDF actually already exhibits a lot of retro-reflection. If you go to Image Slice in BRDF Explorer and look at the bottom edge, that is the retro part. This is probably a lot more physically plausible as far as retro-reflections go.

Edited by Chris_F

## 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