View topic - Updates

Updates

Ask here your questions about development and about raytracing theory & implementation. Here you can post your patches for review.

Updates

Post Sun Mar 05, 2017 4:01 pm

Hello,

I just want to let you know I'm working now on... studying!

My current project (at last!) is to improve materials. I was looking forward to it but afraid at the same time, as this requires to understand much better how materials and integrators work in general and within YafaRay. So, studying all this now... frustrating and slow but once I get a better understanding I hope to be able to make interesting improvements.

I will keep you informed. Best regards!
User avatar
David Bluecame
 
Posts: 343
Joined: Mon Jan 21, 2013 12:42 pm
Location: Spain

Re: Updates

Post Mon Mar 06, 2017 4:41 pm

Keep on!
surena
 
Posts: 90
Joined: Sat Apr 26, 2014 6:37 am
Location: Spain

Re: Updates

Post Mon Mar 20, 2017 2:59 pm

Hi David,

finally got around to looking at the source code, and I think I know why glossy material produces a dark rim around it's specular highlight, and why it doesn't have IOR (when it should have).
maverick
 
Posts: 41
Joined: Fri Jan 13, 2017 10:43 am

Re: Updates

Post Mon Mar 20, 2017 5:36 pm

Hi, Maverick

Please, let me know, I'm very interested on that :-)
User avatar
David Bluecame
 
Posts: 343
Joined: Mon Jan 21, 2013 12:42 pm
Location: Spain

Re: Updates

Post Mon Mar 20, 2017 6:06 pm

It's great you are interested! I'm pretty anxious to discuss it with somebody, because this may very well turn out to be a mistake. So.

So, here's part of the code (one of the parts), responsible for computing specular component:

Code: Select all
glossy = Blinn_D(H*N, (exponentS ? exponentS->getScalar(stack) : exponent)) * SchlickFresnel(cos_wi_H, dat->mGlossy) / ASDivisor(cos_wi_H, woN, wiN);

col = glossy*(glossyS ? glossyS->getColor(stack) : gloss_color);
maverick
 
Posts: 41
Joined: Fri Jan 13, 2017 10:43 am

Re: Updates

Post Mon Mar 20, 2017 6:22 pm

Now let's take a look at the Blinn distribution and Fresnel functions (microfacet.h):

Code: Select all
inline float Blinn_D(float cos_h, float e)
{
   return (e + 1.f) * fPow(cos_h, e);
}


Code: Select all
inline float SchlickFresnel(float costheta, float R)
{
   float c1 = (1.f - costheta);
   float c2 = c1 * c1;
   return R + ( (1.f - R) * c1 * c2 * c2 );
}


Actually, I'm starting to have doubts about the first part of my theory. But anyway...

The Blinn-Phong model https://en.wikipedia.org/wiki/Blinn%E2%80%93Phong_shading_model uses a halfway-vector to eliminate situations when the angle reaches 90°, and so cos(theta)=0. But in this case, I think that's exactly what is happening; Blinn_D gets zeroed out (or returns some very small values), and "kills" the whole glossy component.
maverick
 
Posts: 41
Joined: Fri Jan 13, 2017 10:43 am

Re: Updates

Post Mon Mar 20, 2017 6:36 pm

I'll explain why I think halfway vector is compromised in detail later.

Now about Fresnel. Here it is:

Code: Select all
inline float SchlickFresnel(float costheta, float R)
{
   float c1 = (1.f - costheta);
   float c2 = c1 * c1;
   return R + ( (1.f - R) * c1 * c2 * c2 );
}


If you trace the code, you'll see that the R parameter, that gets passed to this function, is actually "reflection strengh" of the material editor. Meanwhile, in Schlick's approximation R is a function of the indice of refraction of the material (IOR):

Image

It's wrong to substitute the IOR with the reflection strength (but I don't think this is what produces the black rim), although numerically the results are similar at low values of reflectivity.
maverick
 
Posts: 41
Joined: Fri Jan 13, 2017 10:43 am

Re: Updates

Post Tue Mar 21, 2017 4:39 am

Hello,

Thank you for your input. However current glossy material is based on this model: https://www.google.ie/url?sa=t&source=web&rct=j&url=http://www.irisa.fr/prive/kadi/Lopez/ashikhmin00anisotropic.pdf&ved=0ahUKEwjdxPaC3-bSAhWILMAKHeHrAZcQFghMMAw&usg=AFQjCNFgx7DYw2pujGih4P2nbNwE2kcL-w&sig2=aXYEnwo2nCoYvtnOfYCoxg where R is the reflectance and not related to IOR

Another question would be whether the model itself is good enough for us or not. I certainly believe we need to use better glossy models.
User avatar
David Bluecame
 
Posts: 343
Joined: Mon Jan 21, 2013 12:42 pm
Location: Spain

Re: Updates

Post Tue Mar 21, 2017 5:10 am

Yeah, it's material’s reflectance for the normal incidence. Wiki seems to believe it depends on the indices of refraction of the two materials:

Image

But it's not most important point, i think the issue with the half-vector has far more important implications.

When I try open call hierachy on color_t eval and color_t sample functions, I get a "cannot resolve selected text..." message. How can I determine where these functions are called?
maverick
 
Posts: 41
Joined: Fri Jan 13, 2017 10:43 am

Re: Updates

Post Tue Mar 21, 2017 5:18 am

Absolutely, and the Blinn-Phong model, it seems, is rather primitive. A better model is needed.

On the other hand, it should stay for comparison purposes and as a tribute (imho).
maverick
 
Posts: 41
Joined: Fri Jan 13, 2017 10:43 am

Re: Updates

Post Tue Mar 21, 2017 5:25 am

To think of it, the "reflection strength" and IOR can actually be the same thing, or at least, closely related. Or can't they?

But why there's a separate IOR control option? Now I'm completely confused.
maverick
 
Posts: 41
Joined: Fri Jan 13, 2017 10:43 am

Re: Updates

Post Tue Mar 21, 2017 6:21 am

Yes, it's confusing, I agree. That's why I believe we should go for a better model altogether.

I also agree with you that, instead of dramatically modify/replace the current glossy model I'll probably add one or several new "improved" materials, so we can compare with the old ones and also for backwards compatibility with existing scenes.
User avatar
David Bluecame
 
Posts: 343
Joined: Mon Jan 21, 2013 12:42 pm
Location: Spain

Re: Updates

Post Tue Mar 21, 2017 1:09 pm

Let's put Fresnel aside. Can you help me out with something? I can't get my head around it. This is a part of the pathtracing integrator code:

Code: Select all
            vector3d_t pwo = wo;
            ray_t pRay;

            state.chromatic = was_chromatic;
            if(was_chromatic) state.wavelength = RI_S(offs);
            //this mat already is initialized, just sample (diffuse...non-specular?)
            float s1 = RI_vdC(offs);
            float s2 = scrHalton(2, offs);
            if(state.rayDivision > 1)
            {
               s1 = addMod1(s1, state.dc1);
               s2 = addMod1(s2, state.dc2);
            }
            // do proper sampling now...
            sample_t s(s1, s2, path_flags);
            scol = material->sample(state, sp, pwo, pRay.dir, s, W);


We create an object pRay of the ray_t class (2-nd line), and then we pass its direction to the sample function as an argument (last line). But what is the .dir field supposed to contain, if pRay has been assigned nothing? How can it be?
maverick
 
Posts: 41
Joined: Fri Jan 13, 2017 10:43 am


Re: Updates

Post Tue Mar 21, 2017 4:34 pm

Hi Odilkhan,

you see, there's so much information and so little time and concentration to digest it all... Thank you anyway!

I don't know if we can use the MERl brdfs, it's meant for academic purposes. But the whole point here is to make this by yourself.

However, I don't mind somebody explaining to me how the Yafaray code works.

Apparently, I jumped the gun when I said I knew what caused the black rim problem in the Glossy shader. It may very well be the Oren-Nayar component, or something else.
maverick
 
Posts: 41
Joined: Fri Jan 13, 2017 10:43 am

Next

Return to Developers' Corner



Who is online

Users browsing this forum: No registered users and 3 guests

cron