import type { TSLNode, TSLNodeFactory, TSLVec4Node } from '../types/tsl.cjs'; /** Quality and appearance controls for the stable Kuwahara painterly filter. */ export interface KuwaharaOptions { /** Filter radius in pixels. */ radius?: number; /** Number of angular sectors sampled around each pixel. */ sectors?: number; /** Number of discrete angle samples per sector. */ angleSteps?: number; /** Pixel stride between spatial samples. */ stepSize?: number; /** Whether to use the lower-cost flat spatial weighting function. */ useSimpleWeight?: boolean; /** Whether structure-tensor orientation should guide the filter. */ useTensor?: boolean; /** Stroke elongation along coherent image edges. */ anisotropy?: number; /** Mix of the untouched center color retained near coherent edges. */ edgePreservation?: number; /** Soft transition amount between the two lowest-variance sectors. */ sectorBlend?: number; /** Rejection strength for noisier candidate sectors. */ varianceSensitivity?: number; /** Color-boundary rejection strength, or zero to disable range weighting. */ rangeSensitivity?: number; /** Whether to output diagnostic sector, coherence, and variance channels. */ debug?: boolean; } export interface KuwaharaNodeFactory extends TSLNodeFactory<[ originalTextureNode: TSLNode, tensorTextureNode: TSLNode, options?: KuwaharaOptions ], TSLVec4Node> { setParameterLength(length: number): this; } /** * Generalized anisotropic Kuwahara painterly filter with multi-sector sampling. * * **Algorithm** * - Evaluates angular sectors around each pixel * - Structure tensor drives dominant orientation, coherence, and anisotropic scaling * - Optional color-range weighting prevents pigment from bleeding across high-contrast boundaries * - Soft-selects between the two lowest-variance sectors, avoiding cross-edge blur * - More sectors/angle steps = smoother results but slower performance * - Using the structure tensor aligns the brush with image edges (high coherence) and reduces smearing across strong gradients; disabling it falls back to isotropic blurring. * * **Performance Tuning** * - Increase `stepSize` for sparse sampling (large radius with similar sample count) * - Reduce `sectors` or `angleSteps` for speed * - Reduce `sectorBlend` for harder region boundaries; increase it for softer transitions between the two cleanest regions * - Increase `rangeSensitivity` to prevent color bleed across high-contrast silhouettes * - Enable `useSimpleWeight` for flatter look with fewer math ops * * **Debug Output** * - R: Selected sector id (0..1) * - G: Edge coherence from structure tensor * - B: Normalized variance (higher = noisier) * * ```js * import { kuwahara } from 'three-blocks'; * import { structureTensor } from 'three-blocks/experimental/core-tsl-effects'; * import { pass } from 'three/tsl'; * * const scenePass = pass(scene, camera); * const tensorPass = structureTensor(scenePass); * * const painterly = kuwahara(scenePass, tensorPass, { * radius: 6, * sectors: 8, * angleSteps: 3, * stepSize: 1 * }); * ``` * * @function kuwahara * @category TSL * @tags WebGPU, WebGL * @tsl * @param {Node} originalTextureNode Source texture to filter. * @param {Node} tensorTextureNode Structure tensor texture (from `structureTensor()`). * @param {Object} [options={}] Optional parameters. * @param {number} [options.radius=6] Filter radius in pixels (brush size). * @param {number} [options.sectors=8] Number of angular sectors (more = smoother, slower). * @param {number} [options.angleSteps=3] Discrete angle steps per sector (angular smoothness). * @param {boolean} [options.useSimpleWeight=false] Use flat weighting instead of smooth polynomial falloff. * @param {number} [options.stepSize=1] Sparse sampling step (1=dense, >1=sparser/faster). * @param {boolean} [options.useTensor=true] Use structure tensor for orientation; when false, falls back to isotropic filtering. * @param {number} [options.anisotropy=0.6] Stroke elongation along coherent edges (0=isotropic, 1=strongly directional). * @param {number} [options.edgePreservation=0.05] Untouched center-color mix at coherent edges (0=fully filtered, 1=fully raw at maximum coherence). * @param {number} [options.sectorBlend=0.55] Soft transition amount between the two lowest-variance sectors. * @param {number} [options.varianceSensitivity=32] Rejection strength when the second-lowest sector is substantially noisier than the winner. * @param {number} [options.rangeSensitivity=0] Color-boundary rejection strength (0 disables range weighting). * @param {boolean} [options.debug=false] Debug output (R=selected sector, G=edge coherence, B=variance). * @returns {Node.} Filtered painterly color. * @see structureTensor */ export declare const kuwahara: KuwaharaNodeFactory;