Created
July 19, 2022 00:25
-
-
Save EliteMasterEric/a7260887c2fbbd2ad5687ca0e059eb99 to your computer and use it in GitHub Desktop.
Fragment shader (built for Flixel) which replaces a specific color with another.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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