What exactly does Layer Weight do (scientifically/mathematically speaking)?

I’ve found a tutorial that tells me to use a Layer Weight node. I’ve analysed the code and I still don’t understand what the value it returns means, My understanding is that the output of the Fresnel node is the proportion of light that is reflected for a given Index of Refraction, but I can’t figure out what Layer Weight is doing.

Searching the net, I only find very vague information on what it does:

Blender Manual:
The Layer Weight node outputs a weight typically used for layering shaders with the Mix Shader node.

**https://blender.stackexchange.com/questions/21690/whats-the-benefit-of-using-layer-weight**:
The Layer Weight node allows for a smooth blend between the two

**http://manual.cycles4d.net/html/examples/using_layerweight.htm**:
With the layer weight input the colour returned is dependent on the viewing angle. Control of the mix shader is governed by the input value from the layer weight node.

As you can see, all very vague and doesn’t really tell me what the node actually does. I also tried looking at the Wikipedia article on Fresnel Equations, but I couldn’t find anything resembling the algorithm in the node_layer_weight.osl. It appears to derive the Fresnel value from I (which I assume is the angle of incidence), and while I can read the formula, I don’t understand what it achieves.

2 Likes

The best way to see what it does is to plug it into an emission shader. You’ll see a gradient from black at normals facing the camera, to white at 90* from the camera. You can use that 0-1 gradient as a factor to blend between 2 colors/textures/shaders.

You have two output options; fresnel, which is a physically based equation that has a sharp falloff, and facing, which is a basic, more linear(ish) blending.

1 Like

It is basically the dot product of view vector and surface normal. For straight on view to surface, it results in full value 1.0 and for glancing angle it is zero 0.0.

1 Like

You can use layer weight as a different approximation of fresnel for standard dielectrics (~IOR of 1.45):
Layer Weight -> Math(Power, 5) -> fLerp(facing reflection 0.04, edge reflection 1). fLerp can be a color mix node with those values plugged into the colors, or a node group where you do the interpolation using math.

The fresnel node will use the inverse of the IOR for the backface by default, producing Snells Window effect. Normally I will inverse the IOR for the backface again if I don’t want this effect (say for thin leaves or window panes without thickness). If for some reasons you don’t want to mess with things this way, you could use the layer weight^5 approach instead, as layer weight doesn’t get inverted for the backfacing normal.

Layer weight isn’t “scientific” wrt fresnel, but nobody would notice the difference if used right. However, normally it’s just used to get the “looking angle”, facing or glancing.

layer weight has 2 outputs
one for Fresnel but there is also a node for Fresnel alone
these 2 Fresnel don’t work the same way
one is linear and the other one more like a cos function or power function
also the Fresnel Value in one node is from 0 to 1 the other one can use higher value then 1 !

the other one for Facing has to do with face’s being in direct view or not
or using the face’s normal and the camera normal
see explanation by
kesonmis

happy cl

Thanks, all. That makes it make a bit more sense. I should note though, I’m not sure what dielectrics are and I’ve only just got a handle of Fresnel values.

1 Like

Dielectrics are materials that are poor electrical conductors, so generally speaking they are non-metals. In a physically based workflow, materials usually fall into one of two camps, dielectrics or metals, as they have very different visual properties.

1 Like

Ah, I see. I was able to find information on dielectrics being insulators, but I couldn’t see how that applied to rendering. One of the many things that need clarification in the Manual.

I’d try not to get too bogged down by all the technical jargon. A lot of it stems from scientific papers of a wider scope that have been adapted by developers and artists, and the terms just stick.

Unless you want to explore the deeper fascinations of the physical world, you really only need to know how light is absorbed and reflected differently for dialectics and metals (and thin film, which I guess you could say is a sub-catagory).

1 Like

This is a very good Siggraph talk about Physically Based Shading in Theory and Practice:

2 Likes