sample
sample
Encapsulates a custom sampling algorithm (e.g., blur, distortion) into a reusable node to create a custom 'sampler'.
Core Advantages
It allows you to encapsulate complex sampling logic (like multi-tapping or procedural warping) to create reusable, composable custom sampler nodes, which greatly simplifies the node graph and improves code modularity.
Common Uses
Custom texture filtering (e.g., blur)
Domain warping for procedural effects
Implementing tri-planar mapping
How to adjust
Adjusted by modifying the callback function used to create it. You can change the internal algorithm (e.g., add more sample taps for a stronger blur), alter the math operations (e.g., multiply colors instead of adding), or introduce dynamic nodes (like `timer`) to create animated effects.
Code Examples
1// Create a custom 4-tap blur sampler
2const blurSampler = sample( ( uvNode ) => {
3
4 const c1 = textureNode.uv( uvNode.add( vec2( -0.01, -0.01 ) ) );
5 const c2 = textureNode.uv( uvNode.add( vec2( 0.01, -0.01 ) ) );
6 const c3 = textureNode.uv( uvNode.add( vec2( -0.01, 0.01 ) ) );
7 const c4 = textureNode.uv( uvNode.add( vec2( 0.01, 0.01 ) ) );
8
9 // Return the averaged color
10 return add( c1, c2, c3, c4 ).mul( 0.25 );
11
12} );