I’m hoping someone can clarify something for me. I noticed the base pass shader instruction count increases when I change a constant to a parameter (it’s a post process material, if that matters).
I always thought parameters were essentially free. Is that not correct?
Parameters are more expensive becouse it precalculate all variation you can make with changing this parameter. But this cost is only on compiling time so before the game is start, is like construction script in blueprint.
At the end better use parameters to make master materials. The time is take to compile shaders is only on loading time but on runtime of the game is changing nothing between a costant and a parameter. The unique difference was that you can use parameters via blueprints to make a caind of customizzation and costants not allow it.
Constants can be cheaper because they are static and optimizations are applied to them by the translator and the compiler. In the translators case it does a constant folding optimization to collapse operations down into equivalent and simpler ones, while the hlsl compiler is very good at optimizing static/fixed code.
Parameters are non-static and thus cannot be optimized away. They also have a rendering cost beyond the cost to execute the shader on the gpu since the parameter values are dynamically set on the game and render threads.
This however does not mean you should not use parameters, the benefit of parameters is edit-ability at the MIC level (and on the fly in-game), and increasing the sharing potential between MICs. The more that MICs share shader permutations the less memory and compilation time cost of your MICs.