Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commit0a13e47b57

README.md

indirect_visibility

How much of the light of its surroundings reaches a surface, from the scene's occlusion channel (@scene.ao): the open share of the hemisphere, the bent normal and the cone the open part makes against a reflection lobe. The material's own indirect term and every composite that adds light a surface takes from around it (a probe field, a sky light, an environment) read the channel through these functions, so one occlusion answer shades all of that light.

A texel of the channel carries in r how much of the hemisphere is blocked, in g and b the bent normal laid flat on the octahedron, and in a whether a pass wrote one. Where none did, the visibility is exactly 1.

The module is engine-owned (zero::indirect_visibility): the PBR model includes it, so every program composes the engine's own copy, and a copy a world holds is set aside. It binds nothing; the functions that read the channel take it as an argument, so a surface shader and a compute pass call the same code.

#include "@builtin::shaderModules.indirect_visibility"

// In a compute pass that binds the channel as `scene_ao` (`@scene.ao`):
let texel = zpbr_occlusion_texel(scene_ao, vec2<f32>(coord));
let visibility = 1.0 - clamp(texel.r, 0.0, 1.0);
let bent = zpbr_decode_bent_normal(texel, n);
let diffuse = incoming * zpbr_multibounce(visibility, albedo);
let reflected = incoming_spec * zpbr_specular_occlusion(visibility, bent, n, r, roughness);
  • zpbr_multibounce(visibility, albedo): the visible share raised, per channel, by the light a crease of that colour bounces back into itself.
  • zpbr_specular_occlusion(visibility, bent, n, r, roughness): the share of the reflection lobe around r that the open cone holds, measured against the unoccluded lobe.
  • zpbr_cap_overlap(cos_a, cos_b, cos_d): the solid angle two spherical caps share.
  • zpbr_occlusion_texel(channel, px): the channel's texel at a pixel, clamped to the frame.
  • zpbr_decode_bent_normal(texel, fallback): the world-space bent normal a texel carries, fallback where no pass wrote one.
  • zpbr_open_share(channel, px): the open share at a pixel, 1 where no pass wrote the channel.