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

@:value({ textureParam : "texture" })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 Sampler2D in the shader to which input texture will be assigned. Should be present in the shader.

Variables

nearest:Bool

When enabled, sampling on the input texture will use nearest neighbor algorithm.

pass:ScreenFx<T>

ScreenFX pass that will render the filter.

read onlyshader:T

The assigned shader instance. Can be accessed to modify shader uniforms.

Methods

Inherited Variables

Defined by Filter

@:value(true)autoBounds:Bool = true

When enabled, rendering bounds of the filter will be expanded by Filter.boundsExtend in all directions. Otherwise filter should provide custom bounds through Filter.getBounds call. Default : true.

@:value(0.)boundsExtend:Float = 0.

Rendering texture boundaries extent. Increases the rendering area by twice the Filter.boundsExtend value. Automatically applied to object bounds when autoBounds = true or Filter.getBounds is not overridden. Does not affect boundaries when autoBounds = true and boundsExtend is less than 0.

@:value(true)@:isVarenable:Bool = true

When filter is disabled, attached object will render as usual.

@:value(1)resolutionScale:Float = 1

Custom rendering resolution scaling of the filter.

Stacks with additional scaling from Filter.useResolutionScaling if enabled.

@:value(false)smooth:Bool = false

When enabled, filters on not Object which are not Drawable will use bilinear filtering when displayed and some filter will also use bilinear filtering on intermediate textures.

@:value(defaultUseScreenResolution)useScreenResolution:Bool = defaultUseScreenResolution

Use the screen resolution to upscale/downscale the filter rendering resolution.

Stacks with additional scaling from Filter.resolutionScale if enabled.

Inherited Methods

Defined by Filter

bind(s:Object):Void

Sent when filter is bound to an Object s. If Object was not yet allocated, method will be called when it's added to allocated Scene.

getBounds(s:Object, bounds:Bounds, scale:Point):Void

Method should populate bounds with rendering boundaries of the Filter for Object s. Initial bounds contents are undefined and it's recommended to either clear them or call s.getBounds(s, bounds). Only used when Filter.autoBounds is false.

By default uses given Object bounds and extends them with Filter.boundsExtend. Compared to autoBounds = true, negative boundsExtend are still applied, causing rendering area to shrink.

Parameters:

s

The Object instance to which the filter is applied.

bounds

The Bounds instance which should be populated by the filter boundaries.

scale

Contains the desired rendering resolution scaling which should be accounted when constructing the bounds. Can be edited to override provided scale values.

sync(ctx:RenderContext, s:Object):Void

Used to sync data for rendering.

unbind(s:Object):Void

Sent when filter was unbound from an Object s. Method won't be called if Object was not yet allocated.