/** * The TSL material graph behind `SplatMesh`. * * One graph serves both of the mesh's materials: `display` writes premultiplied * color, `pick` encodes linear view depth. They must stay one builder - a pick * that disagreed with the display about projection, covariance or visibility * would return hits for splats the viewer cannot see. * * Everything here runs once, at material build time, and reads only what the * mesh hands it, so these are free functions rather than methods. Note the two * inputs that must be passed live rather than copied: the uniform *node * instances* (display and pick share them, so a frame updates both at once) and * the channels map (a rebuild after `defineChannel` has to see the new entry). * * Internal. Nothing here is exported from `index.ts`. */ import * as THREE from 'three/webgpu'; import { uniformArray } from 'three/tsl'; import type { SplatModifier } from './splat-modifier'; import { foldSplatModifierStack } from './splat-modifier-stack'; import type { SplatPerformanceProfile } from './splat-mesh'; import { type Vec3Uniform, type Vec2Uniform, type FloatUniform, type DisplayColorModifier, type SplatShInputs } from './splat-material-types'; export { asNode, vec3Uniform, boolUniform, type Vec3Uniform, type BoolUniform, type Vec2Uniform, type FloatUniform, type DisplayColorModifier, type SplatShInputs, } from './splat-material-types'; export { isSplatFootprintInFrustum, applyIsotropicCovarianceOverride, DEFAULT_ISOTROPIC_VARIANCE_SCALE, DEFAULT_ISOTROPIC_SCREEN_RADIUS_PX, equalizeProjectedEigenvalues, capProjectedEigenvaluesToScreenRadius, } from './splat-render-math'; export { MAX_SPLAT_RADIUS_PX } from './splat-frustum'; /** The pool data textures a graph samples per splat. */ export interface SplatMaterialTextures { centersTexture: THREE.DataTexture; colorsTexture: THREE.DataTexture; covarianceATexture: THREE.DataTexture; covarianceBTexture: THREE.DataTexture; } /** * Per-source placement inputs for a unified pool ({@link MergedSplatMesh}): the * splat's source id plus the shared array of source matrices. Drives two things * at once - the splat's mesh-local position (`M · poolCenter`, applied before * the modifier stack) and the frame view-dependent SH is evaluated in. */ export interface SplatSourcePlacement { /** Pool-aligned source id channel; unused when {@link sourceId} is given. */ sourceIdTexture?: THREE.DataTexture; /** Caller-built source id, e.g. a per-instance attribute (`unified/pooled`). */ sourceId?: THREE.Node<'int'>; /** Four column vectors per source world matrix. */ columns: ReturnType; } /** * The `mat4 · (poolCenter, 1)` placed center for source id `s`, plus the linear * 3×3 part as a `mat3`, read from the shared column array (three.js * `Matrix4.elements` are column-major, so a column maps to * `elements[k*4 .. k*4+3]`). * * Lives here rather than in `source-transform.ts` because the material graph and * the sorter must place a splat identically. Keeping it on the material side * also avoids a runtime dependency from `source-transform.ts` back into the * material graph. */ export declare function sourceWorldTransform(columns: ReturnType, sourceId: THREE.Node<'int'>, localCenter: THREE.Node<'vec3'>): { worldCenter: THREE.Node<'vec3'>; linear: THREE.Node<'mat3'>; }; /** Coefficients per channel for a band count (0 → none, 3 → 3rd order). */ export declare function shCoefficientCount(bands: number): number; /** * Builds the per-coefficient accessor for whichever SH source the mesh has - * the only part of the SH graph that differs between them. * * `palette` indirects through the splat's codebook label; `packed` reads the * splat's own words straight out of the pool-shaped integer textures and * unpacks them (R: bits 0-10, G: 11-20, B: 21-31, each a unit fraction of its * field, dequantized across the scene's range). The packed texel loads are * hoisted into variables so all 15 coefficients cost at most four fetches. */ export declare function shCoefficientReader(sh: SplatShInputs, textures: { covarianceBTexture: THREE.DataTexture; }, splatTexel: THREE.Node<'ivec2'>): (c: number) => THREE.Node<'vec3'>; /** Evaluates a source's higher-order SH contribution for a local view direction. */ export declare function evaluateSplatSh(sh: SplatShInputs, textures: { covarianceBTexture: THREE.DataTexture; }, splatTexel: THREE.Node<'ivec2'>, direction: THREE.Node<'vec3'>): THREE.Node<'vec3'>; /** Everything the material graph reads, gathered by the mesh. */ export interface SplatMaterialBuildInputs { /** Unculled active list for the independent compute-projection pick draw. */ pickSource?: { indices: THREE.StorageBufferAttribute; capacity: number; }; /** Display-only compute-projected records, indexed by pool slot. */ projected?: { clipCenters: THREE.StorageBufferAttribute; axes: THREE.StorageBufferAttribute; parameters: THREE.StorageBufferAttribute; capacity: number; /** * When true, unpack RGBA8 from `parameters.z` (projector evaluated SH). * When false, the vertex stage uses {@link shFinalColor} or vertex SH. */ packedColor: boolean; }; /** Display-only generated final color; pick always reads the source color. */ shFinalColor?: THREE.Texture; textures: SplatMaterialTextures; sh: SplatShInputs | null; /** * Per-source placement for a unified pool, or `null` for a plain mesh. When * present, a splat's mesh-local center is `M · poolCenter` and SH is * evaluated in the source's own frame. */ sourcePlacement: SplatSourcePlacement | null; /** * Multiplier recovering `.rad` LOD alpha from the stored byte (default 2). * A per-splat node lets one graph draw `.rad` and plain sources together. */ lodAlphaScale?: THREE.Node<'float'>; /** Optional display-only RGB transform; omitted means no extra graph work. */ displayColorModifier: DisplayColorModifier | null; /** * The mesh's uniform *node instances*, not their values: display and pick * share them, so a per-frame write reaches both graphs. */ uniforms: { focal: Vec2Uniform; viewport: Vec2Uniform; /** Conservative cap-aware center bound, shared with the SH cache. */ frustumMargin: Vec2Uniform; localCameraPosition: Vec3Uniform; /** Frontier-cut limit on `own_size / distance` (`foveationMode: 'frontier'`). */ pixelScaleLimit: FloatUniform; /** Internal draw multiplier used to keep a staged stream hidden. */ revealMultiplier?: FloatUniform; /** * Core projected-2D DoF focus plane (world/view units). Live uniform - * racking focus does not rebuild the material. See `depth-of-field.ts`. */ dofFocusDistance: FloatUniform; /** Core DoF aperture; `0` disables. Live uniform. */ dofAperture: FloatUniform; /** * Screen-radius band bounds in px, live so a foveated mesh can follow its * own LOD cut. Whether the band exists at all is still decided at build * time from `settings.minScreenRadiusPx` / `maxScreenRadiusPx`; only the * bounds move. * * They have to move: the band spans one LOD level, so a mesh that refines * its cut to spend spare budget would have exactly that new detail culled * for being smaller than a bound chosen for the coarser cut. */ screenBandMin: FloatUniform; screenBandMax: FloatUniform; }; /** Pick-only uniforms. Required when building in `'pick'` mode. */ pick: { alphaThreshold: FloatUniform; near: FloatUniform; far: FloatUniform; } | null; /** Baked at build time; changing any of these needs a rebuild. */ settings: { maxStdDev: number; /** Screen-space floor on each quad axis, px (0/undefined = off). */ minSplatSizePx?: number; antialias: boolean; /** Classic LCC uses XGRIDS' smaller, always-compensated low-pass. */ projectedFilterProfile: 'default' | 'lcc'; srgbOutput: boolean; performanceProfile: SplatPerformanceProfile; /** Cull splats whose projected radius exceeds this many px (0 = off). */ maxScreenRadiusPx?: number; /** Foveation band lower bound: cull splats *below* this many px (0 = off). */ minScreenRadiusPx?: number; /** * `.rad` foveation cut. `'band'` (default/undefined) uses the screen-radius * band above; `'frontier'` uses Spark's exact per-splat tree cut driven by * `own_size` (from the covariance) and the `parent_size` packed in * `covarianceB.w`. See `docs/formats/rad-notes.md` M14.6. */ foveationMode?: 'band' | 'frontier' | 'page-table'; /** * Cap on a rendered splat's major/minor axis ratio (0/undefined = off). Tames * far-field needle/spike artifacts from very anisotropic Gaussians and * expansion-enlarged coarse LOD nodes. Baked into the material graph. */ maxAspect?: number; /** * Spark's LOD alpha encoding (`.rad`): the stored opacity byte is `alpha/2`, * so the shader multiplies by 2 to recover `alpha ∈ [0,2]`; `alpha > 1` marks * a merged node whose σ-cutoff grows (`+0.7·(remap−1)`) and whose falloff * becomes a super-Gaussian, covering its subtree without scaling covariance. */ lodAlpha?: boolean; /** Drop splats whose on-screen diameter is below this many px (0 = off). */ minPixelSize?: number; /** Drop splats whose opacity × major × minor is below this (0 = off). */ minContribution?: number; }; /** * The mesh's live channel map, not a copy: `defineChannel` adds to it and * then rebuilds, and the graph must resolve names against the new entry. */ channels: ReadonlyMap; modifiers: readonly SplatModifier[]; } /** Which RGB source the display graph uses for a splat's resolved color. */ export type SplatDisplayColorSource = 'cached' | 'packed' | 'vertex-sh' | 'base'; /** * Three-way color selection for the standalone display graph. * Cache wins, then projector-packed RGBA8, then vertex-stage SH, then DC. */ export declare function splatDisplayColorSource(options: { hasCachedColor: boolean; packedProjectedColor: boolean; hasSh: boolean; }): SplatDisplayColorSource; /** * Shared TSL graph for display and pick materials: projection, covariance, * modifiers, visibility, and Gaussian falloff. Display writes premultiplied * color; pick encodes linear view depth into RGB with alpha as the hit flag. * * @param inputs.pick - Required when `mode` is `'pick'`. */ export declare function applySplatMaterialGraph(material: THREE.NodeMaterial, mode: 'display' | 'pick', inputs: SplatMaterialBuildInputs): void; export { foldSplatModifierStack };