# 体积光

体积光(Volumetric Light)是一种很吸引眼球、很能表现氛围、看起来很高级的效果,也被称为天光(GodRay)。体积光的物理原理是丁达尔效应:当光透过胶体时,会被悬浮在胶体中的粒子散射,出现一条光亮的“通路”。因为空气中悬浮的灰尘、水滴等杂质直径大于入射光波长,满足胶体的条件,所以太阳光穿过空气时会出现体积光效果,比如下图。

avatar

avatar

# 初始化

使用GodRays类添加体积光效果。

import { 
    
    Postprocessing, 
    GodRays, 
    KernelSize

} from '@tx3d/postprocessing';

// 创建后处理类
const postprocessing = new Postprocessing( engine );

// 添加后处理效果
const effect = postprocessing.addEffect( GodRays, {

    sunColor:'#ffddaa',
    sunPosition:[ 0, 25, -84 ],
    sunSize:5.3,
    kernelSize:KernelSize.SMALL,
    density:0.96,
    decay:0.94,
    weight:1.0,
    exposure:1.0,
    samples:60,
    clampMax:1.0,
    resolutionScale:0.5

} );
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

提示

体积光初始化参数,详见GodRaysParams

# 属性

🌏 resolutionScale 渲染分辨率

effect.resolutionScale = 0.5;
1

🌏 kernelSize 模糊核大小

effect.kernelSize = KernelSize.SMALL;
1

🌏 density 采样间隔密度

effect.density = 0.96;
1

🌏 decay 光线衰减系数

effect.decay = 0.94;
1

🌏 weight 权重

effect.weight = 1.0;
1

🌏 exposure 曝光度

effect.exposure = 1.0;
1

🌏 clampMax 颜色值上限

effect.clampMax = 1.0;
1

🌏 samples 采样次数

effect.samples = 60;
1

🌏 sunColor 太阳颜色

effect.sunColor = '#ffddaa';
1

🌏 sunPosition 太阳位置

effect.sunPosition = [ 0, 25, -84 ];
1

🌏 sunSize 太阳大小

effect.sunSize = 5.3;
1
Last Updated: 3/10/2023, 1:05:22 PM