When attempting to compute the gradient noise derivatives I've seen the use of a function named "hash" and I don't understand its purpose (nor why they have commented that it should be replaced by something better): link
Code:
vec2 hash( in vec2 x ) // replace this by something better
{
const vec2 k = vec2( 0.3183099, 0.3678794 );
x = x*k + k.yx;
return -1.0 + 2.0*fract( 16.0 * k*fract( x.x*x.y*(x.x+x.y)) );
}
// return gradient noise (in x) and its derivatives (in yz)
vec3 noised( in vec2 p )
{
vec2 i = floor( p );
vec2 f = fract( p );
#if 1
// quintic interpolation
vec2 u = fff(f(f6.0-15.0)+10.0);
vec2 du = 30.0ff(f(f-2.0)+1.0);
#else
// cubic interpolation
vec2 u = ff(3.0-2.0f);
vec2 du = 6.0f(1.0-f);
#endif
vec2 ga = hash( i + vec2(0.0,0.0) );
vec2 gb = hash( i + vec2(1.0,0.0) );
vec2 gc = hash( i + vec2(0.0,1.0) );
vec2 gd = hash( i + vec2(1.0,1.0) );
float va = dot( ga, f - vec2(0.0,0.0) );
float vb = dot( gb, f - vec2(1.0,0.0) );
float vc = dot( gc, f - vec2(0.0,1.0) );
float vd = dot( gd, f - vec2(1.0,1.0) );
return vec3( va + u.x(vb-va) + u.y(vc-va) + u.xu.y(va-vb-vc+vd), // value
ga + u.x(gb-ga) + u.y(gc-ga) + u.xu.y(ga-gb-gc+gd) + // derivatives
du * (u.yx*(va-vb-vc+vd) + vec2(vb,vc) - va));
}
// -----------------------------------------------
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 p = (2.0*fragCoord-iResolution.xy)/iResolution.y;
vec3 n = noised( 8.0*p + iTime*4.0 );
vec3 col = 0.5 + 0.5*((p.x>0.0) ? n.yzx : n.xxx);
fragColor = vec4( col, 1.0 );
}