3
$\begingroup$

I will preface this post by stating that I am a bit of a beginner to shaders in general. From what I can see in the shader editor, you can have say...the output of a noise node plugged into a colorramp node. This colorramp node can have its output plugged into, say a principled BSDF

So in essence, some shaders HAVE to be evaluated before the others. But exactly how are their evaluations ordered? The way I think about it, Blender would have to take the very first node that has an input powered by another node, say a Noise texture. The noise texture would have to be evaluated first, where it is then passed on as an input to the node it was 'powering'

But how would Blender find this 'first node' in a super branched complex node tree? Does it head recursively through each shader to find their inputs, and to find the inputs of its inputs, until it reaches the 'first one' and evaluates that?

$\endgroup$
2

1 Answer 1

3
$\begingroup$

Blender works backwards from the material output node, creating an acyclic directed graph, a data structure that looks vaguely like a tree. The material output node is the root of the tree, and the shader nodes that feed it directly are mapped as the first level of graph nodes. Eventually, every material node will be accounted for and the last level will consist of leaf graph nodes.

Consider this material:

Material

This will generate a tree that looks crudely like:

Generated Tree

Where the top of the drawing is the Material Output node and the bottom is the Texture Coordinate node.

Blender then works from the bottom of the drawing, the leaf nodes, to the top, doing the computations in what amounts to random order for the nodes that are all on the same level. For instance, in this material, it calculates the Texture coordinate first, and then applies the mapping, but it doesn't matter to it what order it calculates the output of the image nodes. But it does have to do the top 4 image nodes and the normal map before it can do the Principled.

By the way, this is done on a pixel by pixel basis.

$\endgroup$
8
  • $\begingroup$ How would it work if I had a Node A with 2 inputs, Node B and Node C, where Node C is also an input to node B? What would the graph be like then? And is this traversal of lead nodes recursive in nature? $\endgroup$
    – Hash
    Nov 9, 2021 at 6:31
  • $\begingroup$ That happens in this example. 3 of the image textures feed directly to the Principled shader, but a 4th one feeds a normal map. Different versions of handled this differently, depending on what optimizations were applied, so it's possible that all the image textures are computed and then the normal map, or it's possible that the image texture that feeds the bump map is computed, then the bump map, and then other image textures. Yes, the tree is walked with a recursive walker. $\endgroup$ Nov 9, 2021 at 14:57
  • $\begingroup$ Sorry I didnt mean that. Suppose I had a principled BSDF, with a noise texture plugged into the color input. The noise texture is also plugged into a bump map which connects to the BSDF. In such a case where a node 'feeds' two nodes at differing levels at the same time, is it possible to determine which of these gets evaluated first? $\endgroup$
    – Hash
    Nov 9, 2021 at 16:33
  • $\begingroup$ Ah, I read your question backwards. I didn't cover that case in my example, but the answer is that the noise texture has to be calculated first, and then the bump texture, because both are needed by the BSDF. Then both are used simultaneously by the BSDF, since it uses all of its inputs at once. $\endgroup$ Nov 9, 2021 at 16:37
  • $\begingroup$ in the context of the principled bsdf, the noise and bump both plug into it at the same level. In the context of the bump map, the bump map exists in one level while the noise exists at a 'lower level' How does Blender account for this and RECOGNIZE this and assign Noise to the lowest level so that it can be evaluated first? $\endgroup$
    – Hash
    Nov 10, 2021 at 14:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.