As per the documentation “Constant folding is an optimization that UE4 employs under the hood to reduce shader instruction count when necessary. For example, an expression chain of Time >Sin >Mul by parameter > Add to something can and will be collapsed by UE4 into a single instruction, the final add. This is possible because all of the inputs of that expression (Time, parameter) are constant for the whole draw call, they do not change per-pixel. UE4 cannot collapse anything in a custom node, which can produce less efficient shaders than an equivalent version made out of existing nodes…”.
Will UE4 collapse a custom node whose all inputs are constant for the whole draw call? In other words, I would like to know if the instructions of a custom node will be executed for each pixel or only once if all of the inputs of this custom node are constant for the whole draw call. How can I check this?
Will UE4 collapse a custom node whose
all inputs are constant for the whole
draw call?
No. Inputs will be collapsed. Code, contained in custom node, won’t.
Is the number of instructions the only trait to check whether the constant folding has been applied?