Ok, here are estimated files to change:
- baseTexture.polynomial.ts
- Added _sphericalPolynomialTargetSize: number via module augmentation on BaseTexture
- Initialized to 0 on prototype (default = full resolution, no behavior change)
- cubeTexture.ts
- Added sphericalPolynomialTargetSize?: number to ICubeTextureCreationOptions
- Wired through constructor options handling
- envCubeTexture.ts
- Added sphericalPolynomialTargetSize = 0 constructor parameter
- Stores on instance; passes to ConvertCubeMapToSphericalPolynomial in the eager (HDR/EXR) path
- hdrCubeTexture.ts
- Added sphericalPolynomialTargetSize = 0 constructor parameter, passes through to EnvCubeTexture
- equiRectangularCubeTexture.ts
- Added sphericalPolynomialTargetSize = 0 constructor parameter, stores on instance
- Added side-effect import of baseTexture.polynomial
- 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
