filters-and-postfx
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePhaser 4 Filters and Post-FX
Phaser 4 滤镜与后期特效
Quick Start
快速入门
Add a glow effect to a sprite:
js
// 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);Add a blur to the camera:
js
// Cameras have filters enabled by default - no enableFilters() needed
const camera = this.cameras.main;
camera.filters.internal.addBlur(0, 2, 2, 1);为精灵添加发光效果:
js
// 在你的场景的create()方法中:
const sprite = this.add.sprite(400, 300, 'player');
// 步骤1:在游戏对象上启用滤镜系统(仅支持WebGL)
sprite.enableFilters();
// 步骤2:通过.filters.internal或.filters.external添加滤镜
sprite.filters.internal.addGlow(0xff00ff, 4, 0, 1);为相机添加模糊效果:
js
// 相机默认已启用滤镜,无需调用enableFilters()
const camera = this.cameras.main;
camera.filters.internal.addBlur(0, 2, 2, 1);Core Concepts
核心概念
How Filters Work in v4
v4中滤镜的工作方式
Filters are GPU-based post-processing effects applied after an object or camera renders to a texture. Each filter runs a shader pass over that texture, producing the final visual output. Filters are WebGL only.
The rendering pipeline for a camera with filters:
- Objects render to a texture the size of the camera.
- Internal filters process that texture, applying effects in object/camera local space.
- The texture is drawn to a context-sized texture, applying camera transformations (position, rotation, zoom).
- External filters process that context texture, applying effects in screen space.
- The final texture is composited into the output.
滤镜是基于GPU的后期处理效果,在对象或相机渲染到纹理后应用。每个滤镜会对该纹理执行一次着色器处理,生成最终的视觉输出。滤镜仅支持WebGL。
带滤镜的相机渲染流程:
- 对象渲染到与相机尺寸一致的纹理上。
- 内部滤镜处理该纹理,在对象/相机的局部空间中应用效果。
- 将纹理绘制到与上下文尺寸一致的纹理上,应用相机变换(位置、旋转、缩放)。
- 外部滤镜处理该上下文纹理,在屏幕空间中应用效果。
- 将最终纹理合成到输出画面中。
Internal vs External Filters
内部滤镜 vs 外部滤镜
Every exposes two sub-lists: and . The distinction controls when the filter runs relative to the camera/object transform:
FilterListfilters.internalfilters.external- Internal -- applied before the camera transform. Effects operate in the object's local coordinate space. A horizontal blur on a rotated object appears rotated with the object. Internal filters only cover the object/camera region, so they are cheaper.
- External -- applied after the camera transform. Effects operate in screen space. A horizontal blur on a rotated object always blurs horizontally on screen. External filters are full-screen and more expensive.
Use internal filters wherever possible for better performance.
每个都包含两个子列表:和。两者的区别决定了滤镜相对于相机/对象变换的执行时机:
FilterListfilters.internalfilters.external- 内部滤镜 -- 在相机变换前应用。效果在对象的局部坐标系中生效。对旋转对象应用水平模糊时,模糊效果会随对象一起旋转。内部滤镜仅覆盖对象/相机区域,因此性能开销更低。
- 外部滤镜 -- 在相机变换后应用。效果在屏幕空间中生效。对旋转对象应用水平模糊时,模糊效果始终沿屏幕水平方向。外部滤镜是全屏的,性能开销更高。
尽可能使用内部滤镜以获得更好的性能。
FilterList
FilterList
FilterListPhaser.GameObjects.Components.FilterList- -- add a Controller instance at an optional index
add(filter, index) - -- remove and destroy a filter
remove(filter, forceDestroy) - -- remove and destroy all filters
clear() - -- return all filters where
getActive()active === true - -- the raw array of Controllers (safe to reorder)
list - Convenience factory methods: ,
addBlur(),addGlow(), etc.addMask()
FilterListPhaser.GameObjects.Components.FilterList- -- 在可选索引位置添加一个控制器实例
add(filter, index) - -- 移除并销毁滤镜
remove(filter, forceDestroy) - -- 移除并销毁所有滤镜
clear() - -- 返回所有
getActive()的滤镜active === true - -- 控制器的原始数组(可安全重新排序)
list - 便捷工厂方法:、
addBlur()、addGlow()等addMask()
Filter Controllers
滤镜控制器
Every filter is a subclass. Common Controller properties:
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) |
Key methods: , , , .
setActive(bool)setPaddingOverride(left, top, right, bottom)getPadding()destroy()每个滤镜都是的子类。常见控制器属性:
Phaser.Filters.Controller| 属性 | 类型 | 描述 |
|---|---|---|
| boolean | 在不移除滤镜的情况下切换其开关状态 |
| Camera | 拥有该滤镜的相机 |
| string | 着色器的渲染节点ID |
| Rectangle | 覆盖自动内边距计算 |
| boolean | 如果为true,当所属FilterList被销毁时,该滤镜会保留(用于复用) |
关键方法:、、、。
setActive(bool)setPaddingOverride(left, top, right, bottom)getPadding()destroy()Enabling Filters on Game Objects
在游戏对象上启用滤镜
Cameras have filters available by default. Game objects do not -- you must call first:
enableFilters()js
const sprite = this.add.sprite(400, 300, 'hero');
sprite.enableFilters();
// Now sprite.filters is available
sprite.filters.internal.addGlow();
sprite.filters.external.addVignette();enableFilters()filterCamerathisRelated properties on game objects after enabling:
| 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 |
Use to check if any active filters will actually render.
willRenderFilters()相机默认已启用滤镜,而游戏对象则需要先调用:
enableFilters()js
const sprite = this.add.sprite(400, 300, 'hero');
sprite.enableFilters();
// 现在可以访问sprite.filters
sprite.filters.internal.addGlow();
sprite.filters.external.addVignette();enableFilters()filterCamerathis启用后游戏对象的相关属性:
| 属性 | 默认值 | 描述 |
|---|---|---|
| null -> Camera | 用于滤镜渲染的内部相机 |
| null -> {internal, external} | 访问FilterList对 |
| true | 所有滤镜渲染的总开关 |
| true | 自动调整相机以跟随对象 |
| false | 聚焦于渲染上下文而非对象边界 |
| false | 即使没有激活的滤镜,也始终绘制到帧缓冲区 |
| null -> Vector2 | 滤镜帧缓冲区的最大纹理尺寸 |
使用检查是否有激活的滤镜会实际渲染。
willRenderFilters()Common Patterns
常见用法
Adding Filters to Game Objects
为游戏对象添加滤镜
js
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);js
const sprite = this.add.sprite(400, 300, 'enemy');
sprite.enableFilters();
// 添加发光效果
const glow = sprite.filters.internal.addGlow(0x00ff00, 4);
// 运行时修改参数
glow.outerStrength = 8;
glow.color = 0xff0000;
// 临时禁用
glow.setActive(false);
// 移除并销毁
sprite.filters.internal.remove(glow);Camera Filters
相机滤镜
js
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();js
const camera = this.cameras.main;
// 内部滤镜:在相机局部空间生效
const blur = camera.filters.internal.addBlur(0, 2, 2, 1);
// 外部滤镜:在屏幕空间生效
const vignette = camera.filters.external.addVignette(0.5, 0.5, 0.5, 0.5);
// 通过ColorMatrix进行颜色分级
const cm = camera.filters.internal.addColorMatrix();
cm.colorMatrix.sepia();Chaining Multiple Filters
链式添加多个滤镜
Filters execute in list order. Each filter receives the output of the previous one:
js
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);滤镜按列表顺序执行,每个滤镜的输出作为下一个滤镜的输入:
js
const cam = this.cameras.main;
// 第一步:应用颜色分级
const cm = cam.filters.internal.addColorMatrix();
cm.colorMatrix.brightness(0.2);
// 第二步:对颜色分级后的结果应用模糊
cam.filters.internal.addBlur(1, 2, 2, 1);
// 第三步:在顶部添加暗角效果
cam.filters.external.addVignette(0.5, 0.5, 0.5, 0.8);Masks via Filters
通过滤镜实现遮罩
Masks in v4 are implemented as filters. They use the alpha channel of a texture or game object to control visibility:
js
// 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);Internal masks match the object being filtered. External masks match the camera context. Use a parameter to control which camera renders the mask game object.
viewCamerav4中的遮罩通过滤镜实现,使用纹理或游戏对象的Alpha通道控制可见性:
js
// 使用静态纹理作为遮罩
sprite.enableFilters();
sprite.filters.internal.addMask('maskTexture');
// 使用游戏对象作为遮罩(自动渲染到DynamicTexture)
const maskShape = this.add.circle(0, 0, 100, 0xffffff);
sprite.enableFilters();
const mask = sprite.filters.internal.addMask(maskShape);
// 反转遮罩
mask.invert = true;
// 控制游戏对象遮罩的自动更新
mask.autoUpdate = true; // 默认值:每帧重新渲染
mask.needsUpdate = true; // 强制单次更新
// 使用指定相机渲染遮罩对象
sprite.filters.external.addMask(maskShape, false, this.cameras.main);内部遮罩与被过滤的对象匹配,外部遮罩与相机上下文匹配。使用参数控制哪个相机渲染遮罩游戏对象。
viewCameraWipe / Reveal Transitions
擦除/显示过渡效果
js
const 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');js
const camera = this.cameras.main;
const wipe = camera.filters.external.addWipe(0.1, 0, 0);
// 通过补间动画实现
this.tweens.add({
targets: wipe,
progress: 1,
duration: 2000,
ease: 'Linear'
});
// 方向辅助方法
wipe.setLeftToRight();
wipe.setTopToBottom();
wipe.setRevealEffect(); // 显示模式
wipe.setWipeEffect(); // 擦除模式
// 擦除到另一张纹理(用于场景过渡)
wipe.setTexture('nextSceneCapture');ParallelFilters (Custom Bloom and Compositing)
ParallelFilters(自定义Bloom与合成)
ParallelFilters splits the input into two paths, processes each independently, then blends the results. This replaces the dedicated Bloom filter from v3:
js
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 inputParallelFilters将输入分为两条路径,分别独立处理后再混合结果。它取代了v3中的专用Bloom滤镜:
js
const camera = this.cameras.main;
const pf = camera.filters.internal.addParallelFilters();
// 上方路径:高亮区域阈值化,然后模糊
pf.top.addThreshold(0.5, 1);
pf.top.addBlur();
// 配置混合方式(上方路径如何与下方路径混合)
pf.blend.blendMode = Phaser.BlendModes.ADD;
pf.blend.amount = 0.5;
// 下方路径:留空则使用原始输入CaptureFrame for Scene-Level Effects
CaptureFrame用于场景级效果
CaptureFramejs
// 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);CaptureFramejs
// 需要相机启用合成模式
this.cameras.main.setForceComposite(true);
// 在CaptureFrame之前渲染的对象会被捕获
const bg = this.add.image(400, 300, 'background');
// 创建捕获点
const capture = this.add.captureFrame('myCapture');
// 显示捕获的纹理并应用滤镜
const display = this.add.image(400, 300, 'myCapture');
display.enableFilters();
display.filters.internal.addBlur(0, 4, 4, 2);All Built-in Filters
所有内置滤镜
| 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 |
| 滤镜 | 添加方法 | 描述 |
|---|---|---|
| Barrel | | 挤压/扩张畸变效果。 |
| Blend | | 使用混合模式混合另一张纹理。支持标准WebGL不具备的混合模式。 |
| Blocky | | 保留原始颜色的像素化效果(无混合)。在禁用抗锯齿时效果最佳。 |
| Blur | | 高斯模糊。Quality:0=低质量,1=中等质量,2=高质量。 |
| Bokeh | | 景深散景模糊效果。 |
| ColorMatrix | | 通过矩阵进行颜色调整。访问 |
| CombineColorMatrix | | 通过颜色矩阵合并两张纹理的通道。适用于Alpha通道传递。 |
| Displacement | | 使用位移图纹理实现像素位移。参数值为极小的浮点数(例如0.005)。 |
| Glow | | 边缘发光效果。支持内外发光和挖空模式。 |
| GradientMap | | 根据亮度使用ColorRamp重新为图像上色。 |
| ImageLight | | 使用全景环境贴图和法线贴图实现基于图像的光照。 |
| Key | | 色度键:移除或隔离特定颜色。配置项: |
| Mask | | 通过纹理或游戏对象实现Alpha遮罩。 |
| NormalTools | | 法线贴图处理:旋转、调整朝向强度、输出灰度朝向数据。 |
| PanoramaBlur | | 全景图像的球面校正模糊效果。配合ImageLight使用。性能开销极高。 |
| ParallelFilters | | 将输入分为两条滤镜路径,混合结果。用于自定义Bloom效果。 |
| Pixelate | | 马赛克/像素化效果。像素尺寸=2+amount。会混合颜色(与Blocky不同)。 |
| Quantize | | 减少颜色调色板。支持RGBA/HSVA模式、伽马、偏移、抖动。 |
| Sampler | | 从渲染结果中提取像素数据。不会修改图像。性能开销高。 |
| Shadow | | 带有偏移、衰减和颜色的投影效果。 |
| Threshold | | 逐通道二元阈值处理。Edges可为数组以实现逐通道控制。 |
| TiltShift | | 微缩/移轴效果(内部使用Bokeh)。 |
| Vignette | | 边缘暗化/上色效果。支持NORMAL、ADD、MULTIPLY、SCREEN混合模式。 |
| Wipe | | 擦除/显示过渡效果。通过补间动画控制 |
API Quick Reference
API快速参考
Enabling and Accessing Filters
启用和访问滤镜
js
// 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();js
// 游戏对象:必须先启用
gameObject.enableFilters();
gameObject.filters.internal.addBlur();
gameObject.filters.external.addGlow();
// 相机:可直接访问滤镜
camera.filters.internal.addBlur();
camera.filters.external.addGlow();FilterList Methods
FilterList方法
js
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)js
const list = camera.filters.internal;
list.addBlur(); // 工厂方法(每种滤镜对应一个)
list.add(controllerInstance); // 添加预构建的控制器
list.add(controller, 2); // 插入到索引2的位置
list.remove(controller); // 移除并销毁
list.clear(); // 移除并销毁所有滤镜
list.getActive(); // 获取所有激活的控制器
list.list; // 原始数组(可安全重新排序)Controller Common API
控制器通用API
js
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 cleanupjs
controller.active = false; // 禁用滤镜但不移除
controller.setActive(true); // 启用滤镜(返回自身)
controller.setPaddingOverride(10, 10, 10, 10); // 覆盖内边距设置
controller.setPaddingOverride(null); // 清除内边距覆盖
controller.ignoreDestroy = true; // 在FilterList销毁时保留
controller.destroy(); // 手动清理Mask Filter API
遮罩滤镜API
js
const 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 sizejs
const mask = list.addMask('texKey'); // 通过纹理键创建
const mask = list.addMask(gameObject); // 通过游戏对象创建
mask.invert = true; // 反转遮罩
mask.autoUpdate = false; // 停止自动更新游戏对象遮罩
mask.needsUpdate = true; // 强制单次更新
mask.setTexture('newKey'); // 更改纹理源
mask.setGameObject(newGO); // 更改游戏对象源
mask.viewCamera = otherCamera; // 用于渲染游戏对象的相机
mask.viewTransform = 'local'; // 'local'或'world'
mask.scaleFactor = 0.5; // 遮罩纹理尺寸缩放因子ColorMatrix Presets
ColorMatrix预设
js
const 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();js
const 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();Gotchas
注意事项
-
WebGL only -- Filters do not work in Canvas renderer.returns early if WebGL is not available.
enableFilters() -
enableFilters() required for game objects -- Cameras have filters by default. Sprites, images, containers, and other game objects requirebefore accessing
enableFilters().filters -
Performance cost -- Each object with active filters creates extra draw calls (one for the base render plus one per active filter). Use sparingly and performance test early.
-
Internal vs external matters -- Internal filters are cheaper (object-region sized). External filters are full-screen. A blur that should rotate with the object must be internal; a blur that should stay screen-aligned must be external.
-
Filter order matters -- Filters are applied sequentially in list order. The output of one feeds into the next.
-
Glow quality and distance are immutable --and
qualityon the Glow filter cannot be changed after creation. Destroy and recreate the filter to change them.distance -
CaptureFrame requires forceComposite -- The camera must haveor otherwise render into a framebuffer for CaptureFrame to work.
setForceComposite(true) -
Padding for expanding effects -- Filters like Blur, Glow, and Shadow can automatically calculate padding to expand the render texture. Override withif needed. Pass
setPaddingOverride()to clear the override. When used on a camera, usenullto render more world outside the image edge.camera.getPaddingWrapper(x) -
Controller reuse -- By default, controllers are destroyed when their FilterList is destroyed. Setto reuse a controller across multiple objects, but you must manage its lifecycle manually. Works best with external filters.
ignoreDestroy = true -
Mask game object rendering -- When using a game object as a mask source, it is rendered to a DynamicTexture each frame (ifis true). Set
autoUpdateand useautoUpdate = falsefor one-shot updates to improve performance for static masks.needsUpdate = true -
No Bloom filter -- v4 does not have a dedicated Bloom filter. Use ParallelFilters with Threshold + Blur + ADD blend instead (see Common Patterns), or useto automate the process.
Phaser.Actions.AddEffectBloom
-
仅支持WebGL -- 滤镜在Canvas渲染器中无法工作。如果WebGL不可用,会提前返回。
enableFilters() -
游戏对象需调用enableFilters() -- 相机默认已启用滤镜。精灵、图像、容器及其他游戏对象在访问前必须调用
filters。enableFilters() -
性能开销 -- 每个带有激活滤镜的对象会增加额外的绘制调用(一次基础渲染加上每个激活滤镜一次调用)。请谨慎使用并尽早进行性能测试。
-
内部与外部滤镜的区别很重要 -- 内部滤镜开销更低(仅覆盖对象区域),外部滤镜是全屏的。需要随对象旋转的模糊效果必须使用内部滤镜;需要保持屏幕对齐的模糊效果必须使用外部滤镜。
-
滤镜顺序很重要 -- 滤镜按列表顺序依次应用,前一个滤镜的输出作为后一个的输入。
-
Glow的quality和distance不可变 -- Glow滤镜的和
quality参数在创建后无法修改。如需更改,需销毁并重新创建滤镜。distance -
CaptureFrame需要forceComposite -- 相机必须设置或以其他方式渲染到帧缓冲区,CaptureFrame才能正常工作。
setForceComposite(true) -
扩展效果的内边距 -- Blur、Glow和Shadow等滤镜会自动计算内边距以扩展渲染纹理。如有需要,可使用覆盖。传入
setPaddingOverride()可清除覆盖。在相机上使用时,可通过null渲染图像边缘外的更多世界内容。camera.getPaddingWrapper(x) -
控制器复用 -- 默认情况下,控制器会在所属FilterList销毁时被销毁。设置可在多个对象间复用控制器,但需手动管理其生命周期。该方式更适用于外部滤镜。
ignoreDestroy = true -
遮罩游戏对象的渲染 -- 使用游戏对象作为遮罩源时,如果为true,每帧都会将其渲染到DynamicTexture。对于静态遮罩,设置
autoUpdate并使用autoUpdate = false进行单次更新可提升性能。needsUpdate = true -
无专用Bloom滤镜 -- v4没有专用的Bloom滤镜。可使用ParallelFilters配合Threshold+Blur+ADD混合模式实现(见常见用法),或使用自动完成该过程。
Phaser.Actions.AddEffectBloom
v4 Changes from v3
v4与v3的差异
| 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 |
| v3(FX) | v4(Filters) | 说明 |
|---|---|---|
| | |
| | 相机现在同时拥有内部和外部滤镜列表 |
| 使用 | 无专用Bloom滤镜;使用ParallelFilters或 |
| 使用Vignette或Mask | 圆形效果已移除;使用带半径的Vignette或圆形Mask,或通过 |
| 使用Gradient GameObject + Quantize | 新增Gradient GameObject用于渲染渐变;Quantize可添加渐变阶数 |
Glow的 | Glow的 | 随机采样取代了线性采样;更低的数值对应更高的质量 |
| | 遮罩现在是滤镜的一部分,而非独立系统 |
| | 统一的滤镜系统 |
| FX控制器 | | 模式相同:返回带有可变属性的控制器对象 |
| -- | 游戏对象需调用 | 新增的显式启用步骤 |
| -- | Blocky、Quantize、Key、Blend、CombineColorMatrix、ImageLight、NormalTools、PanoramaBlur、ParallelFilters、Sampler | v4新增的滤镜 |
Source File Map
源文件映射
| 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 |
Related: sprites-and-images.md, cameras.md, v4-new-features.md
| 文件 | 描述 |
|---|---|
| 混入类,为游戏对象添加 |
| FilterList类,包含所有 |
| 所有滤镜的基类Controller |
| 桶形畸变滤镜 |
| 纹理混合滤镜 |
| 保留颜色的像素化滤镜 |
| 高斯模糊滤镜 |
| 散景/移轴滤镜 |
| 颜色矩阵滤镜(棕褐色调、灰度等) |
| 双纹理通道合并滤镜 |
| 位移图滤镜 |
| 发光/描边滤镜 |
| 渐变映射重上色滤镜 |
| 基于图像的光照滤镜 |
| 色度键滤镜 |
| Alpha遮罩滤镜(纹理或游戏对象) |
| 法线贴图处理滤镜 |
| 球面全景模糊滤镜 |
| 带混合的并行滤镜路径 |
| 像素化滤镜 |
| 颜色量化滤镜 |
| 像素采样/回读滤镜 |
| 投影滤镜 |
| 阈值滤镜 |
| 暗角滤镜 |
| 擦除/显示过渡滤镜 |
| 用于场景级捕获的CaptureFrame游戏对象 |
相关文档:sprites-and-images.md, cameras.md, v4-new-features.md