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:
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.
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.
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.
I've been working on the building islands animation, and here's a really fast version of it:
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;
}
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);
Comments
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.
Post your comment!