kuwahara

@three-blocks/coreWebGPUWebGL
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 stepSize for sparse sampling (large radius with similar sample count)
  • Reduce sectors or angleSteps for speed
  • 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)
Parameters
originalTextureNodeNode
Source texture to filter.
tensorTextureNodeNode
Structure tensor texture (from structureTensor()).
optionsoptionalKuwaharaOptions
Optional parameters.
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
});