What's the Math behind Fresnel node?

image

image

I’ve been researching on this node and have only found the theoretical explanations of it so far.

Basically, The Fresnel node outputs which percentage of light would be reflected off a glossy layer, with the rest being refracted through the layer. At grazing angles more light will be reflected than refracted as happens in reality.

My question is, what’s the Math that Blender used to calculate that 0-1 gradient? What’s the Mathematical formula for that?

Since Fresnel Effect contains both Reflection and Refraction, does Blender use Vector Reflection and Vector Refraction formulas to calculate Fresnel somehow?
Vector Reflection formula: r = i−2[(in^)n^] , such that, r is the reflected vector, i is incident vector and n^ is the normal vector.
I have Vector Refraction formula too but it’s so long to be written in here.

Thank you


Even though there’s an accepted answer.
If you have some input, please don’t hesitate to share some insights.

1 Like

The Fac from the node gives you the Fresnel Reflectance at its Normal angle and view.Iirc the Fresnel formula uses the dot product from normal angle and view. eG.From F0 to F90° angle if used on a sphere.Based of your IOR input ofc.

At this side you can see the most used Fresnel formulas

2 Likes

Thank you.
That’s scary, didn’t expect it to be this complicated.

Its quite simple here parts of the shader code

1 Like

Thank you.
I don’t know how to read code though, but I’ll try my best.

For just the dielectric Fresnel calc (which the node does) the code line 12-20 are used.(in the .h header file).

1 Like

Hi, I’m researching and have raised some questions, please help me if you don’t mind:

Question 1.
Just to make sure, the Fresnel node only considers the Dielectric (non-metal) Fresnel, doesn’t it?
So that I can skip over the Conductor (metal) Fresnel’s formula which includes Imaginary Number.

Question 2.
Blender’s algorithm for Fresnel Effect uses Dot Product, right?
And by definition, Dot Product function outputs:

  • 1 if the angle between 2 vectors were 0 degrees (straight on view to surface).
    In other words, the incident vector and surface’s normal is parallel.
  • 0 if the angle between 2 vectors were 90 degrees (glancing angle).
    In other words, the incident vector and surface’s normal is orthogonal.

BUT, here’s what I don’t understand, considering this image:
image
The straight on view on surface clearly doesn’t output value 1. This is the opposite of the definition of Dot Product.
Meaning, Blender somehow flipped the Dot Product’s 0-1 values?

Please tell me what you think.

You can see in the first .osl file that it uses

float cosi = dot(I, Normal);

The cosi is used to have a fraction based on normal angle at view angle,to calculate the Fresnel reflectance.
This means it is Normal Face geometry and view depending how much reflectance you get.

The cosi within the Fresnel formula gives you the Fresnel reflectance as fac output not the dot product.The dot product is used for calc the Fresnel.Without the cosi you dont have a angle in the Formula,if that makes sence.

2 Likes

I made a quick node rebuild of the code.Maybe this helps.

3 Likes

Thanks a lot for being thoughtful.
I’m trying to translate the codes to Mathematical language. After that, I’ll try to comprehend the Fresnel Equations Wikipedia page to understand the original intuition of the original Math.

The formula is quite simple.Here is a even more simple Schlick-Fresnel approximation.


Look how you can calc F0 without any angle.

3 Likes

1 - Dot(Geometry Normal, Geometry Incoming) = Layer Weight/Facing, which has nothing to do with Layer Weight/Fresnel or the Fresnel node. Not in a direct fashion anyway.

To preview data values like this, you may be better off switching to View Transform/Raw or Display Device/None to prevent any remapping.

Not sure what you mean with Vector Reflection and Vector Refraction. Fresnel is only supposed to be used to calculate how much reflection there is in slot #2 of Mix shader. Slot #1 of the Mix Shader can contain pretty much any fixed Shader Mix of absorption shaders (Refraction, Diffuse, SSS, Translucency, Sheen, pretty much anything surface shader without glossy).

Be aware that to produce the same result on the backside of thin geometry, 1/IOR has to be used for the IOR value. Otherwise you’ll get Snell’s window which is normally the desired effect.

1 Like

Thank you.

@pixelgrip @CarlG

May I ask:
image

  • What’s inputted into the Normal socket? Is that Normal referring to the Normal Vectors of the object?
  • Do all shaders treat the Normal input the same way, which is inputting different Normal Vectors of the object?

You can see most Nodes explaned at the Blender doc

https://docs.blender.org/manual/en/latest/render/shader_nodes/input/fresnel.html

Usually you plug in whatever normal modification you plug into building block shaders for a manual setup. Might want to not do it to make it less expensive.

Afaik, all shaders treat the Normal input the same way, but some shaders are more prone to shading artifacts if used in certain specific ways (which I sometimes do to fake nap direction in some fabrics).

1 Like