fbm3D = `
// The MIT License
// Copyright © 2017 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// https://www.youtube.com/c/InigoQuilez
// https://iquilezles.org/
// Computes the analytic derivatives of a 3D Value Noise. This can be used for example to compute normals to a
// 3d rocks based on Value Noise without approximating the gradient by haveing to take central differences (see
// this shader: https://www.shadertoy.com/view/XttSz2)
// Value Noise 2D, Derivatives: https://www.shadertoy.com/view/4dXBRH
// Gradient Noise 2D, Derivatives: https://www.shadertoy.com/view/XdXBRH
// Value Noise 3D, Derivatives: https://www.shadertoy.com/view/XsXfRH
// Gradient Noise 3D, Derivatives: https://www.shadertoy.com/view/4dffRH
// Value Noise 2D : https://www.shadertoy.com/view/lsf3WH
// Value Noise 3D : https://www.shadertoy.com/view/4sfGzS
// Gradient Noise 2D : https://www.shadertoy.com/view/XdXGW8
// Gradient Noise 3D : https://www.shadertoy.com/view/Xsl3Dl
// Simplex Noise 2D : https://www.shadertoy.com/view/Msf3WH
// Wave Noise 2D : https://www.shadertoy.com/view/tldSRj
float hash(vec3 p) // replace this by something better
{
p = 50.0*fract( p*0.3183099 + vec3(0.71,0.113,0.419));
return -1.0+2.0*fract( p.x*p.y*p.z*(p.x+p.y+p.z) );
}
// return value noise (in x) and its derivatives (in yzw)
vec4 noised( in vec3 x )
{
vec3 i = floor(x);
vec3 w = fract(x);
#if 1
// quintic interpolation
vec3 u = w*w*w*(w*(w*6.0-15.0)+10.0);
vec3 du = 30.0*w*w*(w*(w-2.0)+1.0);
#else
// cubic interpolation
vec3 u = w*w*(3.0-2.0*w);
vec3 du = 6.0*w*(1.0-w);
#endif
float a = hash(i+vec3(0.0,0.0,0.0));
float b = hash(i+vec3(1.0,0.0,0.0));
float c = hash(i+vec3(0.0,1.0,0.0));
float d = hash(i+vec3(1.0,1.0,0.0));
float e = hash(i+vec3(0.0,0.0,1.0));
float f = hash(i+vec3(1.0,0.0,1.0));
float g = hash(i+vec3(0.0,1.0,1.0));
float h = hash(i+vec3(1.0,1.0,1.0));
float k0 = a;
float k1 = b - a;
float k2 = c - a;
float k3 = e - a;
float k4 = a - b - c + d;
float k5 = a - c - e + g;
float k6 = a - b - e + f;
float k7 = - a + b + c - d + e - f - g + h;
return vec4( k0 + k1*u.x + k2*u.y + k3*u.z + k4*u.x*u.y + k5*u.y*u.z + k6*u.z*u.x + k7*u.x*u.y*u.z,
du * vec3( k1 + k4*u.y + k6*u.z + k7*u.y*u.z,
k2 + k5*u.z + k4*u.x + k7*u.z*u.x,
k3 + k6*u.x + k5*u.y + k7*u.x*u.y ) );
}
float noise3(vec3 p) {
vec4 v = noised(p);
return v.x;
}
`