Files
engine/docs/en/graphics/light/ambient.md
2024-08-05 16:03:57 +08:00

2.5 KiB
Raw Blame History

order, title, type, group, label
order title type group label
4 Ambient Light Graphics Light Graphics/Light

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.

image-20231227151844040

Editor Usage

1. Ambient Diffuse

image-20240219163916257
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

2. Ambient Specular

image-20240219163941010
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

Script Usage

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;
  });