Skip to content

Instantly share code, notes, and snippets.

@EliteMasterEric
Created July 19, 2022 00:25
Show Gist options
  • Save EliteMasterEric/a7260887c2fbbd2ad5687ca0e059eb99 to your computer and use it in GitHub Desktop.
Save EliteMasterEric/a7260887c2fbbd2ad5687ca0e059eb99 to your computer and use it in GitHub Desktop.
Fragment shader (built for Flixel) which replaces a specific color with another.
// A vec4 represents the red, green, blue, alpha of a pixel with values from [0.0, 1.0].
const vec4 MAGENTA = vec4(1.0, 0.0, 1.0, 1.0);
const vec4 GREEN = vec4(0.0, 1.0, 0.0, 1.0);
vec4 doWhatever() {
// This function just returns green, but you could add more complex logic here.
return GREEN;
}
void main() {
// Get the color of the texture at the current pixel.
vec4 textureColor = flixel_texture2D(bitmap, openfl_TextureCoordv);
if (textureColor == MAGENTA) {
// If the texture at this pixel is opaque magenta, replace it.
textureColor = doWhatever();
}
// Return the result.
gl_FragColor = textureColor;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment