Lazy and right-to-left evaluation in the node tree
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
1
down vote
favorite
As someone with a programming background, here's a fundamental thing about the Cycles node tree I've been thinking about. Let's say you have a node setup like this:
Here we have two computationally intensive shaders, called "Gigantic Shader A" and "Gigantic Shader B", and a Mix Shader is used to switch between them using some black-and-white mask.
In programming terms, this setup can be thought of as an if-else construct, with shader A and B being the two execution branches of the if-else construct.
Now, in basically every sane programming language, the two if-else branches are evaluated "lazily", meaning that either only the first branch or only the second branch is evaluated, depending on whether the if condition evaluates to true or false.
So here are my questions:
(1) Does Cycles have this lazy evaluation optimization as well? More specifically, is Cycles smart enough to figure out that if Fac=0 or Fac=1 in the above Mix Shader, it can completely ignore either shader B or shader A?
(2) If Cycles does have this optimization, then is it also true that the node tree is actually evaluated from right to left, starting at the Material Output node, and not from left to right, as one would naively assume? Because I can't think of any other way to implement lazy evaluation than going from right to left.
cycles nodes
add a comment |Â
up vote
1
down vote
favorite
As someone with a programming background, here's a fundamental thing about the Cycles node tree I've been thinking about. Let's say you have a node setup like this:
Here we have two computationally intensive shaders, called "Gigantic Shader A" and "Gigantic Shader B", and a Mix Shader is used to switch between them using some black-and-white mask.
In programming terms, this setup can be thought of as an if-else construct, with shader A and B being the two execution branches of the if-else construct.
Now, in basically every sane programming language, the two if-else branches are evaluated "lazily", meaning that either only the first branch or only the second branch is evaluated, depending on whether the if condition evaluates to true or false.
So here are my questions:
(1) Does Cycles have this lazy evaluation optimization as well? More specifically, is Cycles smart enough to figure out that if Fac=0 or Fac=1 in the above Mix Shader, it can completely ignore either shader B or shader A?
(2) If Cycles does have this optimization, then is it also true that the node tree is actually evaluated from right to left, starting at the Material Output node, and not from left to right, as one would naively assume? Because I can't think of any other way to implement lazy evaluation than going from right to left.
cycles nodes
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
As someone with a programming background, here's a fundamental thing about the Cycles node tree I've been thinking about. Let's say you have a node setup like this:
Here we have two computationally intensive shaders, called "Gigantic Shader A" and "Gigantic Shader B", and a Mix Shader is used to switch between them using some black-and-white mask.
In programming terms, this setup can be thought of as an if-else construct, with shader A and B being the two execution branches of the if-else construct.
Now, in basically every sane programming language, the two if-else branches are evaluated "lazily", meaning that either only the first branch or only the second branch is evaluated, depending on whether the if condition evaluates to true or false.
So here are my questions:
(1) Does Cycles have this lazy evaluation optimization as well? More specifically, is Cycles smart enough to figure out that if Fac=0 or Fac=1 in the above Mix Shader, it can completely ignore either shader B or shader A?
(2) If Cycles does have this optimization, then is it also true that the node tree is actually evaluated from right to left, starting at the Material Output node, and not from left to right, as one would naively assume? Because I can't think of any other way to implement lazy evaluation than going from right to left.
cycles nodes
As someone with a programming background, here's a fundamental thing about the Cycles node tree I've been thinking about. Let's say you have a node setup like this:
Here we have two computationally intensive shaders, called "Gigantic Shader A" and "Gigantic Shader B", and a Mix Shader is used to switch between them using some black-and-white mask.
In programming terms, this setup can be thought of as an if-else construct, with shader A and B being the two execution branches of the if-else construct.
Now, in basically every sane programming language, the two if-else branches are evaluated "lazily", meaning that either only the first branch or only the second branch is evaluated, depending on whether the if condition evaluates to true or false.
So here are my questions:
(1) Does Cycles have this lazy evaluation optimization as well? More specifically, is Cycles smart enough to figure out that if Fac=0 or Fac=1 in the above Mix Shader, it can completely ignore either shader B or shader A?
(2) If Cycles does have this optimization, then is it also true that the node tree is actually evaluated from right to left, starting at the Material Output node, and not from left to right, as one would naively assume? Because I can't think of any other way to implement lazy evaluation than going from right to left.
cycles nodes
cycles nodes
asked 4 hours ago
Nam-Quang Tran
836
836
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
4
down vote
When executing shaders, a special optimization is applied to Mix Shader nodes. If Factor evaluates to 0 or 1, any nodes that are only reachable via the unused branch of the mix are not evaluated.
Taken from this page:
https://docs.blender.org/manual/en/dev/render/cycles/optimizations/nodes.html
This page also describes how the node tree is evaluated.
Hmm... the page only mentions the Mix Shader under Run-Time Optimizations. So I guess there's no such optimization for the MixRGB node, which can also be used for if-else branching? :-/
– Nam-Quang Tran
3 hours ago
1
@Nam-QuangTran It works with MixRGB node the same. Pls read the link zzubnik provided.
– Jaroslav Jerryno Novotny
2 hours ago
@Jaroslav Jerryno Novotny: I've read the page, and the MixRGB node is indeed mentioned there, but only under "Node Optimizations". This means, in my interpretation, that the MixRGB node is only optimized during the compile-time tree simplication step, not during run-time, unlike the Mix Shader node. Either that, or the run-time section of the documentation is incomplete.
– Nam-Quang Tran
2 hours ago
@Nam-QuangTran The tree is evaluated and optimized before every frame that renders. The MixRGB node would change values in single frame time-frame only when motion-blur sub-sampling. I'd have to check the source code or test to see if there is a difference in sub-sampling, I doubt it. Maybe it's only the documentation wording like you say.
– Jaroslav Jerryno Novotny
1 hour ago
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
When executing shaders, a special optimization is applied to Mix Shader nodes. If Factor evaluates to 0 or 1, any nodes that are only reachable via the unused branch of the mix are not evaluated.
Taken from this page:
https://docs.blender.org/manual/en/dev/render/cycles/optimizations/nodes.html
This page also describes how the node tree is evaluated.
Hmm... the page only mentions the Mix Shader under Run-Time Optimizations. So I guess there's no such optimization for the MixRGB node, which can also be used for if-else branching? :-/
– Nam-Quang Tran
3 hours ago
1
@Nam-QuangTran It works with MixRGB node the same. Pls read the link zzubnik provided.
– Jaroslav Jerryno Novotny
2 hours ago
@Jaroslav Jerryno Novotny: I've read the page, and the MixRGB node is indeed mentioned there, but only under "Node Optimizations". This means, in my interpretation, that the MixRGB node is only optimized during the compile-time tree simplication step, not during run-time, unlike the Mix Shader node. Either that, or the run-time section of the documentation is incomplete.
– Nam-Quang Tran
2 hours ago
@Nam-QuangTran The tree is evaluated and optimized before every frame that renders. The MixRGB node would change values in single frame time-frame only when motion-blur sub-sampling. I'd have to check the source code or test to see if there is a difference in sub-sampling, I doubt it. Maybe it's only the documentation wording like you say.
– Jaroslav Jerryno Novotny
1 hour ago
add a comment |Â
up vote
4
down vote
When executing shaders, a special optimization is applied to Mix Shader nodes. If Factor evaluates to 0 or 1, any nodes that are only reachable via the unused branch of the mix are not evaluated.
Taken from this page:
https://docs.blender.org/manual/en/dev/render/cycles/optimizations/nodes.html
This page also describes how the node tree is evaluated.
Hmm... the page only mentions the Mix Shader under Run-Time Optimizations. So I guess there's no such optimization for the MixRGB node, which can also be used for if-else branching? :-/
– Nam-Quang Tran
3 hours ago
1
@Nam-QuangTran It works with MixRGB node the same. Pls read the link zzubnik provided.
– Jaroslav Jerryno Novotny
2 hours ago
@Jaroslav Jerryno Novotny: I've read the page, and the MixRGB node is indeed mentioned there, but only under "Node Optimizations". This means, in my interpretation, that the MixRGB node is only optimized during the compile-time tree simplication step, not during run-time, unlike the Mix Shader node. Either that, or the run-time section of the documentation is incomplete.
– Nam-Quang Tran
2 hours ago
@Nam-QuangTran The tree is evaluated and optimized before every frame that renders. The MixRGB node would change values in single frame time-frame only when motion-blur sub-sampling. I'd have to check the source code or test to see if there is a difference in sub-sampling, I doubt it. Maybe it's only the documentation wording like you say.
– Jaroslav Jerryno Novotny
1 hour ago
add a comment |Â
up vote
4
down vote
up vote
4
down vote
When executing shaders, a special optimization is applied to Mix Shader nodes. If Factor evaluates to 0 or 1, any nodes that are only reachable via the unused branch of the mix are not evaluated.
Taken from this page:
https://docs.blender.org/manual/en/dev/render/cycles/optimizations/nodes.html
This page also describes how the node tree is evaluated.
When executing shaders, a special optimization is applied to Mix Shader nodes. If Factor evaluates to 0 or 1, any nodes that are only reachable via the unused branch of the mix are not evaluated.
Taken from this page:
https://docs.blender.org/manual/en/dev/render/cycles/optimizations/nodes.html
This page also describes how the node tree is evaluated.
answered 4 hours ago


zzubnik
814
814
Hmm... the page only mentions the Mix Shader under Run-Time Optimizations. So I guess there's no such optimization for the MixRGB node, which can also be used for if-else branching? :-/
– Nam-Quang Tran
3 hours ago
1
@Nam-QuangTran It works with MixRGB node the same. Pls read the link zzubnik provided.
– Jaroslav Jerryno Novotny
2 hours ago
@Jaroslav Jerryno Novotny: I've read the page, and the MixRGB node is indeed mentioned there, but only under "Node Optimizations". This means, in my interpretation, that the MixRGB node is only optimized during the compile-time tree simplication step, not during run-time, unlike the Mix Shader node. Either that, or the run-time section of the documentation is incomplete.
– Nam-Quang Tran
2 hours ago
@Nam-QuangTran The tree is evaluated and optimized before every frame that renders. The MixRGB node would change values in single frame time-frame only when motion-blur sub-sampling. I'd have to check the source code or test to see if there is a difference in sub-sampling, I doubt it. Maybe it's only the documentation wording like you say.
– Jaroslav Jerryno Novotny
1 hour ago
add a comment |Â
Hmm... the page only mentions the Mix Shader under Run-Time Optimizations. So I guess there's no such optimization for the MixRGB node, which can also be used for if-else branching? :-/
– Nam-Quang Tran
3 hours ago
1
@Nam-QuangTran It works with MixRGB node the same. Pls read the link zzubnik provided.
– Jaroslav Jerryno Novotny
2 hours ago
@Jaroslav Jerryno Novotny: I've read the page, and the MixRGB node is indeed mentioned there, but only under "Node Optimizations". This means, in my interpretation, that the MixRGB node is only optimized during the compile-time tree simplication step, not during run-time, unlike the Mix Shader node. Either that, or the run-time section of the documentation is incomplete.
– Nam-Quang Tran
2 hours ago
@Nam-QuangTran The tree is evaluated and optimized before every frame that renders. The MixRGB node would change values in single frame time-frame only when motion-blur sub-sampling. I'd have to check the source code or test to see if there is a difference in sub-sampling, I doubt it. Maybe it's only the documentation wording like you say.
– Jaroslav Jerryno Novotny
1 hour ago
Hmm... the page only mentions the Mix Shader under Run-Time Optimizations. So I guess there's no such optimization for the MixRGB node, which can also be used for if-else branching? :-/
– Nam-Quang Tran
3 hours ago
Hmm... the page only mentions the Mix Shader under Run-Time Optimizations. So I guess there's no such optimization for the MixRGB node, which can also be used for if-else branching? :-/
– Nam-Quang Tran
3 hours ago
1
1
@Nam-QuangTran It works with MixRGB node the same. Pls read the link zzubnik provided.
– Jaroslav Jerryno Novotny
2 hours ago
@Nam-QuangTran It works with MixRGB node the same. Pls read the link zzubnik provided.
– Jaroslav Jerryno Novotny
2 hours ago
@Jaroslav Jerryno Novotny: I've read the page, and the MixRGB node is indeed mentioned there, but only under "Node Optimizations". This means, in my interpretation, that the MixRGB node is only optimized during the compile-time tree simplication step, not during run-time, unlike the Mix Shader node. Either that, or the run-time section of the documentation is incomplete.
– Nam-Quang Tran
2 hours ago
@Jaroslav Jerryno Novotny: I've read the page, and the MixRGB node is indeed mentioned there, but only under "Node Optimizations". This means, in my interpretation, that the MixRGB node is only optimized during the compile-time tree simplication step, not during run-time, unlike the Mix Shader node. Either that, or the run-time section of the documentation is incomplete.
– Nam-Quang Tran
2 hours ago
@Nam-QuangTran The tree is evaluated and optimized before every frame that renders. The MixRGB node would change values in single frame time-frame only when motion-blur sub-sampling. I'd have to check the source code or test to see if there is a difference in sub-sampling, I doubt it. Maybe it's only the documentation wording like you say.
– Jaroslav Jerryno Novotny
1 hour ago
@Nam-QuangTran The tree is evaluated and optimized before every frame that renders. The MixRGB node would change values in single frame time-frame only when motion-blur sub-sampling. I'd have to check the source code or test to see if there is a difference in sub-sampling, I doubt it. Maybe it's only the documentation wording like you say.
– Jaroslav Jerryno Novotny
1 hour ago
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fblender.stackexchange.com%2fquestions%2f119826%2flazy-and-right-to-left-evaluation-in-the-node-tree%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password