Filters
h2d.Sprite.
mySprite.filter = new Glow();
Build-in filters
h2d.filter package.
Creating custom screen shader filters
To create a shader that works as filter, you need a screen shader.
h3d.shader.ScreenShader, screen shaders only provides you input.position and input.uv, and you can alter the output.position or output.color.
@input var input : { position : Vec2, uv : Vec2,};var output : { position : Vec4, color : Vec4,};
Let’s create a simple shader that changes the red channel based on a parameter:
class MyFilterShader extends h3d.shader.ScreenShader { static var SRC = { @param var texture : Sampler2D; @param var red : Float; function fragment() { pixelColor = texture.get(input.uv); pixelColor.r = red; // change red channel } }}
Usage:
var myShader = new MyFilterShader();myShader.red = 1; // use 0-1 rangevar customFilter = new h2d.filter.Shader(myShader);mySprite.filter = customFilter;
Multiple filters on one sprite
h2d.filter.Group.
var group = new Group([filter1, filter2]);mySprite.filter = group;
