0.57.0: Local ShaderTweaks

We’re occasionally asked if it’s better to make shader assignments high up at parent locations in the scene hierarchy, or lower down at the leaf locations. We usually recommend higher up, because it’s more efficient – fewer locations require processing – and it gives you more freedom to work downstream. As soon as shaders are assigned to leaf locations, you’re pretty much forced to work at leaf locations for evermore, because anything you assign to parents downstream will be overridden by the inheritance rules. There were flaws in our “higher is better” advice though, which we’ve taken the time to address in Gaffer

Consider this classic ball of cows. You’ve followed the recommended practice and assigned your white surface shader to /sphere/cows/instances so that it is inherited by all the cows parented below in the scene hierarchy. You do a render to check and all is well.

Now you want to make one of your bovine buddies stand out from the herd. You create a ShaderTweaks node, assign it to the specific instance you’re interested in and set some parameters.

And…nothing. You get exactly the same image as before.

The problem is that ShaderTweaks operates only on the locations it is filtered to, and there is no shader to operate on at /sphere/seeds/instances/cow/6. You could filter to /sphere/seeds/instances, where the shader actually is, but then you’ll end up affecting all of the cows. It seems this advice about preferring assignments at a parent location was totally bogus.

In a fit of rage, you change the original shader assignment to the leaf locations with /sphere/seeds/instances/cow/* and carry on, muttering something about developers in ivory towers and the vast gulf between theory and practice. Unless of course, you’ve inherited the setup from another department, and you can’t change the assignment. Then you’re a bit stumped. You could probably rig something up with CopyAttributes, but this is all getting a bit out of hand for what should be an easy operation.

In Gaffer there is a simple solution.

Just turn on the new localise setting, and if the shader to be tweaked is inherited from a parent location, a local copy will automatically be made, and the tweaks will be applied to that. Problem solved.

Gaffer also brings a new LocaliseAttributes node which can be used to make local copies of any attribute, along with a bunch of other features, fixes and improvements. You can download it from https://github.com/GafferHQ/gaffer/releases/tag/

Leave a Reply