Created
April 15, 2020 18:46
-
-
Save Geokureli/2c777c3ac4cf5e311b7eee2d7655a1af to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package fx; | |
class Dither extends flixel.system.FlxAssets.FlxShader | |
{ | |
@:glFragmentSource(' | |
#pragma header | |
const float scale = 2.0; | |
float checker(vec2 coord) | |
{ | |
return mod(floor(coord.x / scale) + floor(coord.y / scale), 2.0); | |
} | |
vec4 pixelColor(vec2 coord) | |
{ | |
return texture2D(bitmap, coord / openfl_TextureSize); | |
} | |
vec4 bigPixelCenterColor(vec2 coord) | |
{ | |
return pixelColor(coord + vec2(scale / 2.0, scale / 2.0)); | |
} | |
vec2 bigPixelTopLeft(vec2 coord) | |
{ | |
return vec2(coord.x - mod(coord.x, scale), coord.y - mod(coord.y, scale)); | |
} | |
void main() | |
{ | |
vec2 topLeft = bigPixelTopLeft(openfl_TextureCoordv * openfl_TextureSize); | |
gl_FragColor = bigPixelCenterColor(topLeft); | |
gl_FragColor.w = floor(gl_FragColor.w) * checker(topLeft); | |
} | |
') | |
public function new() { super(); } | |
} | |
// meanwhile in my state | |
package; | |
import fx.Dither; | |
import flixel.FlxCamera; | |
import flixel.FlxG; | |
import flixel.FlxSprite; | |
import openfl.filters.ShaderFilter; | |
class MenuState extends flixel.FlxState | |
{ | |
override public function create() | |
{ | |
FlxCamera.defaultCameras = [FlxG.camera]; | |
var shaderCam = new FlxCamera(); | |
shaderCam.setFilters([new ShaderFilter(new Dither())]); | |
shaderCam.bgColor = 0; | |
FlxG.cameras.add(shaderCam); | |
var sprite = new MySprite(); | |
sprite.camera = shaderCam; | |
add(sprite); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment