In a previous post I describe a fast 32-bit hash function which I’ve been using as the basis for all noises documented on this site.  Recently I have made some changes to it resulting in…

• Improved flexibility
• A slight improvement in randomness
• A larger possible domain
• The possibility of a 4D hash function

For anyone interested in the inner workings, the change is that the input coordinate is first scaled before offsetting the domain.  This has allowed for a larger range of precision for the hashing process.  As with the previous hash function, here is some GLSL code which implements the new 32bit hash function to calculate pseudo random 0.0->1.0 hash values for the 4 corners of a 2D integer grid cell.

##### ```vec4 FAST32_2_hash_2D( vec2 gridcell ) { // gridcell is assumed to be an integer coordinate const vec2 OFFSET = vec2( 403.839172, 377.242706 ); const float DOMAIN = 69.0; const float SOMELARGEFLOAT = 32745.708984; const vec2 SCALE = vec2( 2.009842, 1.372549 ); vec4 P = vec4( gridcell.xy, gridcell.xy + 1.0 ); P = P - floor(P * ( 1.0 / DOMAIN )) * DOMAIN; P = ( P * SCALE.xyxy ) + OFFSET.xyxy; P *= P; return fract( P.xzxz * P.yyww * ( 1.0 / SOMELARGEFLOAT ) ); } ```

The new hash function is slightly slower than the old one so I have left all current noises unchanged.  But given that the new function allows for 4D hashing I have written some new 4D Value and 4D Classic Perlin noises.  Complete source for the improved hash function and these new noises can be found on the GitHub repository.

It is always great to show an image at the end of a post, but it is hard to show the benefits of a 4D noise given that the images are not animated.  One great use of 4D noise is through domain distortion (instead of applying a 3D noise over a 3D surface, use a 4D noise and feed an additional noise into the 4D dimension).  The following image shows such an effect applied to the surface of a planet  : )

Planet rendering showing a distorted fractal