In addition to real-time computed direct light sources, we generally need to pre-bake lighting offline as ambient light for real-time sampling. This method effectively captures the global illumination and atmosphere of the environment, making objects blend better into their surroundings.
Property | Function |
---|---|
Source | Specifies whether the diffuse source is Background or Solid Color , with the default source being Background . Background means using the baked spherical harmonics parameters as the diffuse color; Solid Color means using a solid color as the diffuse color. |
Intensity | Diffuse intensity |
Property | Function |
---|---|
Source | Specifies whether the specular source is Background or Custom , with the default source being Background . Background means using the pre-filtered environment map baked from the background as the specular reflection; Custom means you can separately bake an HDR map as the environment reflection. |
Intensity | Specular intensity |
After obtaining the URL of the baked product through the baking tutorial, load and parse it through the engine's EnvLoader:
engine.resourceManager
.load<AmbientLight>({
type: AssetType.Env,
url: "https://gw.alipayobjects.com/os/bmw-prod/89c54544-1184-45a1-b0f5-c0b17e5c3e68.bin"
})
.then((ambientLight) => {
scene.ambientLight = ambientLight;
// 可以调节漫反射、镜面反射强度,默认为1
// ambientLight.diffuseIntensity = 1;
// ambientLight.specularIntensity = 1;
// 预滤波环境贴图(ambientLight.specularTexture)还可以作为场景的背景
// skyMaterial.texture = ambientLight.specularTexture;
// 由于烘焙产物的颜色编码方式是 RGBM,因此作为背景时需要将解码设置为 textureDecodeRGBM
// skyMaterial.textureDecodeRGBM = true;
});