/** * Stable smoke product API. * * @module three-blocks/smoke */ import type { Matrix4, Node, NodeMaterial, Object3D, Renderer, Storage3DTexture, Texture, Vector2, Vector3 } from 'three/webgpu'; /** Pressure projection algorithm used by the volume solver. */ export type SmokePressureSolver = 'sor' | 'multigrid'; /** Coherent multigrid tuning profile selected before explicit overrides. */ export type SmokeMultigridPreset = 'quality' | 'balanced'; /** Resolution policy used for the turbulence field. */ export type SmokeTurbulenceMode = 'low-resolution' | 'full-resolution'; /** Dispatch strategy used for queued density and velocity sources. */ export type SmokeSplatMode = 'auto' | 'batched' | 'sparse' | 'sequential'; /** Dispatch path reported for the most recent source upload. */ export type SmokeSplatExecutionPath = Exclude | 'none'; /** Blend operation used by density and velocity splats. */ export type SmokeSplatBlendMode = 'add' | 'inflow'; /** Intentional construction controls for the stable 3D smoke solver. */ export interface SmokeVolumeOptions { /** Simulation-speed multiplier applied to host-frame deltas. */ speedFactor?: number | undefined; /** Cubic velocity-grid resolution. */ simRes?: number | undefined; /** Cubic density-grid resolution. */ dyeRes?: number | undefined; /** Pressure sweeps used by the selected solver. */ iterations?: number | undefined; /** Pressure projection algorithm. */ pressureSolver?: SmokePressureSolver | undefined; /** Coherent starting profile for multigrid projection. */ multigridPreset?: SmokeMultigridPreset | undefined; /** V-cycles submitted by each multigrid pressure solve. */ multigridCycles?: number | undefined; /** Density retained by one reference simulation interval. */ densityDissipation?: number | undefined; /** Temperature retained by one reference simulation interval. */ temperatureDissipation?: number | undefined; /** Density diffusion strength. */ densityDiffusion?: number | undefined; /** MacCormack density-correction strength. */ densityAdvectionCorrection?: number | undefined; /** Velocity retained by one reference simulation interval. */ velocityDissipation?: number | undefined; /** Pressure retained between solves. */ pressureDissipation?: number | undefined; /** Vorticity-confinement strength. */ curlStrength?: number | undefined; /** Procedural turbulence amplitude. */ turbulenceStrength?: number | undefined; /** Procedural turbulence spatial frequency. */ turbulenceFrequency?: number | undefined; /** Procedural turbulence animation speed. */ turbulenceSpeed?: number | undefined; /** Number of turbulence noise octaves. */ turbulenceOctaves?: number | undefined; /** Resolution policy for procedural turbulence. */ turbulenceMode?: SmokeTurbulenceMode | undefined; /** Number of solver steps between turbulence-field refreshes. */ turbulenceUpdateInterval?: number | undefined; /** Maximum number of splat sources accepted per submission. */ maxSplatSources?: number | undefined; /** Source dispatch strategy. */ splatMode?: SmokeSplatMode | undefined; /** Buoyancy acceleration applied to hot smoke. */ buoyancyStrength?: number | undefined; /** World-space buoyancy direction. */ buoyancyDirection?: Vector3 | undefined; /** Density contribution that opposes thermal buoyancy. */ densityWeight?: number | undefined; /** Whether box-domain boundary conditions are enabled. */ useBoundaries?: boolean | undefined; /** Whether the occupancy acceleration texture is maintained. */ enableOccupancyCache?: boolean | undefined; /** Whether cached light optical depth is maintained. */ enableLightOpticalDepthCache?: boolean | undefined; /** Cubic resolution of the cached light field. */ lightRes?: number | undefined; /** Integration steps used by cached light optical depth. */ lightSteps?: number | undefined; /** World-space direction toward the primary light. */ lightDirection?: Vector3 | undefined; } /** Options for one world-space smoke injection. */ export interface SmokeSplatOptions { /** Temperature injected with density; defaults to the density amount. */ temperatureAmount?: number | undefined; /** Velocity blend operation. */ velocityMode?: SmokeSplatBlendMode | undefined; /** Velocity interpolation weight used by `inflow` mode. */ velocityBlend?: number | undefined; /** Density blend operation. */ densityMode?: SmokeSplatBlendMode | undefined; /** Density interpolation weight used by `inflow` mode. */ densityBlend?: number | undefined; /** Source radius in normalized volume coordinates. */ radius?: number | undefined; } /** Statistics for the splat stage of the most recent smoke step. */ export interface SmokeSplatStats { /** Number of queued sources consumed by the step. */ readonly sourceCount: number; /** Dispatch path selected for those sources. */ readonly path: SmokeSplatExecutionPath; /** Approximate number of voxels touched by sparse dispatch. */ readonly touchedVoxelEstimate: number; /** CPU time spent preparing and submitting sources, in milliseconds. */ readonly cpuSubmissionMs: number; /** Compute dispatches submitted for sources. */ readonly dispatches: number; /** Renderer compute submissions used for sources. */ readonly submissions: number; /** GPU copies requested while uploading sources. */ readonly copies: number; /** Bytes uploaded for source data. */ readonly uploadBytes: number; /** CPU upload time, in milliseconds. */ readonly uploadMs: number; } /** Read-only scheduling snapshot for the most recent smoke step. */ export interface SmokeStepStats { /** Total compute dispatches submitted by the step. */ readonly dispatches: number; /** Total renderer compute submissions used by the step. */ readonly submissions: number; /** Source-stage statistics. */ readonly sources: Readonly; /** Turbulence resolution policy used by the step. */ readonly turbulenceMode: SmokeTurbulenceMode; /** Cubic resolution of the turbulence field. */ readonly turbulenceResolution: number; /** Whether the step rebuilt its turbulence field. */ readonly turbulenceFieldRefreshed?: boolean | undefined; /** Pressure solver used by the step. */ readonly pressureSolver: SmokePressureSolver; /** Multigrid profile, or `null` for SOR projection. */ readonly multigridPreset?: SmokeMultigridPreset | null | undefined; /** Aggregate pressure relaxation sweeps. */ readonly pressureSweeps: number; /** Finest-grid pressure relaxation sweeps. */ readonly finePressureSweeps: number; /** Coarser-grid pressure relaxation sweeps. */ readonly coarsePressureSweeps: number; /** Multigrid V-cycles submitted by the step. */ readonly multigridCycles: number; /** Multigrid levels visited by the step. */ readonly multigridLevels: number; } /** Render-cache refresh policy for a smoke step or explicit refresh. */ export interface SmokeRenderCacheOptions { /** Refresh or maintain the occupancy acceleration texture. */ occupancy?: boolean | undefined; /** Refresh or maintain the light optical-depth texture. */ lightOpticalDepth?: boolean | undefined; } /** Per-frame smoke scheduling controls. */ export interface SmokeStepOptions { /** Refresh all enabled caches, select individual caches, or skip refreshes. */ refreshRenderCaches?: boolean | SmokeRenderCacheOptions | undefined; } /** Multigrid overrides accepted when changing pressure solvers. */ export interface SmokePressureSolverOptions { /** Coherent multigrid starting profile. */ preset?: SmokeMultigridPreset | undefined; /** V-cycles submitted per pressure solve. */ cycles?: number | undefined; /** Relaxation sweeps before residual restriction. */ preSmooth?: number | undefined; /** Relaxation sweeps after correction prolongation. */ postSmooth?: number | undefined; /** Relaxation sweeps at the coarsest level. */ coarseIterations?: number | undefined; /** Smallest allowed multigrid resolution. */ minResolution?: number | undefined; /** Maximum number of multigrid levels. */ maxLevels?: number | undefined; /** Scale applied to fine-grid correction. */ correctionScale?: number | undefined; /** Scale applied to recursive coarse-grid correction. */ recursiveCorrectionScale?: number | undefined; /** Allow the solver to adjust correction scales from the selected preset. */ autoTune?: boolean | undefined; } /** Domain-object binding controls. */ export interface SmokeDomainBindingOptions { /** Re-read the object's world matrix before every simulation step. */ autoUpdate?: boolean | undefined; } interface SmokeVolumeConstructor { /** Create a stable smoke simulation with optional solver and resolution controls. */ new (options?: SmokeVolumeOptions): SmokeVolume; readonly prototype: SmokeVolume; } /** * Stable 3D smoke-solver facade. The solver owns every returned storage * texture. Construct it before the render material, call {@link SmokeVolume.initialize} * once, queue world splats, call {@link SmokeVolume.step}, and only then render * consumers of its textures. Invalid resolutions, unsupported pressure choices, * missing renderer capabilities, and use after resource teardown can throw. * Dispose the material before this solver, then call {@link SmokeVolume.dispose} * after all texture consumers are detached. */ export interface SmokeVolume { /** Cubic velocity-grid resolution fixed at construction. */ readonly simRes: number; /** Cubic density-grid resolution fixed at construction. */ readonly dyeRes: number; /** Queue a density, temperature, and optional velocity source in world space. */ addWorldSplat(worldPosition: Vector3, worldVelocity?: Vector3 | null, densityAmount?: number, options?: SmokeSplatOptions): this; /** Bind the unit volume to a caller-owned object's world transform. */ setDomainFromObject(object: Object3D, options?: SmokeDomainBindingOptions): this; /** Copy an explicit world transform into the volume mapping. */ setDomainTransform(matrixWorld: Matrix4): this; /** Refresh an auto-bound domain after its object transform changes. */ syncDomainTransform(force?: boolean): this; /** Copy the world-space direction used by cached smoke lighting. */ setLightDirection(direction: Vector3): this; /** Copy the world-space direction used for thermal buoyancy. */ setBuoyancyDirection(direction: Vector3): this; /** Allocate and clear renderer-backed state before the first simulation step. */ initialize(renderer: Renderer): this; /** Change pressure projection for later steps; invalid settings throw. */ setPressureSolver(solver: SmokePressureSolver, options?: SmokePressureSolverOptions): this; /** Return an immutable view of the most recently completed step statistics. */ getLastStepStats(): Readonly; /** Rebuild selected render caches after simulation and before rendering. */ refreshRenderCaches(renderer: Renderer, options?: SmokeRenderCacheOptions): this; /** Submit one simulation step after sources and transforms are updated. */ step(renderer: Renderer, dt?: number, options?: SmokeStepOptions): this; /** Solver-owned density and temperature texture sampled by smoke materials. */ getDensityTexture3D(): Storage3DTexture; /** Solver-owned velocity texture sampled by flow-detail materials. */ getVelocityTexture3D(): Storage3DTexture; /** Solver-owned curl texture sampled by flow-detail materials. */ getCurlTexture3D(): Storage3DTexture; /** Solver-owned occupancy texture used for empty-space skipping. */ getOccupancyTexture3D(): Storage3DTexture; /** Copy the current occupancy-grid dimensions into a caller-owned vector. */ getOccupancyGridSize(target?: Vector3): Vector3; /** Solver-owned cached light optical-depth texture. */ getLightOpticalDepthTexture3D(): Storage3DTexture; /** Release all solver-owned textures and compute resources after consumers detach. */ dispose(): void; } /** Runtime-identical constructor for the narrow stable smoke-volume facade. */ export declare const SmokeVolume: SmokeVolumeConstructor; /** Premultiplied-alpha policy used by the smoke material. */ export type VolumeSmokeOutputMode = 'safe-premultiplied' | 'unclamped-hdr'; /** Borrowed texture or TSL node accepted as a smoke-volume texture input. */ export type VolumeSmokeTextureInput = Texture | Node; /** Construction controls for the stable smoke node material. */ export interface VolumeSmokeNodeMaterialOptions { /** Required borrowed density and temperature texture. */ densityTexture: VolumeSmokeTextureInput; /** Borrowed velocity texture required when flow detail is enabled. */ velocityTexture?: VolumeSmokeTextureInput | null | undefined; /** Borrowed curl texture required when flow detail is enabled. */ curlTexture?: VolumeSmokeTextureInput | null | undefined; /** Borrowed pressure texture required for diagnostic lighting. */ pressureTexture?: VolumeSmokeTextureInput | null | undefined; /** Borrowed divergence texture required for diagnostic lighting. */ divergenceTexture?: VolumeSmokeTextureInput | null | undefined; /** Borrowed occupancy texture required for macrocell skipping. */ occupancyTexture?: VolumeSmokeTextureInput | null | undefined; /** Borrowed cached-light texture. */ lightOpticalDepthTexture?: VolumeSmokeTextureInput | null | undefined; /** Borrowed scene-depth node used to stop rays at opaque geometry. */ sceneDepthNode?: Node | null | undefined; /** Enable velocity and curl detail; the matching textures become required. */ useFlowDetail?: boolean | undefined; /** Enable procedural high-frequency density detail. */ useHighFrequencyDetail?: boolean | undefined; /** Enable pressure and divergence diagnostic lighting. */ useDiagnosticLighting?: boolean | undefined; /** Enable occupancy-guided empty-space skipping. */ useMacrocellSkipping?: boolean | undefined; /** Premultiplied-alpha output policy. */ outputMode?: VolumeSmokeOutputMode | undefined; /** Occupancy-grid dimensions used for macrocell traversal. */ occupancyGridSize?: Vector3 | undefined; /** Density threshold below which an occupancy cell is skipped. */ occupancyThreshold?: number | undefined; /** Density-grid texel dimensions used for finite differences. */ dyeTexelSize?: Vector3 | undefined; /** Primary raymarch sample count. */ steps?: number | undefined; /** World-space direction toward the primary light. */ lightDir?: Vector3 | undefined; /** Base smoke color. */ baseColor?: import('three/webgpu').Color | undefined; /** Upper-hemisphere ambient color. */ skyColor?: import('three/webgpu').Color | undefined; /** Lower-hemisphere ambient color. */ groundColor?: import('three/webgpu').Color | undefined; /** Primary directional-light color. */ lightColor?: import('three/webgpu').Color | undefined; /** Density-to-opacity multiplier. */ densityBoost?: number | undefined; /** Beer-Lambert absorption coefficient. */ absorption?: number | undefined; /** Henyey-Greenstein forward anisotropy. */ anisotropy?: number | undefined; /** Shadow-ray sample count. */ shadowSteps?: number | undefined; /** Strength of volume self-shadowing. */ shadowIntensity?: number | undefined; /** Temporal ray offset in normalized step units. */ temporalJitter?: number | undefined; /** Monotonic frame index used by temporal jitter. */ temporalFrame?: number | undefined; /** Procedural detail amplitude. */ detailNoiseStrength?: number | undefined; /** Procedural detail spatial frequency. */ detailNoiseScale?: number | undefined; /** Procedural detail animation time. */ detailTime?: number | undefined; /** Low-temperature fire color. */ fireColor?: import('three/webgpu').Color | undefined; /** High-temperature fire color. */ fireColorHot?: import('three/webgpu').Color | undefined; /** Emissive fire intensity; zero disables emission. */ fireIntensity?: number | undefined; } /** Compile-time smoke shader variants rebuilt together. */ export interface VolumeSmokeShaderOptions { /** Enable velocity and curl flow detail. */ useFlowDetail?: boolean | undefined; /** Enable procedural high-frequency density detail. */ useHighFrequencyDetail?: boolean | undefined; /** Enable pressure and divergence diagnostic lighting. */ useDiagnosticLighting?: boolean | undefined; /** Enable occupancy-guided empty-space skipping. */ useMacrocellSkipping?: boolean | undefined; /** Premultiplied-alpha output policy. */ outputMode?: VolumeSmokeOutputMode | undefined; } /** Borrowed texture replacements for an existing smoke material. */ export interface VolumeSmokeTextureOptions { /** Replacement density texture; `null` is invalid while rendering. */ densityTexture?: VolumeSmokeTextureInput | null | undefined; /** Replacement velocity texture. */ velocityTexture?: VolumeSmokeTextureInput | null | undefined; /** Replacement curl texture. */ curlTexture?: VolumeSmokeTextureInput | null | undefined; /** Replacement pressure texture. */ pressureTexture?: VolumeSmokeTextureInput | null | undefined; /** Replacement divergence texture. */ divergenceTexture?: VolumeSmokeTextureInput | null | undefined; /** Replacement occupancy texture. */ occupancyTexture?: VolumeSmokeTextureInput | null | undefined; /** Replacement cached light optical-depth texture. */ lightOpticalDepthTexture?: VolumeSmokeTextureInput | null | undefined; } /** Raw borrowed texture values synchronized into existing material nodes. */ export interface VolumeSmokeTextureSyncOptions { /** Current solver-owned density texture. */ densityTexture?: Texture | null | undefined; /** Current solver-owned velocity texture. */ velocityTexture?: Texture | null | undefined; /** Current solver-owned curl texture. */ curlTexture?: Texture | null | undefined; /** Current solver-owned pressure texture. */ pressureTexture?: Texture | null | undefined; /** Current solver-owned divergence texture. */ divergenceTexture?: Texture | null | undefined; /** Current solver-owned occupancy texture. */ occupancyTexture?: Texture | null | undefined; /** Current solver-owned cached light texture. */ lightOpticalDepthTexture?: Texture | null | undefined; } interface VolumeSmokeNodeMaterialConstructor { /** Create a volume material for a smoke simulation and optional texture bindings. */ new (options: VolumeSmokeNodeMaterialOptions): VolumeSmokeNodeMaterial; readonly prototype: VolumeSmokeNodeMaterial; } /** * Three.js node-material facade for raymarching a {@link SmokeVolume}. All input * textures and scene nodes are borrowed; the material owns only its generated * shader graph and renderer-side material state. Synchronize volume textures * after the solver swaps or rebuilds them, render only after the simulation and * cache refresh complete, and call inherited `dispose()` before disposing the * volume. Missing textures required by an enabled shader variant throw. */ export interface VolumeSmokeNodeMaterial extends NodeMaterial { /** Restore this material's generated premultiplied smoke output node. */ useSmokeOutput(): this; /** Replace the borrowed scene-depth node used for opaque intersections. */ setSceneDepthNode(sceneDepthNode: Node | null): this; /** Rebuild compile-time shader variants; required textures are validated. */ setShaderVariants(options?: VolumeSmokeShaderOptions): this; /** Select safe premultiplied output or unclamped HDR accumulation. */ setOutputMode(outputMode: VolumeSmokeOutputMode): this; /** Toggle occupancy skipping and optionally update the occupancy-grid dimensions. */ setMacrocellSkipping(enabled: boolean, occupancyGridSize?: Vector3 | null): this; /** Replace borrowed texture nodes; active shader variants validate dependencies. */ setVolumeTextures(options?: VolumeSmokeTextureOptions): void; /** Synchronize raw texture values without rebuilding the material graph. */ syncVolumeTextures(options?: VolumeSmokeTextureSyncOptions): this; } /** Runtime-identical constructor for the narrow stable smoke-material facade. */ export declare const VolumeSmokeNodeMaterial: VolumeSmokeNodeMaterialConstructor; /** Pointer input accepted by the compact 2D smoke-node factory. */ export type SmokeNodePointerInput = Vector2 | null; /** * TSL node returned by {@link smoke}. The node owns its simulation textures and * automatically submits its per-frame update before dependent rendering. Its * scalar setters are safe between frames. Call {@link SmokeNodeResult.dispose} * after detaching the node from every material. */ export interface SmokeNodeResult extends Node { /** Change the simulation-time multiplier used by later automatic updates. */ setSpeedFactor(value: number): this; /** Change pressure-projection iterations used by later automatic updates. */ setPressureIterations(iterations: number): this; /** Change pointer-motion amplification used by later automatic updates. */ setPointerScale(scale: number): this; /** Release factory-owned render targets, storage textures, and helper materials. */ dispose(): void; } /** * Create the runtime-identical compact 2D smoke TSL node. Invalid resolutions or * unsupported renderer capabilities can fail during setup or the first frame. */ export declare const smoke: (pointer?: SmokeNodePointerInput | undefined, simRes?: number, dyeRes?: number, iterations?: number, densityDissipation?: number, velocityDissipation?: number, pressureDissipation?: number, curlStrength?: number, pressureFactor?: number, radius?: number, useBoundaries?: boolean, pointerScale?: number, neighborStride?: number, speedFactor?: number) => SmokeNodeResult; /** Stable smoke compositing and low-level TSL extensions. */ export { VolumeSmokeRenderCompositor } from './Materials/VolumeSmokeRenderCompositor.js'; export { smokeRTT } from './TSL/SmokeNodeRTT.js'; export { volumeSmokeShadow } from './TSL/volumeSmokeShadow.js';