Hey!
I’ve been wondering how I could create a paletting shader, there are plenty of them on the internet but I couldn’t seem to find one that would account for black/unused pixels on the palette.
This is how my palette looks like:
And this is how I’m creating the texture before assigning it:
var paletteTexture = new Texture2D(256, 1, TextureFormat.RGBA32, false);
paletteTexture.filterMode = FilterMode.Point;
paletteTexture.wrapMode = TextureWrapMode.Clamp;
paletteTexture.LoadRawTextureData(currentPalette);
paletteTexture.Apply();
This is how the graph looks like and the result it yields is below

I’ve found another community project using a shader to achieve the same but they’re using OpenGL, so I copied the fragment piece and converted the function to HLSL by renaming the variables (vec4 → float4, vec2 → float2, texture2D → tex2D, mix → lerp, fract → frac).
And the inputs/output being what I’ve shown in the graph above
float2 TextInterval = 1.0 / uTextSize;
float tlPal = tex2D(mainTexture, uv).x;
float trPal = tex2D(mainTexture, uv + float2(TextInterval.x, 0.0)).x;
float blPal = tex2D(mainTexture, uv + float2(0.0, TextInterval.y)).x;
float brPal = tex2D(mainTexture, uv + TextInterval).x;
float4 transparent = float4(0.5, 0.5, 0.5, 0.0);
float4 tl = tlPal == 0.0 ? transparent : float4(tex2D(palette, float2(tlPal, 1.0)).rgb, 1.0);
float4 tr = trPal == 0.0 ? transparent : float4(tex2D(palette, float2(trPal, 1.0)).rgb, 1.0);
float4 bl = blPal == 0.0 ? transparent : float4(tex2D(palette, float2(blPal, 1.0)).rgb, 1.0);
float4 br = brPal == 0.0 ? transparent : float4(tex2D(palette, float2(brPal, 1.0)).rgb, 1.0);
float2 f = frac(uv.xy * uTextSize);
float4 tA = lerp(tl, tr, f.x);
float4 tB = lerp(bl, br, f.y);
RGBA = lerp(tA, tB, f.y);
Would you guys help me fix this problem?