Look, the material index in the editor starts from one, while in the shader it starts from zero. So, take the index you need from the editor and subtract one.
Thanks i love you. Great shader <3
I love you too... Thank you ))