www.xbdev.net
xbdev - software development
Wednesday January 15, 2025
Home | Contact | Support | WebGPU Graphics and Compute ...
     
 

WebGPU/WGSL Tutorials and Articles

Graphics and Compute ...

 


Noise Categories - Managing the Madness!


Their seems to be so many noise functions - their are hundreds if not thousands of noise algorithms - each with their own name and characteristics.

However, we try and categories the noise functions - group them together - so that we have a handful of types of noises.

Elaboration on an earlier article which was collecting noise functions (LINK). In this article, we sort of try and organise things - and take things further. Each noise function is linked to an interactive example - so you can click on it and see a hacky version of the noise. Send me a quick email if you find a bug or think of a tidier version/better version :)

Out of the 60 example noise functions - we'll group them into 7 main categories (given below).

Noise Function Categories


Base Noise 1. Random Noise 2. Value Noise 3. Gradient Noise 4. White Noise 5. Uniform Noise 6. Blue Noise 7. Pink Noise 8. Gaussian Noise Complex & Layered Noise 9. Fractal Noise 10. Octave Noise 11. Fractional Brownian Motion (FBM) 12. Turbulence Noise 13. Layered Noise 14. Perlin Noise 15. Fractal Cellular Noise 16. Noise Blending 17. Domain Warping Directional Noise 18. Flow Noise 19. Anisotropic Noise 20. Gradient Squared Noise 21. Angular Gradient Noise 22. Spiral Noise 23. Stripe Noise 24. Stripe Gradient Noise 25. Directional Voronoi Cellular Noise 26. Voronoi Noise 27. Worley Noise 28. Cellular Noise 29. Fractal Voronoi 30. Spiral Voronoi 31. Noisy Voronoi Patterned Noise 32. Ring Noise 33. Radial Noise 34. Ripple Noise 35. Polygonal Grid Noise 36. Crosshatch Noise 37. Starburst Noise 38. Circular Wave Noise 39. Spiral Gradient Noise 40. Plasma Noise 41. Interference Noise 42. Checkerboard Noise 43. Hexagonal Noise Animated/Temporal Noise 44. Offset Noise 45. Warped Noise 46. Seamless Noise 47. Texture Distortion Noise 48. Dynamic Noise 49. Time-Varying Voronoi 50. Animated Gradient Noise Specialized Noise 51. Tileable Noise 52. Gradient Ridge Noise 53. Multiscale Noise 54. Spectral Noise 55. Blob Noise 56. Point Cluster Noise 57. Crystal Noise 58. Wavelet Noise 59. Ridged FBM Noise 60. Sparse Convolution Noise


The following give a small description of each example noise function from above - in addition to a mockup code implementation in WGSL (WebGPU Shader Language).




Base Noise



1. Random Noise

Generates uncorrelated random values across the domain.

   fn random(uvvec2<f32>) -> f32 {
       return 
fract(sin(dot(uvvec2<f32>(12.989878.233))) * 43758.5453);
   }



2. Value Noise

Interpolates random values to create smooth transitions.

   fn valueNoise(uvvec2<f32>) -> f32 {
       
let cell floor(uv);
       
let frac fract(uv);
       
let randomValues vec2<f32>(random(cell), random(cell vec2<f32>(1.00.0)));
       return 
mix(randomValues.xrandomValues.yfrac.x);
   }



3. Gradient Noise

Utilizes gradient vectors to interpolate smooth noise.

   fn gradientNoise(uvvec2<f32>) -> f32 {
       
let cell floor(uv);
       
let grad fract(sin(vec2<f32>(dot(cellvec2<f32>(127.1311.7)), dot(cell vec2<f32>(1.00.0), vec2<f32>(269.5183.3)))) * 43758.5453);
       return 
dot(gradfract(uv));
   }



4. White Noise

Produces uncorrelated, high-frequency noise.

   fn whiteNoise(uvvec2<f32>) -> f32 {
       return 
random(uv);
   }



5. Uniform Noise

Generates noise with uniform distribution.

   fn uniformNoise(uvvec2<f32>) -> f32 {
       return 
step(0.5random(uv));
   }



6. Blue Noise

Low-frequency noise optimized for dithering.

   fn blueNoise(uvvec2<f32>) -> f32 {
       return 
smoothstep(0.20.8random(uv));
   }



7. Pink Noise

Lower frequency noise useful in audio synthesis.

   fn pinkNoise(uvvec2<f32>) -> f32 {
       return 
pow(random(uv), 1.0 3.0);
   }



8. Gaussian Noise

Generates noise with a Gaussian distribution.

   fn gaussianNoise(uvvec2<f32>) -> f32 {
       
let rand1 random(uv);
       
let rand2 random(uv vec2<f32>(1.01.0));
       return 
sqrt(-2.0 log(rand1)) * cos(6.283185 rand2);
   }






Complex/Layered Noise



9. Fractal Noise

Combines multiple layers of noise at different scales.

   fn fractalNoise(uvvec2<f32>, octavesi32) -> f32 {
       var 
value 0.0;
       var 
frequency 1.0;
       var 
amplitude 1.0;
       for (var 
ii32 0octaves1) {
           
value += fbm(uv frequency) * amplitude;
           
frequency *= 2.0;
           
amplitude *= 0.5;
       }
       return 
value;
   }



10. Octave Noise

A simpler layering of multiple frequencies of noise.

    fn octaveNoise(uvvec2<f32>, octavesi32) -> f32 {
        var 
result 0.0;
        for (var 
ii32 0octaves1) {
            
result += fbm(uv pow(2.0f32(i))) / pow(2.0f32(i));
        }
        return 
result;
    }



11. Fractional Brownian Motion (FBM)

A widely-used method for natural-looking noise patterns.

    fn fbm(uvvec2<f32>) -> f32 {
        var 
value 0.0;
        var 
frequency 1.0;
        var 
amplitude 0.5;
        for (var 
ii32 051) {
            
value += gradientNoise(uv frequency) * amplitude;
            
frequency *= 2.0;
            
amplitude *= 0.5;
        }
        return 
value;
    }



12. Turbulence Noise

A variant of FBM using absolute values for sharper textures.

    fn turbulence(uvvec2<f32>) -> f32 {
        var 
value 0.0;
        var 
frequency 1.0;
        for (var 
ii32 051) {
            
value += abs(gradientNoise(uv frequency));
            
frequency *= 2.0;
        }
        return 
value;
    }



13. Layered Noise

Stacks noise layers for texture complexity.

    fn layeredNoise(uvvec2<f32>, layersi32) -> f32 {
        var 
result 0.0;
        for (var 
ii32 0layers1) {
            
result += gradientNoise(uv pow(2.0f32(i))) / pow(2.0f32(i));
        }
        return 
result;
    }



14. Perlin Noise

A classic noise function used in procedural generation.

    fn perlinNoise(uvvec2<f32>) -> f32 {
        
let cell floor(uv);
        
let grad fract(sin(vec2<f32>(dot(cellvec2<f32>(127.1311.7)), dot(cell vec2<f32>(1.00.0), vec2<f32>(269.5183.3)))) * 43758.5453);
        return 
dot(gradfract(uv));
    }



15. Fractal Cellular Noise

Combines cellular noise with fractal layers.

    fn fractalCellularNoise(uvvec2<f32>, layersi32) -> f32 {
        var 
result 0.0;
        for (var 
ii32 0layers1) {
            
result += voronoiNoise(uv pow(2.0f32(i))) / pow(2.0f32(i));
        }
        return 
result;
    }



16. Noise Blending

Interpolates between multiple noise types.

    fn noiseBlending(uvvec2<f32>, weightf32) -> f32 {
        return 
mix(gradientNoise(uv), voronoiNoise(uv), weight);
    }



17. Domain Warping

Applies noise to distort its own domain.

    fn domainWarping(uvvec2<f32>) -> f32 {
        
let warp fbm(uv);
        return 
fbm(uv warp);
    }





Directional Noise



18. Flow Noise

Produces smoothly flowing patterns, ideal for fluid effects.

    fn flowNoise(uvvec2<f32>, timef32) -> f32 {
        
let warpedUV uv vec2<f32>(sin(time), cos(time));
        return 
fbm(warpedUV);
    }



19. Anisotropic Noise

Stretches noise along a specific axis for directional effects.

    fn anisotropicNoise(uvvec2<f32>, directionvec2<f32>) -> f32 {
        
let stretchUV uv direction;
        return 
gradientNoise(stretchUV);
    }



20. Gradient Squared Noise

Amplifies directional gradients for sharp features.

    fn gradientSquaredNoise(uvvec2<f32>) -> f32 {
        
let grad gradientNoise(uv);
        return 
grad grad;
    }



21. Angular Gradient Noise

Creates angular patterns for circular or star-like effects.

    fn angularGradientNoise(uvvec2<f32>) -> f32 {
        
let angle atan2(uv.yuv.x) * 0.5 3.14159;
        return 
abs(fract(angle) - 0.5);
    }



22. Spiral Noise

Generates spiraling patterns.

    fn spiralNoise(uvvec2<f32>, twistsf32) -> f32 {
        
let angle atan2(uv.yuv.x);
        return 
abs(sin(angle twists length(uv)));
    }



23. Stripe Noise

Produces parallel line patterns.

    fn stripeNoise(uvvec2<f32>, frequencyf32) -> f32 {
        return 
abs(sin(uv.frequency));
    }



24. Stripe Gradient Noise

Adds a gradient effect to stripe noise.

    fn stripeGradientNoise(uvvec2<f32>, frequencyf32minValuef32maxValuef32) -> f32 {
        return 
mix(minValuemaxValueabs(sin(uv.frequency)));
    }



25. Directional Voronoi

Orients Voronoi noise in a specific direction.

    fn directionalVoronoi(uvvec2<f32>, directionvec2<f32>) -> f32 {
        
let dirUV uv direction;
        return 
voronoiNoise(dirUV);
    }





Cellular Noise



26. Voronoi Noise

Generates cell-like patterns with varying sizes.

    fn voronoiNoise(uvvec2<f32>) -> f32 {
        
let cell floor(uv);
        
let frac fract(uv);
        
        var 
minDist 1.0;
    
        for (var 
yi32 = -1<= 11) {
            for (var 
xi32 = -1<= 11) {
                
let neighbor cell vec2<f32>(f32(x), f32(y));
                
let point neighbor random(neighbor);
                
let dist length(frac - (point cell));
                
minDist min(minDistdist);
            }
        }
    
        return 
minDist;
    }



27. Worley Noise

Computes distances to nearest neighbors for texture variety.

    fn worleyNoise(uvvec2<f32>) -> f32 {
        var 
minDistf32 1e9;
        var 
featurePointvec2<f32>;
        
        
// Generate feature points and calculate distance
        
for (var ii32 = -1<= 11) {
            for (var 
ji32 = -1<= 11) {
                
featurePoint floor(uv) + vec2<f32>(f32(i), f32(j)) + fract(sin(vec2<f32>(dot(floor(uv) + vec2<f32>(f32(i), f32(j)), vec2<f32>(12.989878.233))) * 43758.5453));
                var 
distf32 length(uv featurePoint);
                if (
dist minDist) {
                    
minDist dist;
                }
            }
        }
        return 
minDist;
    }



28. Cellular Noise

Combines cellular techniques for organic looks.

    fn cellularNoise(uvvec2<f32>) -> f32 {
        return 
worleyNoise(uv) - voronoiNoise(uv); // or another combination of functions
    
}



29. Fractal Voronoi

Layers Voronoi noise for fractal patterns.

    fn fractalVoronoi(uvvec2<f32>, octavesi32) -> f32 {
        var 
result 0.0;
        for (var 
ii32 0octaves1) {
            
result += voronoiNoise(uv pow(2.0f32(i))) / pow(2.0f32(i));
        }
        return 
result;
    }



30. Spiral Voronoi

Twists Voronoi cells into spirals.

    fn spiralVoronoi(uvvec2<f32>, twistsf32) -> f32 {
        return 
voronoiNoise(uv vec2<f32>(sin(twists), cos(twists)));
    }



31. Noisy Voronoi

Adds randomness to Voronoi cells.

    fn noisyVoronoi(uvvec2<f32>) -> f32 {
        return 
voronoiNoise(uv) * random(uv);
    }





Patterned Noise



32. Ring Noise

Produces concentric rings.

    fn ringNoise(uvvec2<f32>) -> f32 {
        return 
abs(sin(length(uv) * 10.0));
    }



33. Radial Noise

Creates circular, radial patterns.

    fn radialNoise(uvvec2<f32>) -> f32 {
        return 
fract(length(uv) * 5.0);
    }



34. Ripple Noise

Mimics ripples in water.

    fn rippleNoise(uvvec2<f32>) -> f32 {
        return 
sin(length(uv) * 10.0) * 0.5 0.5;
    }



35. Polygonal Grid Noise

Creates a grid of polygons like hexagons.

    fn polygonalGridNoise(uvvec2<f32>, sidesf32) -> f32 {
        
let angle atan2(uv.yuv.x) + 3.14159;
        
let segment floor(angle / (6.28318 sides));
        return 
fract(segment random(uv));
    }



36. Crosshatch Noise

Produces crosshatching patterns.

    fn crosshatchNoise(uvvec2<f32>, frequencyf32) -> f32 {
        
let lineX step(0.5sin(uv.frequency) * 0.5 0.5);
        
let lineY step(0.5sin(uv.frequency) * 0.5 0.5);
        return 
lineX lineY;
    }



37. Starburst Noise

Radiates lines from a central point.

    fn starburstNoise(uvvec2<f32>) -> f32 {
        return 
abs(sin(atan2(uv.yuv.x) * 10.0));
    }



38. Circular Wave Noise

Produces expanding concentric waves.

    fn circularWaveNoise(uvvec2<f32>, timef32) -> f32 {
        return 
sin(length(uv) * 10.0 time);
    }



39. Spiral Gradient Noise

Generates a gradient that spirals outward.

    fn spiralGradientNoise(uvvec2<f32>, frequencyf32amplitudef32) -> f32 {
        
let angle atan2(uv.yuv.x);
        
let dist length(uv);
    
        
// Create a spiral pattern with frequency and amplitude controls
        
let spiral sin(angle frequency dist amplitude);
        
        
// Blend the spiral pattern with noise
        
let noise random(uv);
        
        
// Fade the effect based on distance
        
let fade smoothstep(0.01.0dist);
    
        
// Combine the spiral and noise with the fade
        
return mix(noisespiralfade);
    }



40. Plasma Noise

Produces a plasma-like, colorful pattern resource.

    fn plasmaNoise(uvinvec2<f32>) -> f32 {
        var 
scale:f32 0.1;
        var 
timef32 0.5;
        var 
uv uvin*scale;
        
let layer1 sin(uv.10.0 time) * cos(uv.10.0 time);
        
let layer2 sin(uv.20.0 uv.20.0 time 2.0) * 0.5;
        
let layer3 cos(uv.40.0 uv.40.0 time 4.0) * 0.25;
        
        
let noise layer1 layer2 layer3;
        
        return 
noise 0.5 0.5// Normalize to range [0, 1]
    
}



41. Interference Noise

Simulates wave interference.

    fn interferenceNoise(uvvec2<f32>) -> f32 {
        return 
sin(uv.5.0) + cos(uv.5.0);
    }



42. Checkerboard Noise

Produces a checkerboard pattern.

    fn checkerboardNoise(uvvec2<f32>) -> f32 {
        
let check floor(uv.x) + floor(uv.y);
        return 
fract(sin(check) * 43758.5453);
    }



43. Hexagonal Noise

Creates a hexagonal tiling pattern.

    fn hexagonalNoise(uvvec2<f32>) -> f32 {
        
// Constants to define hexagonal grid
        
let k vec2<f32>( sqrt(3.0), 1.0);
        
        
// Transform UV coordinates to hexagonal grid space
        
let uv_hex vec2<f32>(
            
uv.k.uv.k.y,
            
uv.k.uv.k.y
        
);
    
        
// Calculate hexagonal cell coordinates
        
let cell floor(uv_hex);
        
let f fract(uv_hex);
        
        
// Calculate noise values for the corners of the hexagon
        
let corners = array<vec2<f32>, 6>(
            
vec2<f32>(0.00.0),
            
vec2<f32>(1.00.0),
            
vec2<f32>(0.50.866),
            
vec2<f32>(-0.50.866),
            
vec2<f32>(-1.00.0),
            
vec2<f32>(-0.5, -0.866)
        );
    
        var 
noise_valuef32 0.0;
        var 
min_distancef32 1e10;
    
        for (var 
iu32 0u6u1u) {
            
let corner cell corners[i];
            
let dist distance(uv_hexcorner);
            
            if (
dist min_distance) {
                
min_distance dist;
                
noise_value fract(sin(dot(cornervec2<f32>(12.989878.233))) * 43758.5453);
            }
        }
    
        return 
noise_value;
    }





Animated/Temporal Noise



44. Offset Noise

Introduces an offset effect, often used for animation.

    fn offsetNoise(uvvec2<f32>, timef32) -> f32 {
        return 
random(uv time);
    }



45. Warped Noise

Distorts the noise field over time to create dynamic effects.

    fn warpedNoise(uvvec2<f32>, timef32) -> f32 {
        
let warpedUV uv sin(time uv) * 0.5;
        return 
random(warpedUV);
    }



46. Seamless Noise

Creates a continuous, looping noise pattern, typically used in textures.

    fn seamlessNoise(uvvec2<f32>) -> f32 {
        
let repeatUV fract(uv);
        return 
random(repeatUV);
    }



47. Texture Distortion Noise

Distorts texture coordinates for dynamic texture animation.

    fn textureDistortionNoise(uvvec2<f32>, timef32) -> f32 {
        
let distortedUV uv sin(uv time) * 0.1;
        return 
random(distortedUV);
    }



48. Dynamic Noise

Changes its characteristics over time for evolving patterns.

    fn dynamicNoise(uvvec2<f32>, timef32) -> f32 {
        
let dynamicUV uv time 0.1;
        return 
random(dynamicUV);
    }



49. Time-Varying Voronoi

Modifies the Voronoi cells over time for moving patterns.

    fn timeVaryingVoronoi(uvvec2<f32>, timef32) -> f32 {
        
let timeShiftedUV uv time 0.1;
        return 
voronoiNoise(timeShiftedUV);
    }



50. Animated Gradient Noise

Creates animated gradients by adjusting the direction over time.

    fn animatedGradientNoise(uvvec2<f32>, timef32) -> f32 {
        
let angle time atan2(uv.yuv.x);
        
let gradient vec2<f32>(cos(angle), sin(angle));
        return 
dot(uvgradient);
    }





Specialized Noise



51. Tileable Noise

Generates repeating noise patterns, typically used for textures.

    fn tileableNoise(uvvec2<f32>) -> f32 {
        return 
random(fract(uv));
    }



52. Gradient Ridge Noise

Adds ridges to gradient noise for more pronounced features.

    fn gradientRidgeNoise(uvvec2<f32>) -> f32 {
        
let gradient gradientNoise(uv);
        return 
abs(gradient) * 2.0 1.0;
    }



53. Multiscale Noise

Combines multiple noise functions at different scales.

    fn multiscaleNoise(uvvec2<f32>, scalesi32) -> f32 {
        var 
result 0.0;
        for (var 
ii32 0scales1) {
            
result += random(uv pow(2.0f32(i))) / pow(2.0f32(i));
        }
        return 
result;
    }



54. Spectral Noise

Noise with controlled frequency components, often for sound design.

    fn spectralNoise(uvvec2<f32>, frequencyf32) -> f32 {
        return 
random(uv frequency);
    }



55. Blob Noise

Creates irregular blob-like structures.

    fn blobNoise(uvvec2<f32>, sizef32) -> f32 {
        var 
minDistf32 0.0// Initialize with a large value
        
        
for (var yi32 = -1<= 11) {
            for (var 
xi32 = -1<= 11) {
                
let neighbor vec2<f32>(f32(x), f32(y));
                
let point floor(uv) + neighbor random(floor(uv) + neighbor);
                
let dist length(uv point) * 2.0;
                if ( 
dist 1.5 && minDist==0.0)
                {
                    
minDist 8.0;
                }
                
minDist min(minDistdist) ;
            }
        }
    
        return 
exp(-minDist size);
    }



56. Point Cluster Noise

Generates clustered points for dense structures.

    fn pointClusterNoise(uvvec2<f32>) -> f32 {
        return 
step(0.5random(uv));
    }



57. Crystal Noise

Creates crystal-like sharp, angular noise patterns.

    fn crystalNoise(uvvec2<f32>) -> f32 {
        var 
minDistf32 1.0// Initialize with a large value
        
var facetvec2<f32> = vec2<f32>(0.00.0);
    
        for (var 
yi32 = -1<= 11) {
            for (var 
xi32 = -1<= 11) {
                
let neighbor vec2<f32>(f32(x), f32(y));
                
let point floor(uv) + neighbor random(floor(uv) + neighbor);
                
let dist length(uv point);
                
                if (
dist minDist) {
                    
minDist dist;
                    
facet point;
                }
            }
        }
    
        
let angle atan2(uv.facet.yuv.facet.x);
        return 
abs(sin(angle 10.0));
    }



58. Wavelet Noise

Uses wavelets to generate smooth, multi-scale noise.

    fn waveletNoise(uvvec2<f32>, scalef32) -> f32 {
        
let noise sin(uv.scale random(uv) * scale) * cos(uv.scale random(uv.yx) * scale);
        return 
abs(noise);
    }



59. Ridged FBM Noise

A variant of FBM that enhances high-frequency features.

    fn ridgedFBM(uvvec2<f32>, octavesi32) -> f32 {
        var 
result 0.0;
        var 
amplitude 1.0;
        for (var 
ii32 0octaves1) {
            
result += amplitude * (1.0 abs(fbm(uv pow(2.0f32(i))))) / pow(2.0f32(i));
            
amplitude *= 0.5;
        }
        return 
result;
    }



60. Sparse Convolution Noise

Noise with sparse, scattered values used for specialized effects.

    fn sparseConvolutionNoise(uvvec2<f32>) -> f32 {
        var 
scalef32 2.0;
        var 
totalf32 0.0;
        var 
weightf32 0.0;
    
        for (var 
yi32 = -1<= 11) {
            for (var 
xi32 = -1<= 11) {
                
let neighbor vec2<f32>(f32(x), f32(y));
                
let offset random(neighbor) * scale;
                
let point uv neighbor offset;
    
                
let value random(point);
                
let dist length(neighbor);
                
let influence 1.0 / (1.0 dist);
                
                
total += value influence;
                
weight += influence;
            }
        }
    
        return 
total weight;
    }




Resources & Links


• WebGPU Code Samples/Interactive (LINK)

• Lots of noise functions on a single image (LINK)

• Earlier article when research the and collecting different noise functions (just functions) (LINK)

• Diary/run through of noise (LINK)


































WebGPU Development Pixels - coding fragment shaders from post processing to ray tracing! WebGPU by Example: Fractals, Image Effects, Ray-Tracing, Procedural Geometry, 2D/3D, Particles, Simulations WebGPU Games WGSL 2d 3d interactive web-based fun learning WebGPU Compute WebGPU API - Owners WebGPU Development Cookbook - coding recipes for all your webgpu needs! WebGPU & WGSL Essentials: A Hands-On Approach to Interactive Graphics, Games, 2D Interfaces, 3D Meshes, Animation, Security and Production Kenwright graphics and animations using the webgpu api 12 week course kenwright learn webgpu api kenwright programming compute and graphics applications with html5 and webgpu api kenwright real-time 3d graphics with webgpu kenwright webgpu for dummies kenwright webgpu api develompent a quick start guide kenwright webgpu by example 2022 kenwright webgpu gems kenwright webgpu interactive compute and graphics visualization cookbook kenwright wgsl webgpu shading language cookbook kenwright WebGPU Shader Language Development: Vertex, Fragment, Compute Shaders for Programmers Kenwright wgsl webgpugems shading language cookbook kenwright WGSL Fundamentals book kenwright WebGPU Data Visualization Cookbook kenwright Special Effects Programming with WebGPU kenwright WebGPU Programming Guide: Interactive Graphics and Compute Programming with WebGPU & WGSL kenwright Ray-Tracing with WebGPU kenwright



 
Advert (Support Website)

 
 Visitor:
Copyright (c) 2002-2024 xbdev.net - All rights reserved.
Designated articles, tutorials and software are the property of their respective owners.