Created
December 5, 2024 20:16
-
-
Save akella/5688e1c770160213b925e2f566070c23 to your computer and use it in GitHub Desktop.
simplex TSL noise
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// from https://mameson.com/experiment/glsl/proven_2/proven_2.html | |
function mm_hash12( iw){ //★ x, y とも 0〜2,000,000 の整数入力。 | |
const w = iw.mul( 0.000303) //★ 入力の 6 ケタとも活かす。 | |
.add( fract( iw.mul( 0.707))); //★ 入力の上位ケタは捨てて下位ケタ拾い上げ。 | |
const a = w.x.add( w.y.mul( 0.3)); //★ 斜めにする。 | |
//★ 最近気に入っているフェイク sin。 | |
a.assign( fract( a)); | |
a.assign( a.sub( a.mul( a))); | |
return fract( a.mul( 937652.481)); | |
} | |
function rnd_dir( ip){ | |
return fract( vec3( 1, 99, 9999).mul( mm_hash12( ip.xy.add( ip.zz.mul( 100))))).sub( 0.5); | |
} | |
function simplex3d( p){ | |
const ip = floor( p.add( dot( vec3( 0.333333), p))); | |
const p0 = p.sub( ip).add( dot( vec3( 0.166666), ip)); | |
const f = step( p0.yzx, p0); | |
const ff = f.mul( f.zxy); | |
const v1 = f.sub( ff); | |
const v2 = ff.sub( f.zxy).add( 1); | |
const p1 = p0.sub( v1).add( 0.166666); | |
const p2 = p0.sub( v2).add( 0.333333); | |
const p3 = p0.sub( 1).add( 0.5); | |
const d = max( negate( vec4( | |
dot( p0, p0), | |
dot( p1, p1), | |
dot( p2, p2), | |
dot( p3, p3) | |
)).add( 0.58), 0); | |
d.assign( d.mul( d)); | |
d.assign( d.mul( d)); | |
return dot( vec4( | |
dot( p0, rnd_dir( ip)), | |
dot( p1, rnd_dir( ip.add( v1))), | |
dot( p2, rnd_dir( ip.add( v2))), | |
dot( p3, rnd_dir( ip.add( 1))) | |
), d).mul( 40).add( 0.5); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment