I moved to a new URL! Check it out!

Dev Log: Some Shaders

Dev Log: Some Shaders
One of the things I miss about working in FlashPunk and working with a bunch of bitmaps and blitting to the screen is the super easy color overlay blending. FlashPunk had an Image blending mode called Tint and it could be used in place of Multiply and it is amazing for doing effects like fading an entire sprite to a specific color. The world of rendering quads and triangles I don't have such a luxury, but I do have shaders.

I've been working on the building islands animation, and here's a really fast version of it:

Image


At the end of it when the island pops out it's silhouetted with solid white. The white fades to cyan, and also fades back to the normal art at the same time. To get this effect I used a simple shader to handle a color overlay.
uniform sampler2D texture;
uniform vec4 overlayColor;

void main() {
vec4 pixcol = texture2D(texture, gl_TexCoord[0].xy);
vec4 outcol = mix(pixcol, overlayColor, overlayColor.a);
outcol.a = pixcol.a;
gl_FragColor = outcol;
}
I also use this code for enemies as well. When they get hit they turn red for a brief moment. I use code in the C# end to determine the color and intensity of the overlay and pass it along to the shader.
var overlay = Util.ScaleClamp(Combatant.Stun, 0, Combatant.StunMax, 0, 1);
var color = new Color(1, 0.2f, 0.1f, overlay);

ImageSpineAnim.Shader.SetParameter("overlayColor", color);
Soon I'll probably make some sort of system that allows me to easily add a bunch of color overlays to the shader and automatically figure out the final color for the shader to use. I'll probably also use the shader for a bunch of different effects down the road.

Comments

cepro
cepro
"At the end of it when the island pops out it's silhouetted with solid white. The white fades to cyan, and also fades back to the normal art at the same time." How do you express this inside the shader? I really like the "flash effect" in that gif but I can't manage to reproduce it using the shader you gave :)
Posted December 30th 2014 1:00 AM
Kyle
Kyle
The only part I drive with the shader is the color overlay. On the C# side I'm setting the RGBA values of the overlay color.

So when the island first spawns the overlay color is set to 1, 1, 1, 1, which is pure 100% alpha white. After that I interpolate the R value to 0 which fades to cyan, and then shortly after I fade the alpha to 0 which fades the overlay color away completely.
Posted January 2nd 2015 11:25 AM
cepro
cepro
Got it :) It works perfectly :D Thank you so much.
Posted January 2nd 2015 1:42 PM
new comment!

Post your comment!

Name
Email
Comment