As I understand you cant make palette swap? or you have other conceptual problems?
I have a fork from RedBlue Games “Palette Swap” that I personally use. Be aware, that workflow is far prom polished.
Here the links:
using UnityEngine;
[ExecuteInEditMode]
public class PaletteSwapMatrix : MonoBehaviour
{
public Color Color0;
public Color Color1;
public Color Color2;
public Color Color3;
Material _mat;
void OnEnable()
{
Shader shader = Shader.Find("Hidden/PaletteSwapMatrix");
if (_mat == null)
_mat = new Material(shader);
}
void OnDisable()
{
if (_mat != null)
DestroyImmediate(_mat);
}
void OnRenderImage(RenderTexture src, RenderTexture dst)
{
_mat.SetMatrix("_ColorMatrix", ColorMatrix);
Graphics.Blit(src, dst, _mat);
}
Matrix4x4 ColorMatrix
{
get
{
Matrix4x4 mat = new Matrix4x4();
mat.SetRow(0, ColorToVec(Color0));
mat.SetRow(1, ColorToVec(Color1));
mat.SetRow(2, ColorToVec(Color2));
mat.SetRow(3, ColorToVec(Color3));
return mat;
}
}
Vector4 ColorToVec(Color color)
{
return new Vector4(color.r, color.g, color.b, color.a);
}
}
Good news!!! I’ve spent some time studying shaders and managed to get the effect
Using SpriteLightKit and make the RenderTexture full black and white we can compare the pixel color:
half4 frag( fragmentInput i ) : COLOR
{
half4 main = tex2D( _MainTex, i.uv );
half4 lights = tex2D( _LightsTex, i.uv );
fixed x = tex2D(_MainTex, i.uv).r;
return lights.r > 0.9 ? _MultiplicativeFactor * main * lights : _ColorMatrix[x * 3];
}
I’m checking if the current pixel from LightsText (Black/White) is white. In that case i’m going to render the original image. Otherwise I’ll apply the color swapping on black areas.