## Small SchlickBRDF::SampleF question

Discussion related to the implementation of new features & algorithms to the Core Engine.

Moderators: jromang, tomb, zcott, coordinators

### Small SchlickBRDF::SampleF question

Hi,

just a little brush-up

It seems that SchlickBRDF::SampleF uniformly samples either the coating or the diffuse base, without considering the fresnel effects of the coating, correct? So at grazing angles it may pick sub-optimal directions if it samples the diffuse base?
May contain traces of nuts.

Lord Crc

Posts: 4455
Joined: Sat Nov 17, 2007 2:10 pm

### Re: Small SchlickBRDF::SampleF question

Hi,

Exactly, that's one thing I plan to look at when reworking the glossy material. It has the potential of dramatically reducing the noise on glossy materials but last time I had a look at it, I seem to remember that the math wasn't that straightforward.

Jeanphi
jeanphi

Posts: 6577
Joined: Mon Jan 14, 2008 7:21 am

### Re: Small SchlickBRDF::SampleF question

Right, that's what I thought. And I'm not surprised the math isn't a walk in the park

Reason I asked was I was fooling around adding a "MicrofacetReflection" base, just for fun. I was thinking about comparing this simple modification with the more elaborate one from the layered brdf paper, which takes refraction of the coating layer into account. Just to see if it has a big impact or not.
Attachments
May contain traces of nuts.

Lord Crc

Posts: 4455
Joined: Sat Nov 17, 2007 2:10 pm

### Re: Small SchlickBRDF::SampleF question

While we're at it, pdfBack, that's the same as Pdf(wi, wo)?
May contain traces of nuts.

Lord Crc

Posts: 4455
Joined: Sat Nov 17, 2007 2:10 pm

### Re: Small SchlickBRDF::SampleF question

Now, this may (probably) be just silly, but my initial idea regarding the SampleF was that if wo is near the horizon, it's likely we're in a grazing angle situation and we want to sample the coating. Thus we can use wo to calculate the fresnel factor and adjust the sampling ratio based on this. Something like

Code: Select all
   const float u = fabsf(wo.z);   const float S = SchlickFresnel(u).Filter(sw);   const float w_diff = 0.5f * (1.f - S);   if (u3 < w_diff) {      // Cosine-sample the hemisphere, flipping the direction if necessary      *wi = CosineSampleHemisphere(u1, u2);      ... etc ...   } else {      u2 *= 4.f;      const float cos2theta = u1 / (roughness * (1 - u1) + u1);      const float costheta = sqrtf(cos2theta);      const float sintheta = sqrtf(1.f - cos2theta);      const float p = 1.f - fabsf(anisotropy);      ... etc ...   }...   const float specPdf = SchlickZ(H.z) * SchlickA(H) / (4.f * M_PI);   *pdf = w_diff * fabsf(wi->z) * INV_PI + (1.f - w_diff) * specPdf / fabsf(wo.z);...

Thus as one approaches grazing angles the probability for sampling the diffuse layer drops quickly, while at near normal angles, the probability is the old 50% (which seems to work well).

As you probably noticed I had to add u3, for testing I used the one from SingleBSDF (which is unused there), but if we go for this we'd have to add another random number to SampleF proper (this would be needed if we ever implement a proper layered material anyway).

Anyway, with similar changes to Pdf() I'm getting less noise here on my testing scene, and at high spp there's virtually no change so I believe it's not that far from behaving correct. However I'm really not sure about pdfBack, which may be more tricky than I hoped. Currently I recompute the fresnel factor using the sampled wi:
Code: Select all
   if (pdfBack) {      const float u_back = fabsf(wi->z);      const float S_back = SchlickFresnel(u_back).Filter(sw);      const float w_diff_back = 0.5f * (1.f - S);      *pdfBack = w_diff_back * fabsf(wo.z) * INV_PI + (1.f - w_diff_back) * specPdf / fabsf(wi->z);   }

Surely it can't be this simple?
May contain traces of nuts.

Lord Crc

Posts: 4455
Joined: Sat Nov 17, 2007 2:10 pm

### Re: Small SchlickBRDF::SampleF question

Hi,

Yes, that's more or less the deal, but this actually needs to be handled by a layered BSDF referencing 2 BxDF (the base and the coating) so that the BxDF doesn't need this 3rd parameter. That's what I'm trying to implement.

Jeanphi
jeanphi

Posts: 6577
Joined: Mon Jan 14, 2008 7:21 am

### Re: Small SchlickBRDF::SampleF question

May contain traces of nuts.

Lord Crc

Posts: 4455
Joined: Sat Nov 17, 2007 2:10 pm

### Re: Small SchlickBRDF::SampleF question

Hi,

If you want to have a look at it, go for it, I'm currently reviewing and fixing a bunch of Mantis issues, so I won't have time to work on this in the coming days.

Jeanphi
jeanphi

Posts: 6577
Joined: Mon Jan 14, 2008 7:21 am

### Re: Small SchlickBRDF::SampleF question

Well it would be fun to give it a go

Did you plan on making this a true multi-layered, or just a two-layered one for now?

In order to move this logic to the BSDF, we need to get the specular reflection factor for a given direction from the BxDF. Should I add a new method to BxDF which returns this, or did you plan on a much tighter integration with the Schlick BxDF? Or did you have some other good idea (taking a Fresnel object for each BxDF added, null in case of non-refractive, ie the base?).

Also for coating absorption to work we'll have to return this from the BxDFs, we could add a SigmaA or something to them?
May contain traces of nuts.

Lord Crc

Posts: 4455
Joined: Sat Nov 17, 2007 2:10 pm

### Re: Small SchlickBRDF::SampleF question

Hi,

My idea was that a generic 2 layer BSDF would be stackable to allow multilayers.
Regarding the specular reflection, you get to it either with the Rho member or by updating the Weight member which is meant for that (only used by glass currently with specular transmission/reflection). The hardest part here is that the specular reflection depends on the half angle which you don't know beforehand, I hadn't found any elegant heuristic to solve that part.
For the coating absorption, I planed to reference a named volume for the coating, this would give the IOR and the absorption in one go, plus allow scattering if we ever want to support it... It would be stored in the BSDF along with the coating depth so the BSDF would have all element to compute the absorption.
A new feature that I wanted to add in the process is a passthrough factor for the coating, ie the ability to see part of the base unaffected by the coating, this would probably help with skin or materials where the coating is not uniform, but that can wait.

Jeanphi
jeanphi

Posts: 6577
Joined: Mon Jan 14, 2008 7:21 am

Next