prefilterEquirectRadiance function Lighting and environment

Texture prefilterEquirectRadiance(
  1. Texture sourceEquirect, {
  2. bool sourceIsLinear = false,
  3. bool mipLayout = false,
})

Prefilters an equirectangular radiance texture for image-based specular lighting.

Renders kPrefilterBandCount GGX-prefiltered roughness bands (see flutter_scene_prefilter_env.frag). With mipLayout (the default layout new environments use, see EnvironmentMap.useMipRadianceLayout) the bands are the mip levels of one equirect texture, sampled with hardware trilinear textureLod; otherwise the bands are stacked vertically into the legacy atlas. Intended to run once when an EnvironmentMap is constructed; the result is cached on the environment and sampled at draw time by the standard shader's SamplePrefilteredRadiance.

sourceEquirect is an equirectangular radiance map. By default it is treated as sRGB-encoded; pass sourceIsLinear when it already holds linear radiance (an HDR environment), so it is not linearized twice. The result always stores linear radiance.

Implementation

gpu.Texture prefilterEquirectRadiance(
  gpu.Texture sourceEquirect, {
  bool sourceIsLinear = false,
  bool mipLayout = false,
}) {
  final atlas = createPrefilterAtlasTexture(mipLayout: mipLayout);
  if (mipLayout) {
    for (var band = 0; band < kPrefilterBandCount; band++) {
      _prefilterPass(
        sourceEquirect,
        atlas,
        band: band,
        clear: true,
        sourceIsLinear: sourceIsLinear,
      );
    }
  } else {
    _prefilterPass(
      sourceEquirect,
      atlas,
      band: -1,
      clear: true,
      sourceIsLinear: sourceIsLinear,
    );
  }
  return atlas;
}