Skip to content

Commit

Permalink
added hashBlur
Browse files Browse the repository at this point in the history
  • Loading branch information
sunag committed Oct 10, 2024
1 parent 4efe2d0 commit d849f33
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions examples/jsm/tsl/display/hashBlur.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { float, Fn, vec2, sin, rand, degrees, cos, Loop, vec4 } from 'three/tsl';

// https://www.shadertoy.com/view/4lXXWn

export const hashBlur = /*#__PURE__*/ Fn( ( [ textureNode, bluramount = float( 0.1 ), repeats = float( 45 ) ] ) => {

const draw = ( uv ) => textureNode.uv( uv );

const targetUV = textureNode.uvNode;
const blurred_image = vec4( 0. ).toVar();

//const map = textureNode.value;

Loop( { start: 0., end: repeats, type: 'float' }, ( { i } ) => {

const q = vec2( vec2( cos( degrees( i.div( repeats ).mul( 360. ) ) ), sin( degrees( i.div( repeats ).mul( 360. ) ) ) ).mul( rand( vec2( i, targetUV.x.add( targetUV.y ) ) ).add( bluramount ) ) );
const uv2 = vec2( targetUV.add( q.mul( bluramount ) ) );
blurred_image.addAssign( draw( uv2 ) );

} );

blurred_image.divAssign( repeats );

return blurred_image;

} );

0 comments on commit d849f33

Please sign in to comment.