Skip to content

Instantly share code, notes, and snippets.

@AustinEast
Last active January 2, 2023 09:41
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save AustinEast/d3892fdf6a6079366fffde071f0c2bae to your computer and use it in GitHub Desktop.
Save AustinEast/d3892fdf6a6079366fffde071f0c2bae to your computer and use it in GitHub Desktop.
HaxeFlixel Pixel-Perfect Outline Shader
import flixel.system.FlxAssets.FlxShader;
import flixel.util.FlxColor;
class Outline extends FlxShader
{
@:glFragmentSource('
#pragma header
uniform vec2 size;
uniform vec4 color;
void main()
{
vec4 sample = flixel_texture2D(bitmap, openfl_TextureCoordv);
if (sample.a == 0.) {
float w = size.x / openfl_TextureSize.x;
float h = size.y / openfl_TextureSize.y;
if (flixel_texture2D(bitmap, vec2(openfl_TextureCoordv.x + w, openfl_TextureCoordv.y)).a != 0.
|| flixel_texture2D(bitmap, vec2(openfl_TextureCoordv.x - w, openfl_TextureCoordv.y)).a != 0.
|| flixel_texture2D(bitmap, vec2(openfl_TextureCoordv.x, openfl_TextureCoordv.y + h)).a != 0.
|| flixel_texture2D(bitmap, vec2(openfl_TextureCoordv.x, openfl_TextureCoordv.y - h)).a != 0.)
sample = color;
}
gl_FragColor = sample;
}')
public function new(color:FlxColor = 0xFFFFFFFF, width:Float = 1, height:Float = 1)
{
super();
this.color.value = [color.red, color.green, color.blue, color.alpha];
this.size.value = [width, height];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment