/** * `@voluma/vlam/effects` - optional, tree-shakeable effects built on the M7 * {@link SplatModifier} contract. Import only what you use; nothing here is * pulled into the core renderer bundle. * * - {@link sdfEffects}: a declarative sphere/box/cylinder shape list evaluated * in-shader from a bounded uniform array (a fixed unroll over `maxShapes` * slots, gated by the live count) - add/move/remove shapes is data-only * (no pipeline recompile), on WebGPU and the WebGL2 fallback alike (M7.4). * The kinds mirror the CPU selection volumes (`createSelectionVolume` on * `@voluma/vlam/selection`), so a host can highlight exactly what a * selection would take. * - {@link lightingPreset} / {@link revealPreset}: small reference presets, * starting points rather than a framework (M7.5). * - {@link worldWarpPreset}: camera-centered sphere wrap (planet / bowl). * - {@link lodLevelDebugModifier}: false-color view of a streamed mesh's * resident LOD levels. * - {@link renderSplatDepth}: alpha-tested splat depth into a render target, * for fog, depth of field and other post effects. * - {@link depthOfFieldPreset}: stylized modifier-based depth-of-field (M13). * For physically-modeled camera DoF prefer the core * {@link SplatMesh.setDepthOfField} / `UnifiedSplatMesh.setDepthOfField` * path - this preset is the soft/approximate alternative built purely on * the modifier hook. * * Every preset here reads positions from `ctx.localCenter` - mesh-local space, * which inside a `MergedSplatMesh` is the splat's **placed** position. So a shape or * a reveal spans every source as one scene instead of travelling with a moved * one; see `docs/guide/effects-and-modifiers.md` for what that looks like, and * `ctx.sourceCenter` for the opposite behaviour. * * See `docs/guide/effects-and-modifiers.md`. */ import * as THREE from 'three/webgpu'; import type { SplatModifier } from '../core/splat-modifier'; import { LOD_LEVEL_CHANNEL } from '../core/lod-level-channel'; export { LOD_LEVEL_CHANNEL }; /** * A signed-distance primitive kind. `cylinder` is capped and runs along the * shape-local Y axis (rotate it with {@link SdfShape.rotation}). */ export type SdfShapeKind = 'sphere' | 'box' | 'cylinder'; /** * What a shape does to the splats it covers: * - `tint` - blend the splat color toward the shape color. * - `desaturate` - blend the splat color toward its luminance. * - `hide` - fade the splat out (soft cutaway). * - `rim` - tint only a band around the shape's surface. */ export type SdfMode = 'tint' | 'desaturate' | 'hide' | 'rim'; /** One SDF shape in a {@link sdfEffects} list. All spaces are mesh-local. */ export interface SdfShape { /** * Shape-local → mesh-local affine placement. Mutually exclusive with center/rotation. * Must be finite and invertible; setShapes snapshots it, so later edits require setShapes. */ transform?: THREE.Matrix4; kind: SdfShapeKind; /** Shape center, mesh-local. Default `[0, 0, 0]`. */ center?: readonly [number, number, number]; /** * Sphere/cylinder radius. Required for `kind: 'sphere'` and * `kind: 'cylinder'`; must be positive - {@link SdfEffect.setShapes} throws * otherwise. */ radius?: number; /** * Cylinder full height along the shape-local Y axis. Required (and only * used) for `kind: 'cylinder'`; must be positive - {@link SdfEffect.setShapes} * throws otherwise. */ height?: number; /** * Box half-extents. Required (and only used) for `kind: 'box'`; every * component must be positive - {@link SdfEffect.setShapes} throws otherwise. */ halfExtents?: readonly [number, number, number]; /** Orientation quaternion `[x, y, z, w]` (boxes and cylinders). Default identity. */ rotation?: readonly [number, number, number, number]; /** Effect color (tint/rim). Default white. */ color?: readonly [number, number, number]; /** Soft-edge width in shape-local units; 0 is a hard edge. Default `0`. */ falloff?: number; /** Invert the test - affect the outside of the shape instead. */ invert?: boolean; /** Effect strength in `[0, 1]`. Default `1`. */ strength?: number; mode: SdfMode; } /** A live SDF effect: one modifier plus a data-only way to update its shapes. */ export interface SdfEffect { /** Attach to `mesh.modifiers`. Built once; updating shapes never recompiles. */ readonly modifier: SplatModifier; /** * Replaces the shape list. Purely a uniform-buffer write, so animating * shape poses/colors/thresholds every frame costs no pipeline recompile. * Shapes beyond {@link maxShapes} are dropped with a one-time warning. * * Throws (before writing anything) if a sphere or cylinder lacks a positive * `radius`, a cylinder lacks a positive `height`, or a box lacks positive * `halfExtents` - a zero-size shape is always a caller bug, never a useful * no-op. */ setShapes(shapes: readonly SdfShape[]): void; /** The compiled-in shape capacity (see {@link sdfEffects} `maxShapes`). */ readonly maxShapes: number; } /** * Builds a {@link SdfEffect} from a declarative shape list. Shapes live in a * bounded uniform array and are tested in-shader against each splat's local * center as a **fixed unroll over all `maxShapes` slots**, each slot gated by * `slot < count` so unused slots contribute nothing. (An in-shader loop is * not viable here - see the TSL varying constraint documented inside the * modifier.) Adding, moving or removing a shape - or changing the count - is * still a pure uniform write with no recompile. Works on WebGPU and the * WebGL2 fallback. * * `maxShapes` is the compiled capacity (default 32). Because every slot is * unrolled into the shader, raising it grows the shader's size and compile * time (and the uniform array; very large values can exceed WebGL2's uniform * limits), so keep it to what a scene needs. * * Shape positions are mesh-local. In a `MergedSplatMesh` that means scene * coordinates - a shape overlapping two sources covers both as one continuous * shape - so place them with `computeSplatBounds()`, which reports the sources * at their current placement. */ export declare function sdfEffects(initialShapes?: readonly SdfShape[], options?: { maxShapes?: number; }): SdfEffect; /** A preset that exposes a live light direction uniform. */ export interface LightingPreset { readonly modifier: SplatModifier; /** * Mesh-local light direction; mutate `.value` to animate (no recompile). * Inside a `MergedSplatMesh` that frame is the scene's, so one direction lights * every source consistently however they are posed. */ readonly direction: { value: THREE.Vector3; }; } /** * Simple per-splat Lambertian shading using the splat's approximate normal * (`ctx.normal`, the least-variance covariance axis). A starting point for * relit product shots - not a lighting rig. Works on both backends. * * In a `MergedSplatMesh` the normal comes from the *placed* covariance, so a source * that rotates relights as it turns. */ export declare function lightingPreset(options?: { direction?: readonly [number, number, number]; ambient?: number; diffuse?: number; }): LightingPreset; /** A live depth-of-field preset: focus plane and aperture are mutable uniforms. */ export interface DepthOfFieldPreset { readonly modifier: SplatModifier; /** World-unit distance to the focal plane; splats there stay sharp. Mutate * `.value` to rack focus (no recompile). Must stay positive. */ readonly focusDistance: { value: number; }; /** Blur strength (aperture-like); 0 is no blur. Mutate `.value`. */ readonly aperture: { value: number; }; } /** * Depth-of-field on the {@link SplatModifier} hook - **stylized / soft** path * (M13). Prefer {@link SplatMesh.setDepthOfField} / the core projected-2D * aperture model for camera DoF (isotropic screen-space CoC with √det opacity). * * A splat's circle of confusion grows with how far its view-space depth * sits from `focusDistance`; the modifier blurs it by enlarging it * (`scale = 1 + coc`) and, because the material scales the projected covariance * by `scale²`, divides opacity by `scale²` so the widened splat conserves its * integrated mass instead of over-brightening. Focus and aperture are live * uniforms, so racking focus every frame costs no recompile. Pure TSL - works * on WebGPU and the WebGL2 fallback. * * This is an *approximate* DoF: `scale` is a uniform 3D-covariance multiplier, * so the blur enlarges the splat's own (possibly anisotropic) footprint rather * than adding a truly isotropic screen-space disc. The physically exact aperture * model adds `coc²·I` to the *projected 2D* covariance with the same √(det) * opacity conservation the antialias filter uses - that path is * `SplatMesh.setDepthOfField` / `UnifiedSplatMesh.setDepthOfField` * (see `docs/guide/effects-and-modifiers.md`, M13). * * Opacity conservation is exact only with `antialias` on: without it, the * fixed 0.3-px dilation dominates sub-pixel splats, so strong blur *dims* * distant splats (their footprint barely grows while alpha still falls by * 1/scale²) rather than blurring them. */ export declare function depthOfFieldPreset(options?: { focusDistance?: number; aperture?: number; maxBlur?: number; }): DepthOfFieldPreset; /** A preset that exposes a reveal `progress` uniform in `[0, 1]`. */ export interface RevealPreset { readonly modifier: SplatModifier; /** Reveal progress; 0 hides everything, 1 shows everything. */ readonly progress: { value: number; }; } /** * Time-driven dissolve/reveal. A value-noise field over the splat's local * position is thresholded against `progress`: splats whose noise is below the * threshold are shown, with a soft alpha edge. The noise is a `wgslFn` chunk - * the M7 escape hatch - so this preset is **WebGPU-only** (see the fallback * notes); force WebGL2 and it will not compile. * * The field is anchored to the mesh, so in a `MergedSplatMesh` a moved source * reveals in step with whatever it now sits beside (and the pattern slides * across it as it travels) rather than carrying its own schedule around. */ export declare function revealPreset(options?: { frequency?: number; edge?: number; }): RevealPreset; /** A live world-warp preset: signed intensity and radius are mutable uniforms. */ export interface WorldWarpPreset { readonly modifier: SplatModifier; /** * Signed warp amount in `[-1, 1]`. Positive wraps the street *down* so you * walk on top of the sphere (tiny planet); negative wraps it *up* so you * stand in the bowl (Inception fold). `0` is identity. Mutate `.value` to * animate (no recompile). */ readonly intensity: { value: number; }; /** * Distance at which the wrap becomes strong. Nearby splats (`depth ≪ * radius`) stay put so walk/fly controls still read as moving through the * unwarped near field. Must stay positive. Mutate `.value`. */ readonly radius: { value: number; }; } /** * Camera-centered splat warp on the {@link SplatModifier} hook: one signed * `intensity` uniform, two opposite hinges of the same view-space wrap. The * camera is not moved - only splat centers (and their rigid orientation) * change, so WASD / orbit stay as they are. * * Both sides hinge view-space `(y, z)` around camera +X by * `(π/2) · atan(depth / radius)`: * * - `intensity > 0` - planet: the far street wraps *down* under your feet so * you walk on top of the sphere. * - `intensity < 0` - fold: the far street wraps *up* over your head so you * stand in the bowl. * - `intensity = 0` is identity (`offset = 0`, rotation unchanged). * * The shader mixes each full-strength hinge toward the original position by * `|intensity|`. Orientation follows the orthonormalized Jacobian so * ellipsoids wrap with the surface rather than sliding. Pure TSL - WebGPU * and the WebGL2 fallback. * * Displaced splats keep their **pre-displacement** depth-sort order (the * modifier-stack contract). Extreme warps can composite in the wrong order; * this preset does not re-sort on warped centers. */ export declare function worldWarpPreset(options?: { intensity?: number; radius?: number; }): WorldWarpPreset; /** * Colors each splat by the LOD level its streamed mesh resolved for it: * 0 (finest) red, then orange, yellow, green, and blue for 4 and coarser. * Magenta marks splats no run has written yet. The tint is mixed with the * splat's own color so the scene stays readable. * * The level comes from the {@link LOD_LEVEL_CHANNEL} channel, so enable it * first with `StreamedSplatMesh.setLodLevelDebug(true)`; a mesh without that * channel throws when its material builds. Works on a standalone mesh on both * backends and inside a `UnifiedSplatMesh` (the channel is gathered per * source). The pooled WebGL2 unified draw carries no per-splat channels, so the * modifier cannot build there. * * @param channel - Channel to read, for a host that writes its own levels. */ export declare function lodLevelDebugModifier(channel?: string): SplatModifier; export { renderSplatDepth, type SplatDepthOptions } from './splat-depth';