sprite background colour

Can a image sprite be given a background colour as well. So it will be represented by a png and the image sprite has a background colour. There is a computational way of doing everything. I am thinking of something simple, without to much coding thanks in advance.

1 Comment

You can add a simple shader to the sprite:

vec4 color = texture2D(uDiffuseSampler, uvAlphaTime.xy);
gl_FragColor.xyz = mix(backgroundColor, color.xyz, color.w);
gl_FragColor.w = uvAlphaTime.z;

In this case I'm using a uniform called backgroundColor so you should add that to your sprite as well, like this:

Then change the value of backgroundColor to suit your needs.

Post a reply
Add Attachment
Submit Reply
Login to Reply