Page MenuHome

Cycles Nodes - Mix and Multiply Nodes Don't Skip Unnecessary Inputs
Closed, ArchivedPublic

Description

System Information
Win10, 8GB RAM, GTX 570

Blender Version
2.78c e92f235283

Short description of error
Related to 2c58e96685e8.
Cycles skips unnecessary mix (1 or 0 for Fac) and multiply node inputs of constant value (~1s render time: good):

However, when Fac or one of the multiply inputs is a variable, both inputs are calculated regardless if it should be skipped (~5s render time for identical result: bad):

In other words, despite the input value being 0 and the output being completely black, the render take the same time as it would with all the noise visible (~5s)

Noise stress-test (~5s):


Output (~5s):

Material was rendered on 10x10 plane at 50% 1080p, however it can drastically scale in performance decrease. Adding/fixing this optimization could drastically reduce render times depending on the complexity of a shader.

Event Timeline

Jason (LuftWaffle) updated the task description. (Show Details)
Lukas Stockner (lukasstockner97) changed the task status from Unknown Status to Archived.Apr 24 2017, 9:00 AM

While in this case it is obvious that the result is always zero, the shader optimizer in Cycles has no real way of knowing that - Shaders are compiled independently of the objects in which they're used, so unfortunately per-object attributes can't be used for constant folding.

To support something like that, it would be neccessary to compile different shaders for each object. Also, it would cause usability issues like recompiling your shaders whenever you move an object in the viewport.

So, while this specific instance could be optimized, it's unfortunately not really possible to do so in general...