Making a Sprite shader in Unity with colour applied as overlay

Hello,
First post on here in years…..

I wanted to get the sprite colour in Unity to be applied using a Photoshop style overlay layer mode.

I found this page here that lists the calculations for all the Photoshop blend modes

http://www.deepskycolors.com/archive/2010/04/21/formulas-for-Photoshop-blending-modes.html

It has a cool space background as well which is a bonus.

Anyway. With that I created a new shader using the default sprite shader and used the following in the fragment shader.

fixed4 c = SampleSpriteTexture (IN.texcoord);// * IN.color;
c.r = (step(0.5f,c.r)*(1-(1-2*(c.r-0.5))*(1-IN.color.r))) + (step(c.r,0.5f)*(2*c.r)*IN.color.r);
c.g = (step(0.5f,c.g)*(1-(1-2*(c.g-0.5))*(1-IN.color.g))) + (step(c.g,0.5f)*(2*c.g)*IN.color.g);
c.b = (step(0.5f,c.b)*(1-(1-2*(c.b-0.5))*(1-IN.color.b))) + (step(c.b,0.5f)*(2*c.b)*IN.color.b);
c.rgb *= c.a;
return c;

With that you can create a grey scale image with highlights and shadows and tint it.

overlay coloured balls

 

About admin

Mike Robinson
This entry was posted in Unity and tagged , , . Bookmark the permalink.

Comments are closed.