Let's start with a simpe noise generator function that creates rough noise - just random numbers. We'll normalize the numbers so they're in the range 0.0 to 1.0.
There are lot of various ways of doing this - worth looking into
chaos theory
if this facinates you!
Simple 2d noise function
A popular noise function is one that mixes trignometric functions with large values - the values are so large and wrap around that they create a chaotic pattern which we can sample from using a seed value (offset).
If we write a simple fragment shader for a full screen quad, we can take a look at this noise - color each pixel using the value as an rgb color (grayscale) using the uv coordinates as the seed.
@fragment fn main(@location(0) fragCoord : vec2<f32>) -> @location(0) vec4<f32> { // generate random number var randomNumber = random(fragCoord);
// Use random number for fragment color (for demonstration) var color: vec3<f32> = vec3<f32>(randomNumber); // Use the random number for RGB values
// Output final color return vec4<f32>(color, 1.0); }
The output isn't very exciting - just lots of randompixels - looks like static noise you'd see on an old tv!
In fact, you can add an 'offset' to the uv coordinates so it contantly changes (e.g., create a uniform timer called `mytimer`) which we increment each frame.
Visitor:
Copyright (c) 2002-2024 xbdev.net - All rights reserved.
Designated articles, tutorials and software are the property of their respective owners.