Seeking help on a visibility lerp material function with multiple ranges

I’m trying to make a material function I’ll use in a lot of materials, and I’m having no luck with it- the math is beyond me, I’m afraid.
The material function I’m talking about will be used to lerp visibility on a particle. I want to be able to set up a curve with definable points throughout the distance from the camera.
Distance 0-A= 0
A-B= ramp from 0 to 1
B-C= 1
C-D= ramp from 1 to 0
Anything past distance D would stay at 0.

Basically, I’m trying to make a particle be invisible up close, but then start to fade in at, say 500 meters from the camera. From there until 1000 meters, it ramps up to full visibility. From 1000 meters to 2000 meters, it stays fully visible. After 2000 meters, it ramps down to invisible by 3000 meters, and stays invisible at any distance past that.

Anyone know how to construct a shader graph to do this? I’ve tried setting up a curve and atlas in the material, which works… but only for the ranges defined in the curve. I’m trying to make this into a material function with four scalar inputs so that I can use this in multiple materials.
Thanks!

Hope i have understood your question correct, and that you can link this to your particles material in the required channels, instead of the used color channels. This here switches between red and green, as placeholder for your visible and invisible (just switch them to black and white for that). From Zero to 500 it´s red, from 500 to 1000 it should become green, stays green to almost 2000, and from 2000 to 3000 it should become red again.

https://s18.directupload.net/images/190822/adch78xn.jpg

Full res image: https://s18.directupload.net/images/190822/adch78xn.jpg

Thanks! Yes, that’s exactly what I’m looking for. I came up with a solution, but I think yours is more elegant and cheaper. Thank you!