Loading...
Loading...
Use this skill when applying visual filters or post-processing effects in Phaser 4. Covers bloom, blur, glow, color matrix, barrel distortion, displacement, custom shaders, and the filter pipeline. Triggers on: filter, post-processing, shader, bloom, blur, glow, color effects.
npx skill4agent add phaserjs/phaser filters-and-postfx// In your Scene's create() method:
const sprite = this.add.sprite(400, 300, 'player');
// Step 1: Enable the filter system on the game object (WebGL only)
sprite.enableFilters();
// Step 2: Add filters via .filters.internal or .filters.external
sprite.filters.internal.addGlow(0xff00ff, 4, 0, 1);// Cameras have filters enabled by default - no enableFilters() needed
const camera = this.cameras.main;
camera.filters.internal.addBlur(0, 2, 2, 1);FilterListfilters.internalfilters.externalFilterListPhaser.GameObjects.Components.FilterListadd(filter, index)remove(filter, forceDestroy)clear()getActive()active === truelistaddBlur()addGlow()addMask()Phaser.Filters.Controller| Property | Type | Description |
|---|---|---|
| boolean | Toggle the filter on/off without removing it |
| Camera | The camera that owns this filter |
| string | The render node ID for the shader |
| Rectangle | Override automatic padding calculation |
| boolean | If true, the filter survives when its FilterList is destroyed (for reuse) |
setActive(bool)setPaddingOverride(left, top, right, bottom)getPadding()destroy()enableFilters()const sprite = this.add.sprite(400, 300, 'hero');
sprite.enableFilters();
// Now sprite.filters is available
sprite.filters.internal.addGlow();
sprite.filters.external.addVignette();enableFilters()filterCamerathis| Property | Default | Description |
|---|---|---|
| null -> Camera | The internal camera used for filter rendering |
| null -> {internal, external} | Access to the FilterList pair |
| true | Master toggle for all filter rendering |
| true | Auto-adjust camera to follow the object |
| false | Focus on the rendering context instead of the object bounds |
| false | Always draw to a framebuffer even with no active filters |
| null -> Vector2 | Maximum texture size for filter framebuffers |
willRenderFilters()const sprite = this.add.sprite(400, 300, 'enemy');
sprite.enableFilters();
// Add a glow
const glow = sprite.filters.internal.addGlow(0x00ff00, 4);
// Modify at runtime
glow.outerStrength = 8;
glow.color = 0xff0000;
// Temporarily disable
glow.setActive(false);
// Remove and destroy
sprite.filters.internal.remove(glow);const camera = this.cameras.main;
// Internal: effect in camera-local space
const blur = camera.filters.internal.addBlur(0, 2, 2, 1);
// External: effect in screen space
const vignette = camera.filters.external.addVignette(0.5, 0.5, 0.5, 0.5);
// Color grading via ColorMatrix
const cm = camera.filters.internal.addColorMatrix();
cm.colorMatrix.sepia();const cam = this.cameras.main;
// First: apply color grading
const cm = cam.filters.internal.addColorMatrix();
cm.colorMatrix.brightness(0.2);
// Second: apply blur to the color-graded result
cam.filters.internal.addBlur(1, 2, 2, 1);
// Third: add a vignette on top
cam.filters.external.addVignette(0.5, 0.5, 0.5, 0.8);// Mask with a static texture
sprite.enableFilters();
sprite.filters.internal.addMask('maskTexture');
// Mask with a game object (renders to DynamicTexture automatically)
const maskShape = this.add.circle(0, 0, 100, 0xffffff);
sprite.enableFilters();
const mask = sprite.filters.internal.addMask(maskShape);
// Invert the mask
mask.invert = true;
// Control auto-updating for game object masks
mask.autoUpdate = true; // default: re-renders each frame
mask.needsUpdate = true; // force a one-time update
// Use a specific camera for viewing the mask object
sprite.filters.external.addMask(maskShape, false, this.cameras.main);viewCameraconst camera = this.cameras.main;
const wipe = camera.filters.external.addWipe(0.1, 0, 0);
// Animate via tween
this.tweens.add({
targets: wipe,
progress: 1,
duration: 2000,
ease: 'Linear'
});
// Direction helpers
wipe.setLeftToRight();
wipe.setTopToBottom();
wipe.setRevealEffect(); // reveal mode
wipe.setWipeEffect(); // wipe mode
// Wipe to another texture (for scene transitions)
wipe.setTexture('nextSceneCapture');const camera = this.cameras.main;
const pf = camera.filters.internal.addParallelFilters();
// Top path: threshold bright areas, then blur them
pf.top.addThreshold(0.5, 1);
pf.top.addBlur();
// Configure the blend (how top combines onto bottom)
pf.blend.blendMode = Phaser.BlendModes.ADD;
pf.blend.amount = 0.5;
// Bottom path: left empty = uses original inputCaptureFrame// Requires composite mode on the camera
this.cameras.main.setForceComposite(true);
// Objects rendered before CaptureFrame are captured
const bg = this.add.image(400, 300, 'background');
// Create the capture point
const capture = this.add.captureFrame('myCapture');
// Display the captured texture with filters applied
const display = this.add.image(400, 300, 'myCapture');
display.enableFilters();
display.filters.internal.addBlur(0, 4, 4, 2);| Filter | Add Method | Description |
|---|---|---|
| Barrel | | Pinch/expand distortion. |
| Blend | | Blend another texture using a blend mode. Supports modes not available in standard WebGL. |
| Blocky | | Pixelation that preserves original colors (no blending). Best without anti-aliasing. |
| Blur | | Gaussian blur. Quality: 0=low, 1=medium, 2=high. |
| Bokeh | | Depth-of-field bokeh blur effect. |
| ColorMatrix | | Color manipulation via matrix. Access |
| CombineColorMatrix | | Combine channels from two textures via color matrices. Useful for alpha transfer. |
| Displacement | | Pixel displacement using a displacement map texture. Values are very small floats (e.g. 0.005). |
| Glow | | Luminous halo around edges. Supports inner/outer glow and knockout mode. |
| GradientMap | | Recolor image using a ColorRamp based on brightness. |
| ImageLight | | Image-based lighting using a panorama environment map and normal map. |
| Key | | Chroma key: remove or isolate a specific color. Config: |
| Mask | | Alpha masking via texture or game object. |
| NormalTools | | Manipulate normal maps: rotate, adjust facing power, output grayscale facing data. |
| PanoramaBlur | | Spherically-correct blur for panorama images. For use with ImageLight. Very slow. |
| ParallelFilters | | Split input into two filter paths, blend results. Use for custom bloom. |
| Pixelate | | Mosaic/pixelation effect. Pixel size = 2 + amount. Blends colors (unlike Blocky). |
| Quantize | | Reduce color palette. Supports RGBA/HSVA modes, gamma, offset, dithering. |
| Sampler | | Extract pixel data from the render. Does not alter the image. Expensive. |
| Shadow | | Drop shadow with offset, decay, and color. |
| Threshold | | Binary threshold per channel. Edges can be arrays for per-channel control. |
| TiltShift | | Miniature/tilt-shift effect (uses Bokeh internally). |
| Vignette | | Edge darkening/coloring. Supports NORMAL, ADD, MULTIPLY, SCREEN blend modes. |
| Wipe | | Wipe/reveal transition. Animate |
// Game objects: must enable first
gameObject.enableFilters();
gameObject.filters.internal.addBlur();
gameObject.filters.external.addGlow();
// Cameras: filters available immediately
camera.filters.internal.addBlur();
camera.filters.external.addGlow();const list = camera.filters.internal;
list.addBlur(); // Factory method (one per filter type)
list.add(controllerInstance); // Add a pre-built controller
list.add(controller, 2); // Insert at index 2
list.remove(controller); // Remove and destroy
list.clear(); // Remove and destroy all
list.getActive(); // Get all active controllers
list.list; // Raw array (reorder safely)controller.active = false; // Disable without removing
controller.setActive(true); // Enable (returns this)
controller.setPaddingOverride(10, 10, 10, 10); // Override padding
controller.setPaddingOverride(null); // Clear override
controller.ignoreDestroy = true; // Survive FilterList.destroy()
controller.destroy(); // Manual cleanupconst mask = list.addMask('texKey'); // From texture key
const mask = list.addMask(gameObject); // From game object
mask.invert = true; // Invert mask
mask.autoUpdate = false; // Stop auto-updating GO masks
mask.needsUpdate = true; // Force one update
mask.setTexture('newKey'); // Change texture source
mask.setGameObject(newGO); // Change GO source
mask.viewCamera = otherCamera; // Camera for GO rendering
mask.viewTransform = 'local'; // 'local' or 'world'
mask.scaleFactor = 0.5; // Scale mask texture sizeconst cm = list.addColorMatrix();
cm.colorMatrix.sepia();
cm.colorMatrix.grayscale(1);
cm.colorMatrix.brightness(0.3);
cm.colorMatrix.hue(90);
cm.colorMatrix.saturate(-0.5);
cm.colorMatrix.contrast(0.3);
cm.colorMatrix.blackWhite();
cm.colorMatrix.negative();
cm.colorMatrix.desaturate();
cm.colorMatrix.night(0.5);
cm.colorMatrix.lsd();
cm.colorMatrix.brown();
cm.colorMatrix.vintagePinhole();
cm.colorMatrix.kodachrome();
cm.colorMatrix.technicolor();
cm.colorMatrix.polaroid();
cm.colorMatrix.shiftToBGR();enableFilters()enableFilters()filtersqualitydistancesetForceComposite(true)setPaddingOverride()nullcamera.getPaddingWrapper(x)ignoreDestroy = trueautoUpdateautoUpdate = falseneedsUpdate = truePhaser.Actions.AddEffectBloom| v3 (FX) | v4 (Filters) | Notes |
|---|---|---|
| | |
| | Cameras now have both internal and external lists |
| Use | No dedicated Bloom filter; build it with ParallelFilters or |
| Use Vignette or Mask | Circle effect removed; use Vignette with radius or a circular Mask, or automate with |
| Use Gradient GameObject + Quantize | New Gradient GameObject renders gradients; Quantize adds steps if wanted |
Glow | Glow | Stochastic sampling replaces line sampling; higher quality at lower values |
| | Masks are now filters, not a separate system |
| | Same unified filter system |
| FX controllers | | Same pattern: returned controller objects with mutable properties |
| -- | | New explicit opt-in step for game objects |
| -- | Blocky, Quantize, Key, Blend, CombineColorMatrix, ImageLight, NormalTools, PanoramaBlur, ParallelFilters, Sampler | New filters added in v4 |
| File | Description |
|---|---|
| Mixin that adds |
| FilterList class with all |
| Base Controller class for all filters |
| Barrel distortion filter |
| Texture blend filter |
| Color-preserving pixelation filter |
| Gaussian blur filter |
| Bokeh / tilt shift filter |
| Color matrix filter (sepia, grayscale, etc.) |
| Dual-texture channel combining filter |
| Displacement map filter |
| Glow/outline filter |
| Gradient map recoloring filter |
| Image-based lighting filter |
| Chroma key filter |
| Alpha mask filter (texture or game object) |
| Normal map manipulation filter |
| Spherical panorama blur filter |
| Parallel filter paths with blend |
| Pixelation filter |
| Color quantization filter |
| Pixel sampling/readback filter |
| Drop shadow filter |
| Threshold filter |
| Vignette filter |
| Wipe/reveal transition filter |
| CaptureFrame game object for scene-level capture |