主题
DepthOfFieldEffect
概览
| 字段 | 值 |
|---|---|
| Kind | Unit · 单位 Unit |
| Realm | common |
继承关系
- Unit(4 属性 / 25 函数 / 6 事件)
- BasePostEffect(1 属性)
- [DepthOfFieldEffect](2 属性)
- BasePostEffect(1 属性)
继承成员
2 个来源 / 5 属性 / 25 函数 / 6 事件
- 来自 BasePostEffect(1 属性)
- 属性:
Enabled
- 属性:
- 来自 Unit(4 属性 / 25 函数 / 6 事件)
- 属性:
AssetId、Name、Desc、Parent - 函数:
ClearAllChildren、GetChildren、GetDescendants、IsAncestorOf、IsDescendantOf、FindFirstAncestor、FindFirstAncestorWhichIsA、FindFirstAncestorOfClass、FindFirstChild、FindFirstChildWhichIsA、FindFirstChildOfClass、HasChildren、GetChildCount、GetChildAtIndex、SetAttribute、GetAttribute、GetAllProps、Clone、IsA、Destroy、GetPropertyChangedSignal、GetAttributeChangedSignal、FindFromPath、GetFullPath、GetDebugId - 事件:
ChildAdded、ChildRemoved、DescendantAdded、DescendantRemoving、AncestryChanged、Destroying
- 属性:
DepthOfFieldEffect 是控制场景景深效果的后处理单元,通过 FocusDistance 和 MaxBlurSize 调整对焦距离与最大模糊半径;启用后需挂载到 LightingService 才能生效。
适用场景
常用于需要突出特定距离物体的场景,例如在过场动画或特写镜头中,通过设置 FocusDistance 和 MaxBlurSize 使背景或前景产生模糊,增强视觉层次感。
使用要点
通过 game:CreateUnit("DepthOfFieldEffect", { Enabled = true }) 创建实例,将 Parent 设置为 LightingService,再设置 FocusDistance 和 MaxBlurSize 调整景深效果。
注意事项
实例必须挂载到 LightingService 下才能参与后处理(与 BloomEffect、ColorGradingEffect 一致)。正式服务名必须保留 Service 后缀。
代码示例
创建 DepthOfFieldEffect 并挂载到光照服务
lua
-- @runtime client
local Lighting = game:GetService('LightingService')
local depthOfFieldEffect = game:CreateUnit('DepthOfFieldEffect', {
Enabled = true,
})
depthOfFieldEffect.Parent = Lighting
print('后处理已启用:', depthOfFieldEffect.Enabled)属性 (2)
| Name | 类型 | 默认值 | 说明 |
|---|---|---|---|
FocusDistance | Float | 0.0 | 控制景深效果的对焦距离,即清晰成像的平面到摄像机的距离。 |
MaxBlurSize | Float | 0.0 | 控制景深效果的最大模糊半径,数值越大,远离对焦平面的区域越模糊。 |
