It was just to present the idea of how to approach it. Here’s a ready solution.
This is a demonstration so you know what is going on (I duplicated some nodes for readability)
Here’s the same functionality, only put into a MaterialFunction
Finally, put together