6
$\begingroup$

Hello i am having trouble understanding how the 'mix shader' node actually works and more specifically why mix 2 identical nodes? For example: why is there a different result between using a glossy shader then mixing 2 glossy shaders with the same color and the same average roughness? what does mix shader actually do? average(with factor) the pixel color returned by each shader? i see people mixing 2 glossy shaders claiming it looks better since it gives a different roughness distribution, but i am curious to what is happening behind the scenes and what is actually the 100% PBR way.

mixed version on the right

related resources:

What's the point of mixing the same shader types?

https://www.youtube.com/watch?v=nsem2HjwZQU

https://www.blenderguru.com/articles/making-better-materials

$\endgroup$
1
  • $\begingroup$ I think that videos like the second one you linked are probably tripping you up. There was a lot of needless BSDF mixing and general haphazardness in the construction of that gold material. It could have been made much more simply with practically identical results. $\endgroup$
    – HISEROD
    Commented Jan 1, 2022 at 9:05

2 Answers 2

6
$\begingroup$

The easy part of the answer is that the 100% PBR way is to not use the mix shader because the mix shader does not preserve the physical properties of light.

The mix shader works, put crudely, by adding the output of the two BSDF nodes that are its inputs, in a ratio controlled by the value of Fac. Call the Shader that plugs into the top input $T$. Call the Shader that plugs into the bottom input $B$. Then the output of the mix shader is $Fac * B + (1 - Fac) * T$

The mix shader is used for a lot of purposes, but they all rely on using some input to control the Fac value. Many of these purposes were overcome by the Principled BSDF shader; but you still see examples. There's a common glass shader that uses a Fresnel or Layer Weight node to set FAC to mix between a glossy and a transparent shader, for example.

Even with the Principled BSDF shader available, some effects are still better produced by mixing two shaders to overcome limitations of the Cycles render engine.

Mixing two identical shaders is an artistic tradeoff that gives up actual photorealism for an effect that might better simulate the look that the artist wants. It's not a way to achieve PBR.

$\endgroup$
7
  • 1
    $\begingroup$ Thank you for your quick and helpful replay @Marty Fouts ! In the formula you described for the mix shader, you are mixing between the shaders A and B outputs, which are pixels? What specifically are you multiplying? Also do you know if the Principled BSDF 100% PBR? $\endgroup$ Commented Jan 1, 2022 at 16:02
  • 2
    $\begingroup$ This answer talks about what BSDF is. This paper describes the Principled Shader that Principled Shader is based on. The principled is not 100% PBR because Cycles is not. In particular it doesn't correctly model any frequency related light physics. But it is close enough for most materials, except for when the object is translucent (or transparent.) $\endgroup$ Commented Jan 1, 2022 at 16:16
  • 2
    $\begingroup$ B and T are colors, in RGB coordinates. They're not pixel colors, but rather the color that results of a light of a given color striking the material from the angle of the ray that the ray tracing algorithm has directed at the object. $\endgroup$ Commented Jan 1, 2022 at 16:18
  • 1
    $\begingroup$ Can you go into detail on "the mix shader does not preserve the physical properties of light" ? It seems like if you feed it energy-conserving shaders, and you use a fac between 0 and 1, you end up with energy conservation. Obviously, not all features of light are represented in a ray-tracer (like, there's nothing in the world that's just a surface, everything real is a volume) but I can't think of any particular thing that's right until you use a mix shader. $\endgroup$
    – Nathan
    Commented Jan 1, 2022 at 17:49
  • 2
    $\begingroup$ Yes, it's not the mix shader itself that doesn't conserve energy but the shaders that feed it. Emissions are not energy conserving for example, so the emission shader or the emission setting on the Principled shader can lead to non-conservation. That the emission itself doesn't conserve energy is valid physics, of course. $\endgroup$ Commented Jan 1, 2022 at 18:29
3
$\begingroup$

Mix shader is not complicated. It finds the color returned by each shader and interpolates between the two (in linear space) by the factor given. It's really just a mixRGB. Indeed, if we use it in Eevee, it's identical to shader to RGB -> mixRGB. (In Cycles, of course, this mixRGB has to happen for further ray bounces and has to preserve information like ray type and ray direction.)

Why is it different to mix shader two different roughnesses than to use a single, average roughness? I think the best parallel would be to imagine mixing two circles of different diameter:

enter image description here

When we take two white circles of different sizes and mix their colors, is it the same thing as taking one white circle of average size? Clearly not.

The same thing is true of roughnesses. Let's look at the same thing with a single lamp on spheres, but mixing roughnesses this time:

enter image description here

If we take a wide, dull highlight (1.0 roughness) and mix it with a tight, bright highlight (0.0 roughness) we're mixing two circles of different sizes. It is not the same thing as taking a medium highlight (0.5 roughness.) And the colors make it more clear what the difference is between mixing two different elements, and just taking the average of those elements.

$\endgroup$
2
  • 1
    $\begingroup$ 2 such great answers. I was unconsciously assuming Mix Shader mixed rays/samples, not just the returned colour, until corrected by you guys. $\endgroup$
    – Robin Betts
    Commented Jan 1, 2022 at 19:20
  • $\begingroup$ Thank you for your reply! understood the first paragraph about eevee (pretty cool) but i didnt completly understand your circles example. what are the white and black circles in the top? could you please screenshot your node trees so ill be sure what material corresponds to which sphere? additionally why doesnt the mix shader in cycles behave the same way as in eevee? what else can it interpolate except the pixel colors returned from each shader? if you have any links for further reading about this subject (shaders, render engines and anything related) i would be gratefull for them. $\endgroup$ Commented Jan 3, 2022 at 21:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .