Log inGet started
Package

ambient_light.shaderModule

Newest version

This package holds more than this page lists. See all of its files in its world.

README.md

ambient_light

The diffuse light a point takes from its surroundings: the scene's flat ambient term, the captured environment (the reflection probes and the sky under them) around a direction, and the baked irradiance light-probe volumes wherever they cover the point. The PBR diffuse lobe reads it along a surface's normal, and a participating medium reads it from every direction at once, so fog, smoke and the surfaces around them are lit by the same sky or room.

The module is engine-owned (zero::ambient_light): it reads the probe and volume records behind the environment binding, so every program composes the engine's own copy of it, and a copy a world holds is set aside.

#include "@builtin::shaderModules.ambient_light"

// A surface with normal `n`.
let irradiance = zpbr_surroundings_irradiance(world_pos, n, flat_ambient);
// A point in a medium, lit from every direction.
let in_scatter = zpbr_surroundings_in_scatter(world_pos, flat_ambient);
  • zpbr_surroundings_irradiance(world_pos, n, flat_ambient): the irradiance on a surface with normal n. Baked volumes replace the unbaked term where they cover the point and fade to it at a field's border.
  • zpbr_surroundings_in_scatter(world_pos, flat_ambient): the mean of the irradiance over the six axis directions, the light a medium of albedo 1 scatters evenly. Over a baked volume it is the SH field's constant term, and over the captured environment a six-direction estimate of the mean over the sphere, so the sky above and the ground below light the medium together.
  • zpbr_ambient_irradiance(world_pos, n, flat_ambient): the unbaked term, the flat ambient plus zpbr_environment_irradiance, the captured environment along n at its widest prefiltered lobe.
  • zpbr_volume_irradiance(world_pos, n): the baked volumes alone, with their total blend weight in w.

Each *_with_probes form takes the probes zpbr_select_probes(world_pos) already selected, for a caller reading several directions at one point.

Bindings

Reads environment_map, environment_sampler and zero_environment by name, through zero::environment: group(0)'s in a material, and in a compute pass the bindings its bindings.yaml declares under those names:

bindings:
  - { name: environment_map, kind: textureCubeArray }
  - { name: environment_sampler, kind: sampler }
  - { name: zero_environment, kind: buffer, access: read, element: ZeroEnvironment, array: false }
inputs = {
    environment_map = "@scene.environment",
    environment_sampler = "@scene.environmentSampler",
    zero_environment = "@scene.reflectionProbes",
}