Palette swap based on light

Hello!

I’m trying to create this type of art style where dark areas gets its color swapped to a different one preserving only the edge/silhouette color.

In this example you can see the brick being lit has a greenish color and the unlit area has a dark tone:

I’ve tried to apply the concepts from these articles but couldn’t get it to work :frowning:

Shaders Case Study - Pixel Art Palette Swapping -Shaders Case Study - Pixel Art Palette Swapping - YouTube

Prime31 - SpriteLightKit - GitHub - prime31/SpriteLightKit: Blended lighting system for Unity that works with standard Sprites

Stencil Buffer Using the Stencil Buffer for Sprite Occlusion - prime31 blog - Game dev tips, tricks and random thoughts

Solution can be found here:

https://forum.unity.com/threads/palette-swap-based-on-light-position.871576/#post-5737003

You can edit SpriteLightKit-BlendImageEffect.shader to do the following:

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.