1
\$\begingroup\$

I want to implement an effect similar to what you see in this clip of Contra.

When the boss takes damage, he flashes wildly with different colors.

A similar effect can be seen in this clip from the Messenger (with the addition of an outline).

I don't care how they did it in Contra or the Messenger. I want to achieve a similar effect, preferably with a shader using GLSL.

Any ideas on how to go about it?

The effect seems to alternate the sprites between red and blue palettes, but I'm not sure if palette swapping is an effective way to achieve this, especially since I don't have my art assets in gray scale.

Maybe a hue shift shader is a viable alternative? Or maybe there's another way.

\$\endgroup\$
3
\$\begingroup\$

I think you could achieve this effect by using a rotating color palette. You can do this in GLSL by passing in a grayscale image and a 1D texture containing the color palette. You'd sample the grayscale image and use the resulting value to lookup into the 1D texture. You get the palette rotation by adding a value to the grayscale value. Something like this (not tested, probably has mistakes):

uniform sampler2D image;
uniform sampler1D colorPalette;
uniform float offset; // <- value between 0 and 1 that increases on each frame and wraps around
void main()
{
    float grayscalePixel = texture2D(gl_TexCoord[0], image);
    float paletteLookup = fract(grayscalePixel + offset);
    return texture1D(paletteLookup, colorPalette);
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.