prefilterEquirectRadianceToCube function Lighting and environment
Prefilters an equirectangular radiance source into a roughness-mip cubemap
(mip i = perceptual roughness i/(kPrefilterBandCount-1)), sampled at
draw time with textureLod(samplerCube, dir, roughness * maxLod). Removes
the equirect pole singularity from the radiance reflections sample. size
is the base-mip face size.
The result is exactly what EnvironmentMap.fromGpuTextures expects for the
cube layout, and what EnvironmentMap.fromKtx2Bytes reproduces from a
pre-baked file. sourceEquirect is sRGB-encoded unless sourceIsLinear.
Implementation
gpu.Texture prefilterEquirectRadianceToCube(
gpu.Texture sourceEquirect, {
bool sourceIsLinear = false,
int size = kRadianceCubeSize,
}) {
final cube = createRadianceCubeTexture(size: size);
for (var face = 0; face < 6; face++) {
for (var band = 0; band < kPrefilterBandCount; band++) {
prefilterEquirectRadianceCubeFace(
sourceEquirect,
cube,
face,
band,
sourceIsLinear: sourceIsLinear,
);
}
}
return cube;
}