Horizontal fading material (Cycles)

I have created this material which fades to transparency from the bottom to the top.

This is the output which is ok:

However I would like to control the position where the fading happens (that is the upper handle in the colour ramp) to be controlled from the outside by the Z-position of an empty as that position is relevant for other settings in the scene. How can I achieve that?
Blend file is attached.


MaterialHorizFade.blend (506 KB)

This may not be 100% what you’re after, but you should be able to derive something from it. The main idea is to use an empty to control where a “linstep” fade happens. The cylinder is unwrapped and uses a coordinate direction to map it onto, change as appropriate:

Cool. That works. It is probably also a bit more efficient than using a colour ramp. Could you explain how all this math conversion works? For me this looks a bit like a big black box of magic.

It should work same as color ramp for floats, in linear interpolation mode, but the major benefit is the ability to expose the inputs. I have it in a utility group where I can select outputs linstep, smoothstep, and smootherstep. Linstep is the “first half” of the calculations involved in smoothstep.

When trying to apply this setup to the real material I run into some problems, where the borderline where it fades to transparancy is not as expected. Playing around with the different output slots of both separate XYZ nodes helped in finding a combination that works. I think this depends on the orientation of your unwraped UV.