import { Renderer } from '../../core/renderers/utils'; import { GPUCurtains } from '../../curtains/GPUCurtains'; import { HDRImageData, HDRLoader } from '../loaders/HDRLoader'; import { Texture, TextureParams } from '../../core/textures/Texture'; import { Sampler } from '../../core/samplers/Sampler'; import { Mat3 } from '../../math/Mat3'; /** Define the base parameters for the {@link ComputePass} {@link Texture} writing. */ export interface ComputePassTextureParams { /** The size of the {@link Texture}, knowing the `width` and `height` are equal. */ size?: number; /** Number of samples to use in the {@link ComputePass} to generate the {@link Texture}. */ computeSampleCount?: number; } /** Define the base {@link Texture} parameters for the textures. */ export interface ComputeTextureBaseParams { /** Label of the {@link Texture}. */ label?: TextureParams['label']; /** Name of the {@link Texture}. */ name?: TextureParams['name']; /** Format of the {@link Texture}. */ format?: TextureParams['format']; } /** Define the parameters used to create the LUT {@link Texture}. */ export interface LUTTextureParams extends ComputePassTextureParams, ComputeTextureBaseParams { } /** Define the parameters used to create the diffuse cube map {@link Texture}. */ export interface DiffuseTextureParams extends ComputePassTextureParams, ComputeTextureBaseParams { } /** Define the parameters used to create the specular cube map {@link Texture}. */ export interface SpecularTextureParams extends ComputeTextureBaseParams { /** Number of samples to use for the mips PMREM generation. */ numSamples?: number; } /** Define the options used to create the textures by the {@link EnvironmentMap}. */ export interface EnvironmentMapOptions { /** Whether to create a LUT {@link Texture}. Default to `true`. */ useLutTexture: boolean; /** Define the parameters used to create the LUT {@link Texture}. */ lutTextureParams: LUTTextureParams; /** Define the parameters used to create the diffuse cube map {@link Texture}. */ diffuseTextureParams: DiffuseTextureParams; /** Define the parameters used to create the specular cube map {@link Texture}. */ specularTextureParams: SpecularTextureParams; /** Define the intensity of the indirect diffuse contribution to use in a PBR shader. Default to `1`. */ diffuseIntensity: number; /** Define the intensity of the indirect specular contribution to use in a PBR shader. Default to `1`. */ specularIntensity: number; /** Define the {@link EnvironmentMap} rotation along Y axis, in radians. Default to `Math.PI / 2` (90 degrees). */ rotation: number; } /** Define the parameters used to create the {@link EnvironmentMap}. */ export interface EnvironmentMapParams extends Partial { } /** * Utility to create environment maps specular, diffuse and LUT textures using an HDR file. * * Create a LUT texture on init using a {@link ComputePass}. Can load an HDR file and then create the cubemap and diffuse textures using two separate {@link ComputePass} and the PMREM texture using custom mips. * * Especially useful for IBL shading with {@link extras/meshes/LitMesh.LitMesh | LitMesh}. * * @example * ```javascript * // assuming 'renderer' is a valid renderer or curtains instance * const environmentMap = new EnvironmentMap(renderer) * await environmentMap.loadAndComputeFromHDR('path/to/environment-map.hdr') * ``` */ export declare class EnvironmentMap { #private; /** The {@link Renderer} used. */ renderer: Renderer; /** The universal unique id of the {@link EnvironmentMap}. */ readonly uuid: string; /** The {@link Sampler} used in both the {@link ComputePass} and in `IBL` shading from the {@link core/shaders/full/fragment/get-PBR-fragment-shader-code | getPBRFragmentShaderCode} utility function. */ sampler: Sampler; /** {@link HDRLoader} used to load the .hdr file. */ hdrLoader: HDRLoader; /** Options used to generate the {@link lutTexture}, {@link specularTexture} and {@link diffuseTexture}. */ options: EnvironmentMapOptions; /** Define the default environment maps rotation {@link Mat3}. */ rotationMatrix: Mat3; /** LUT {@link Texture} used for IBL shading, containing BRDF GGX in the `RG` channels and BRDF "Charlie" sheen in the `B` channel. */ lutTexture: Texture | null; /** Environment cube map {@link Texture}. */ cubemapTexture: Texture | null; /** Diffuse environment cube map {@link Texture}. */ diffuseTexture: Texture | null; /** Specular/PMREM environment cube map {@link Texture}. */ specularTexture: Texture | null; /** function assigned to the {@link onRotationAxisChanged} callback */ _onRotationAxisChangedCallback: () => void; /** * {@link EnvironmentMap} constructor. * @param renderer - {@link Renderer} or {@link GPUCurtains} class object used to create this {@link EnvironmentMap}. * @param params - {@link EnvironmentMapParams | parameters} use to create this {@link EnvironmentMap}. Defines the various textures options. */ constructor(renderer: Renderer | GPUCurtains, params?: EnvironmentMapParams); /** * Set or reset this {@link EnvironmentMap} {@link EnvironmentMap.renderer | renderer}. * @param renderer - New {@link Renderer} or {@link GPUCurtains} instance to use. */ setRenderer(renderer: Renderer | GPUCurtains): void; /** * Get the current {@link EnvironmentMapOptions.rotation | rotation}, in radians. */ get rotation(): number; /** * Set the current {@link EnvironmentMapOptions.rotation | rotation}, in radians. * @param value - New {@link EnvironmentMapOptions.rotation | rotation} to use, in radians. */ set rotation(value: number); /** * Callback to call whenever the {@link EnvironmentMapOptions.rotation | rotation} changed. * @param callback - Called whenever the {@link EnvironmentMapOptions.rotation | rotation} changed. */ onRotationAxisChanged(callback: () => void): this; /** * Create our {@link lutTexture} eagerly. */ createLUTTextures(): void; /** * Create our {@link specularTexture} and {@link diffuseTexture} eagerly. They could be resized later when calling the {@link computeFromHDR} method. */ createSpecularDiffuseTextures(): void; /** * Create the {@link lutTexture | BRDF GGX and sheen LUT texture} using the provided {@link LUTTextureParams | LUT texture options} and a {@link ComputePass} that runs once. */ computeBRDFLUTTexture(): Promise; /** * Create the {@link cubemapTexture | cube map texture} from a loaded {@link HDRImageData} using a {@link ComputePass} that runs once. * @param parsedHdr - parsed {@link HDRImageData} loaded by the {@link hdrLoader}. */ computeSpecularCubemapFromHDRData(parsedHdr: HDRImageData): Promise; /** * Generates the {@link specularTexture} Prefiltered, Mipmapped Radiance Environment Map (PMREM). * We manually generate the {@link specularTexture} prefiltered mips from our original {@link cubemapTexture}. * * @param commandEncoder - {@link GPUCommandEncoder} to use for mips generation. * @param mipBuffers - Array of {@link GPUBuffer} that will be created for each mips. Will be destroyed later. */ generateSpecularPMREMTexture(commandEncoder: GPUCommandEncoder, mipBuffers: GPUBuffer[]): void; /** * Compute the {@link diffuseTexture | diffuse cube map texture} from the {@link cubemapTexture | cube map texture } using the provided {@link DiffuseTextureParams | diffuse texture options} and a {@link ComputePass} that runs once. */ computeDiffuseFromCubemap(): Promise; /** * Load an HDR environment map and then generate the {@link specularTexture} and {@link diffuseTexture} using two separate {@link ComputePass}. * @param url - The url of the .hdr file to load. */ loadAndComputeFromHDR(url: string): Promise; /** * Generate the {@link specularTexture} and {@link diffuseTexture} using two separate {@link ComputePass}. */ computeFromHDR(): void; /** * Destroy the {@link EnvironmentMap} and its associated textures. */ destroy(): void; }