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 :(
Shaders Case Study - Pixel Art Palette Swapping -https://www.youtube.com/watch?v=u4Iz5AJa31Q
Prime31 - SpriteLightKit - https://github.com/prime31/SpriteLightKit
Stencil Buffer http://prime31.github.io/stencil-buffer-occlusion/
Answer by nantoaqui · Apr 25, 2020 at 11:06 PM
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.
Your answer
![](https://koobas.hobune.stream/wayback/20220612231905im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Low cost light with texture or shader, it's possible ? 0 Answers
Stencil Buffer not working with SpriteMask 0 Answers
apply lighting to custom shader made in shader graph? 0 Answers
Increase thickness of outlines 0 Answers
How create a material silhouette? 0 Answers