The base class for simple filters that don't need specialized render passes and rely completely on the shaders.
Provides an easy interface to implement custom filters without going too deep into filter rendering process with render passes.
Compatible shaders should extend from h3d.shader.ScreenShader
and contain an input texture uniform, as well as assign pixelColor
in fragment shader.
Sample of a simple custom filter:
class InvertColorShader extends h3d.shader.ScreenShader {
static var SRC = {
@param var texture : Sampler2D;
function fragment() {
var pixel : Vec4 = texture.get(calculatedUV);
// Premultiply alpha to ensure correct transparency.
pixelColor = vec4((1. - pixel.rgb) * pixel.a, pixel.a);
// Some other filters directly assign `output.color` and fetch from `input.uv`.
// While it will work, it does not work well when multiple shaders in one filter are involved.
// In this case use `calculatedUV` and `pixelColor`.
}
}
}
// When initializing
// Second argument should point at Sampler2D that will take in the texture with contents filter should modify.
myObj.filter = new h2d.filter.Shader<InvertColorShader>(new InvertColorShader(), "texture");
Constructor
new(shader:T, textureParam:String = "texture")
Create new shader filter.
Parameters:
shader | The shader instance that will be used for rendering. |
---|---|
textureParam | The name of |