Open Bartalon opened 3 years ago
Thanks for the feedback!
The plugin is indeed pretty simple & doesn't translate the actual HLSL into a shader graph. Doing so would require parsing the HLSL code itself, which would be way out of the scope of the plugin.
Out of curiosity, do you have examples where constant folding really improves performance? I've always been curious to see how important is really is.
No problem, I figured it might be out of scope. One day perhaps :)
I'm not a programmer, but constant folding seems to apply to code compiling in general. From what I understand, something like 2 * 10 * 12
would be constant-folded to become just 240 without any multiply operations. A Custom node in the Material Editor (according to Epic) would not benefit from this and instead would have each multiplication operation as part of the compiled shader code.
Gotcha :)
Actually, "classic" constant folding is already done by the shader compiler - if you have 2 * 10 * 12
the bytecode will just use 240.
The unreal constant folding is to apply that to "constant" parameters that aren't known at the shader compile time. Eg, if you have sin(MyParameter)
unreal can precompute the sin when you set MyParameter
, only doing the operation once instead of once per pixel per frame.
As far as I can tell this can be useful in some very specific scenarios, but in the vast majority of cases it shouldn't matter much if at all.
Oh cool, thanks for the extra info! This makes sense.
It would be ideal to have that separation with this plug-in if only just to maintain team-accessible graphs. But as you said, out of scope for the time being. :)
Ideally this plugin would be able to differentiate between content that needs to definitely be part of a Custom node and everything else in order to take advantage of constant folding.
Function code:
Generated graph:
Expected format: Intensity parameter and X output are not used within the while loop, and therefore could be broken out from the custom node: