It just makes things neater, it doesn’t optimize.
The function needs to be calculated separately for each material.