Filters

h2d.Sprite.

  1. 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.

  1. @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:

  1. 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:

  1. 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.

  1. var group = new Group([filter1, filter2]);mySprite.filter = group;