from unreal marketplace ddownload this learning project:
It is done by Epic and it is free. There are custom material functions that you can use for your material. Or you can just open it and see how that works.
I strongly suggest at least looking how to use their functions, and then migrating *just functions) to your project. It will save you time.