Download

What is the cost of simple maths in materials?

In more complex materials I often like to use equations (division, subtraction, rounding, multiplying, if statements, etc) on my input parameters to keep them in sync with eachother. Does this impact the cost of the material in any significant way?

That question cannot be answered in a definite way. Actual cost depends on a lot of factors, including hardware-specific ones. On a modern hardware such math is dirt cheap left alone, but if you stack up good deal of such nodes, you may run into performance issues.

There are some optimizations done to ease the burden of shaders under the hood, like caching. But I’m not sure how this works with dynamic parameters. I think these sort of optimizations just happen on the fly in the renderer. I worked on projects that had tons of different material instances, parameters, and math everywhere and they run just fine (75 FPS in 1080p on a GTX 960. You can probably get even better performance from a 1050).

In my experience basic math (addition, subtraction, multiplication, division, exponents, linear interpolation, sine waves) are incredibly cheap. Powers and compound sine waves are not as cheap, but still easily affordable. I also heard UE4 concatenated these math nodes down if they’re static. Modern renderers are very efficient: they won’t perform more work than they need to. It might look like you’re performing the same math over and over again per-pixel using the stats you get from the Material Editor, but that doesn’t tell you the whole story.