Basic idea is that gray texture is a horizontal lookup value for palette texture. I usually give little offset because the value is right on the border between colors, maybe that’s the problem. The offset I use is -1/colorcount*0.5 to be in the middle of the palette color. Then add a vertical offset to choose the palette row on the palette texture.