Skip to content

DepthOfFieldEffect

概览

字段
KindUnit · 单位 Unit
Realmcommon

继承关系

  • Unit(4 属性 / 25 函数 / 6 事件)

继承成员

2 个来源 / 5 属性 / 25 函数 / 6 事件

DepthOfFieldEffect 是控制场景景深效果的后处理单元,通过 FocusDistance 和 MaxBlurSize 调整对焦距离与最大模糊半径;启用后需挂载到 LightingService 才能生效。

适用场景

常用于需要突出特定距离物体的场景,例如在过场动画或特写镜头中,通过设置 FocusDistance 和 MaxBlurSize 使背景或前景产生模糊,增强视觉层次感。

使用要点

通过 game:CreateUnit("DepthOfFieldEffect", { Enabled = true }) 创建实例,将 Parent 设置为 LightingService,再设置 FocusDistance 和 MaxBlurSize 调整景深效果。

注意事项

实例必须挂载到 LightingService 下才能参与后处理(与 BloomEffectColorGradingEffect 一致)。正式服务名必须保留 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类型默认值说明
FocusDistanceFloat0.0控制景深效果的对焦距离,即清晰成像的平面到摄像机的距离。
MaxBlurSizeFloat0.0控制景深效果的最大模糊半径,数值越大,远离对焦平面的区域越模糊。

关联类型