kuwahara
kuwahara(originalTextureNode : Node, tensorTextureNode : Node, options : KuwaharaOptions) : Node<vec4>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
- Selects sector with minimum variance for painterly effect
- 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
stepSizefor sparse sampling (large radius with similar sample count) - Reduce
sectorsorangleStepsfor speed - Enable
useSimpleWeightfor 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)
Parameters
originalTextureNodeNodeSource texture to filter.
tensorTextureNodeNodeStructure tensor texture (from
structureTensor()).optionsoptionalKuwaharaOptionsOptional parameters.
Default is
Default is
{}.Returns
Node<vec4> — Filtered painterly color.See also
Example
import { kuwahara, structureTensor } from '@three-blocks/core';
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
});