Light tint on 2D sprites

Hi,

I am making a 2D game and want my player and enemies to flash light red when hit and light blue when picking up weapons. All sprites use the Sprites-Default Material.

Using renderer.Color = new Color(1f,.5f,.5f,1f); (for example) I am only able to tint the sprites with dark colors. Is there a simple and efficient way to make a light color tint on sprites that is fast and works well on low-end mobile devices?

Thanks in advance!

I believe the tint on a render is multiplied by the current pixel color of the spirte. So if you set it to Red, all your white areas will turn red and the other pixels will become darker tinted red. You could create a sprite that has a lot of white in it around the borders and outlining your guy, swap this sprite in when you want to flash colors. Then set the renderer to red and white over a small time period. When its done flashing swap back in your normal sprite.

The other options is to modify the default Sprite Shader and have it only apply the tint to colors close to white and leave the rest alone. then it won’t darken nearly as much

You could modify the Sprites-Default shader to overbrighten the colors; something simple like changing “OUT.color = IN.color * _Color” to “OUT.color = IN.color * _Color * 2” might be enough for what you want. That way colors at 50% brightness have the same effect as colors at 100% brightness do with the unmodified Sprites-Default shader, so going up from 50% will be more brightified.

–Eric

Thanks Eric, this sounds like a really interesting solution. Are there any performance issues doing this?

Also, are there any tutorials or information about how to modify the Sprites-Default shader?

Thanks!

Download the shader and modify it with a text editor, like you do with a script. Make sure the shader name (in the code) is something different from Sprites/Default.

–Eric

Thanks, I got the custom shader working. Unfortunately all colors containing any zeros in either their R, G or B channel that part of the sprite doesn’t overbrighten at all, so I am not able to get a light tint on dark sprites.

I could update all bitmaps adding RGB(“#010101”) to all colors to avoid zeros, but seems like a cumbersome solution?

You could try this line in the vert function of the shader:

float4 modColor = (0.5,0.5,0.5,0.5);
OUT.color = IN.color * _Color *0.5f + modColor;

This would map the range of 0->1 onto the range of 0.5->1 (.25 would become .625 .5 would become .75)

Of course you’d only want to do this when your flashing. otherwise it would brighten your sprites all the time. You can easily change shaders when flashing or not though. Its very little performance as the shaders are all precompiled ahead of time.