Download

Question about shader optimization with constant parameters

If a material requires a power node to be placed in front of a parameter, will the released material compress the parameter and power node into a single constant for the final game? The reason I ask is because converting just one of the parameters in my shader to a constant will remove 7 instructions for the finished game. It would be nice if we could still view the release stats for shaders relying heavily on constant parameters.

There are certain operations which have been implemented to ‘fold’ (aka operations on constants will be done on the CPU). These are

add/sub/mul/div/dot
sin/cos
sqrt
length
frac
append
min/max
clamp
floor
ceil
fmod
abs

Unfortunately pow has not been implemented so it cannot be folded. Lerp is also notably missing.

Wow, that’s odd. Can this issue be addressed in a new update? I have a dual algorithm that converts a grayscale image to two separate sets of grayscale images, and it performs a value adjustment based on the threshold, effectively gaining two different value sets from one texture. But to get this to work in gamma space, I need to add 4 extra instructions with a power node. I guess I could just multiply the threshold by itself to get a power of 2, but the result would be very inaccurate. After testing the results, I specifically need a power of 2.2123 for the system to work properly.

It would be nice if you could fold the lerp node, too! :slight_smile:

I second that! Lerp is one of the most useful nodes of the bunch!