content: Quad
Filter
A visual container that renders its children to a texture for post-processing effects.
Filter renders its children to a RenderTexture, allowing you to:
- Apply shader effects to groups of visuals
- Add blur, glow, or other post-processing effects
- Blend or transform rendered results as a single texture
- Create complex visual effects like reflections or distortions
- Improve performance by caching complex visuals
The filter process:
- Children are rendered to an internal RenderTexture
- The texture can be processed with shaders or effects
- The result is displayed as a single quad/mesh
Features:
- Automatic render texture management
- Optional custom mesh for advanced effects
- Toggle effects without changing hierarchy
- Explicit render control for performance
- Support for texture atlases via TextureTilePacker
// Create a blur filter
var blurFilter = new Filter();
blurFilter.size(400, 300);
blurFilter.shader = assets.shader('blur');
// Add content to be blurred
var text = new Text();
text.content = 'Blurred Text';
blurFilter.content.add(text);
// Toggle effect
blurFilter.enabled = false; // Disable blur
Instance Members
observedDirty: Bool
Default is false
, automatically set to true
when any of this instance's observable variables has changed.
textureId: String
Optional ID assigned to the internal render texture. Useful for debugging or identifying textures in tools.
mesh: Mesh
Optional mesh for advanced rendering effects.
By default, the filter renders as a simple quad. Providing a custom mesh allows for advanced effects like:
- Distortion effects with deformed vertices
- Multi-pass rendering with custom UVs
- Complex shader effects requiring custom attributes
The mesh will be added as a child and the render texture assigned to it.
destroyMeshOnRemove: Bool
If set to true
, when assigning null
or
a new mesh intance to the mesh
field will destroy
any existing mesh previously assigned.
The container for visuals to be rendered through this filter. Add your visuals as children of this content quad. Everything added here will be rendered to the filter's texture and processed according to the filter's settings.
hitVisual: Visual
If provided, visuals in content will react to hit tests
and touch events as if they were inside this hit visual.
By default, hitVisual
is the Filter
instance itself.
enabled: Bool
Toggle the filter effect on/off.
When false:
- No render texture is used
- Children render directly to screen
- No performance overhead from filtering
- Useful for toggling effects without changing hierarchy
Default is true (filter enabled).
The filtering mode for the render texture.
- LINEAR: Smooth filtering (default, good for most effects)
- NEAREST: No filtering (good for pixel art)
depthBuffer: Bool
Whether to use a depth buffer for the render texture. Enable when rendering 3D content or when precise depth testing is needed. Default is true.
stencil: Bool
Whether to use a stencil buffer for the render texture. Enable for masking effects or when using stencil-based rendering techniques. Default is true.
antialiasing: Int
Antialiasing level for the render texture. 0 = no antialiasing (default) 2, 4, 8, etc. = multisampling levels Higher values provide smoother edges but use more GPU resources.
autoRender: Bool
Whether the render texture updates automatically. Set to false for manual control over when rendering happens. Useful for static content that doesn't need continuous updates. Default is true.
explicitRender: Bool
Enable manual control over when the filter renders.
When true:
- Children don't render automatically
- Use render() method to trigger rendering
- Filter manages children's active state
- Useful for performance optimization
Default is false (automatic rendering).
textureTilePacker: TextureTilePacker
Optional texture tile packer for efficient texture atlas usage. When set, the filter will allocate tiles from the packer's texture atlas instead of creating dedicated render textures. Useful for optimizing many small filters.
textureTile: TextureTile
The allocated texture tile when using a TextureTilePacker. Read-only. Automatically managed when textureTilePacker is set.
renderTexture: RenderTexture
The render texture used for this filter. Read-only. Automatically created based on filter size and settings. Can be observed for changes using the @observe attribute.
density: Float
Texture density/resolution multiplier. -1 = use screen density (default) 1.0 = normal density 2.0 = double density (retina) Affects the internal resolution of the render texture.
neverEmpty: Bool
Force the filter to render even when content is empty.
By default, empty filters don't render (optimization). Set to true when you need the filter to process even without content, such as for time-based shader effects or render passes that don't depend on input visuals.
Adds a hidden 1x1 quad to ensure rendering occurs.
invalidateRenderTexture(): Void
render(?done: Function): Void
Manually trigger rendering when explicitRender is true.
This method:
- Activates content for rendering
- Waits for the render pass
- Updates the render texture
- Deactivates content
- Calls the done callback
Handles concurrent render calls gracefully by queuing callbacks.
Name | Type | Default | Description |
---|---|---|---|
done |
Function | (optional) | Optional callback invoked when rendering completes |
Test if a visual inside the filter's content is hit at the given coordinates.
This method handles the coordinate transformation from screen space through the filter's render texture to the visual's local space. Used internally for touch/mouse hit testing on filtered content.
Name | Type | Description |
---|---|---|
visual |
Visual | The visual to test |
x |
Float | Screen x coordinate |
y |
Float | Screen y coordinate |
Returns | Description |
---|---|
Bool | True if the visual is hit at the given coordinates |
computeContent(): Void
destroy(): Void
new(): Void
Private Members
meshDirty: Bool
neverEmptyQuad: Quad
unobservedRenderTexture: RenderTexture
explicitRenderState: Int
Internal flag used to keep track of current explicit render state
explicitRenderPendingResultCallbacks: Array<Function>
Used internally when concurrent renders are trigerred
Event when any observable value as changed on this instance.
Name | Type |
---|---|
instance |
Filter |
fromSerializedField |
Bool |
emitRenderTextureChange(current: RenderTexture, previous: RenderTexture): Void
Event when renderTexture field changes.
Name | Type |
---|---|
current |
RenderTexture |
previous |
RenderTexture |
Name | Type |
---|---|
density |
Float |
prevDensity |
Float |
updateRenderTextureAndContent(filterWidth: Int, filterHeight: Int, density: Float, depthBuffer: Bool, stencil: Bool, antialiasing: Int): Void
Name | Type |
---|---|
filterWidth |
Int |
filterHeight |
Int |
density |
Float |
depthBuffer |
Bool |
stencil |
Bool |
antialiasing |
Int |
Metadata
Name | Parameters |
---|---|
:build |
tracker.macros.ObservableMacro.build() |
:autoBuild |
tracker.macros.ObservableMacro.build() |
:build |
tracker.macros.EventsMacro.build() |
:autoBuild |
tracker.macros.EventsMacro.build() |
:build |
ceramic.macros.EntityMacro.buildForCompletion() |
:autoBuild |
ceramic.macros.EntityMacro.buildForCompletion() |