6

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

Marty Fouts
  • 33,070
  • 10
  • 35
  • 79
  • 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. – HISEROD Jan 01 '22 at 09:05

2 Answers2

6

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.

Marty Fouts
  • 33,070
  • 10
  • 35
  • 79
  • 1
    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? – Daniel Liberty Jan 01 '22 at 16:02
  • 2
    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.) – Marty Fouts Jan 01 '22 at 16:16
  • 2
    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. – Marty Fouts Jan 01 '22 at 16:18
  • 1
    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. – Nathan Jan 01 '22 at 17:49
  • 2
    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. – Marty Fouts Jan 01 '22 at 18:29
  • Thank you everyone for your awesome answers! i sort of understand your answers but i clearly lack the technical knowledge to understand them completly yet. in the circle mixing example, i didnt understand what are the circles on the top, could you please screenshot your node trees? Also do you know where can i read upon all of this? the behind the scenes of render engines, shaders and if possible how it works in blender specifically. i bought the blender shader encyclopedia which is pretty awesome but i couldnt find anything that goes more in depth. how did you guys learn all of this? – Daniel Liberty Jan 03 '22 at 19:38
  • 1
    @DanielLiberty you need to ask Nathan in a comment on his answer about the circle mixing example. I don't know of a good source of all of this information all in one place. I've picked it up over the years from various materials tutorials, and an undergraduate class in computer graphics, back in the '70s. – Marty Fouts Jan 03 '22 at 19:54
3

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.

Nathan
  • 24,535
  • 1
  • 22
  • 68
  • 1
    2 such great answers. I was unconsciously assuming Mix Shader mixed rays/samples, not just the returned colour, until corrected by you guys. – Robin Betts Jan 01 '22 at 19:20
  • 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. – Daniel Liberty Jan 03 '22 at 21:21