Hello All,
I’m trying to create a shader which will change the colours on a sprite based on the palette that I pass in, for example;
But instead, what I am getting is this
This is my first time working on a shader, if anyone could point me in the right direction, I would be extremely grateful
Thanks
Shader "Custom/bitty_shader"
{
Properties
{
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
_DefaultPaletteTex ("Default Palette (RGB)", 2D) = "white"
_CustomPaletteTex ("Custom Palette (RGB)", 2D) = "white"
}
SubShader
{
Lighting Off
LOD 200
CGPROGRAM
#pragma surface surf Lambert
fixed4 _Color;
sampler2D _MainTex;
sampler2D _DefaultPaletteTex;
sampler2D _CustomPaletteTex;
float4 _DefaultPaletteTex_TexelSize;
float4 _CustomPaletteTex_TexelSize;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
o.Alpha = 0;
for(int _DefaultPalette_x = 0; _DefaultPalette_x < _DefaultPaletteTex_TexelSize.z; _DefaultPalette_x++)
{
for(int _DefaultPalette_y = 0; _DefaultPalette_y < _DefaultPaletteTex_TexelSize.w; _DefaultPalette_y++)
{
fixed4 main = tex2D(_MainTex, IN.uv_MainTex);
fixed4 palette = tex2D(_DefaultPaletteTex, float2(_DefaultPalette_x, _DefaultPalette_y));
if(main.r == palette.r && main.g == palette.g && main.b == palette.b)
{
fixed4 c = tex2D(_CustomPaletteTex, float2(_DefaultPalette_x, _DefaultPalette_y));
o.Albedo = c.rgb;
o.Alpha = 255;
}
}
}
}
ENDCG
}
FallBack "Diffuse"
}