So I'm trying to move up in the world when it comes to shaders. And I figured adding color tinting and transparency to my spritebatcher would be a good place to start.
I have added the ability to use a Color object in some of my methods. Where this object is made up of 4 float components for RGBA
And I have also added a separate AlphaValue for how transparent a sprite is even if its tinted by a color.
Now I'm wondering, can some one tell me if my idea is right?
That I should be multiplying the Alpha of my color tint against its own RGB before adding it to the over all texture color?
My fragment shader looks like this:
//Get the texture pixel data from the sampler
vec4 texColor = texture2D(texture, uvCoords);
//Make the image more transparent based on the alpha value
texColor *= alphaValue;
//Add the tint color
//Not sure part: multiple the tint color's RGB by its alpha then add it to the color of the texture
//And multiple it by the texture's alpha
texColor = (textColor + (tintColor.xyz * tintColor.w)) * textColor.a;
gl_FragColor = textColor;
When it comes to using methods that do not allow a Color object or tinting. EG: Draw(texture, xPos, yPos) vs Draw(texture, tintColor, xPos, yPos)
The color vertex data for the non tint color method is filled with 0s
VertexData[COLOR_R] = 0.0f;
VertexData[COLOR_G] = 0.0f;
VertexData[COLOR_B] = 0.0f;
VertexData[COLOR_A] = 0.0f;