Posts

Showing posts with the label noise

kodelife/GLSL simple noise code

Below is some code that generates some smooth looking noise. It isn't very complex, but it's probably good enough to get you going. Using code from The Art of Code youtube channel. Let's break down the important functions and see how they feed into one another. float N21(vec2 p){     return fract(sin(p.x*1000.0+p.y*6832.0)*5224.0); } This function takes a vector 2 "p", which is actually going to be our uv coordinate & multiplies each component(x and y) by two arbitrary large numbers , before getting the sine value. This small value is then multiplied by another large number, and then only the fractional part of that value is returned. On it's own, this will return nice static tv/white noise kinda values. You might call it in the main function like this - float c= N21(uv*4.0)   Next up, is  float smoothNoise(vec2 uv){     vec2 lv=fract(uv);    lv=lv*lv*(3.0-2.0*lv);    vec2 id=floor(uv);        float bl...

random number generation, noise and fbm, glsl

I should really change the name of this blog to Shader Shit.... anyway.. I'll get back to Unity specific crap one day. The following code is all for GLSL & will need adapting for use in a Unity fragment shader. I like to use Kodelife to test out my shader ideas. Look it up & give it some support if you like it! This post is about fake randomness, learnt from The Book of Shaders & The Art of Coding, on the website & youtube channel respectively. Within your main GLSL function, you might need to create a random value, often just a float value (remember you can make a vector from multiple floats). A great thing to feed such a random number generating function is your UV value. Here's an example- float random(vec2 uv){ return fract(sin(dot(uv,vec2(52.2957001,2355.957250024))*574.9829619)); } What we're doing here is getting the dot product of our UV coordinate, with an arbitrary vector that consists of large numbers with plenty of "complex" fractiona l...