Downsampled SphericalHarmonics Creation

Ok, here are estimated files to change:

  1. baseTexture.polynomial.ts
  • Added _sphericalPolynomialTargetSize: number via module augmentation on BaseTexture
  • Initialized to 0 on prototype (default = full resolution, no behavior change)
  1. cubeTexture.ts
  • Added sphericalPolynomialTargetSize?: number to ICubeTextureCreationOptions
  • Wired through constructor options handling
  1. envCubeTexture.ts
  • Added sphericalPolynomialTargetSize = 0 constructor parameter
  • Stores on instance; passes to ConvertCubeMapToSphericalPolynomial in the eager (HDR/EXR) path
  1. hdrCubeTexture.ts
  • Added sphericalPolynomialTargetSize = 0 constructor parameter, passes through to EnvCubeTexture
  1. equiRectangularCubeTexture.ts
  • Added sphericalPolynomialTargetSize = 0 constructor parameter, stores on instance
  • Added side-effect import of baseTexture.polynomial
  1. cubemapToSphericalPolynomial.ts (main logic)
  • GPU path (ConvertCubeMapTextureToSphericalPolynomial): reads texture._sphericalPolynomialTargetSize, if mipmaps available reads from computed mip level, otherwise falls back to CPU box-filter downsample after readback
  • CPU path (ConvertCubeMapToSphericalPolynomial): accepts optional targetSize parameter, downsamples each face before integration
  • _DownsampleFace: box-filter averaging helper, handles both Float32Array and Uint8Array
  • _NearestPow2Floor: clamps non-pow-2 target sizes to nearest power-of-two (rounding down) — so passing e.g. 100 silently becomes 64

And here is a playground, open devtools console to compare performance:


This is less precise, but even faster than the GPU accelerated impl

1 Like