Are Material Expression optimizations possible?

anonymous_user_30faac86
Mon, 11 Apr 2016 20:32:22 +0000
Rendering

I’m new at analyzing Material Expressions. I understand the basics: it compiles into shaders (HLSL, GLSL, etc.) so the library of expressions is limited and not easily extendable. Since shader code also does not have branching (if-then, loops, etc.) I wanted to know if there were “under the hood” optimizations, at compile time or at runtime, much like you would find in a modern C++ compiler. I doubt it, but bear with me; here’s an example:

We have a grass interaction shader that checks the player’s position and the object’s (herb, grass) position, then tests" if they are close enough, then it “animates” (rotates) the grass. It has an On/Off “switch” (a scalar) that is set to 1 when the player moves and 0 when it does not.

My assumption is that even if the On/Off scalar’s value is 0, the shader will still compute the entire code for the “test” and just Multiply it by 0, in effect voiding (wasting) the whole test. When that is done on 50k+ instances, it should add up. I also assume it would cost a lot of GPU time to copy the player’s position (a vector) in GPU memory (so also a lot of GPU memory). Am I right in my assumptions?

Tips, pointers and suggestions are welcome.

1 post - 1 participant