Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

day 004

no interaction for this one
project link

three.js | shader


Moist and crystal dew, never evaporate before sunrises. Let's party, and get wasted.

learned today

Noise section from the book of shaders.

Noise function is linear transition of random function so that the result is more coherent and organic.

float i = floor(x); // integer

float f = fract(x); // fraction

y = rand(i); (blocks of number)

//the following are noise part

y = mix(rand(i), rand(i + 1.0), f);

y = mix(rand(i), rand(i + 1.0), smoothstep(0.,1.,f));

mix( ) -- mix() performs a linear interpolation between x and y using a to weight between them. The return value is computed as x × (1−a) + y × a. So the smaller the a is, the closer to x, the larger the a is, closer to y.

2D noise function

 float noise(vec2 st) {
     vec2 i = floor(st);
     vec2 f = fract(st);
     //same as smoothstep()
     vec2 u = f * f * (3.0-2.0 * f);
     // u = smoothstep(0.,1.,f);
     return mix( mix( dot( random2(i + vec2(0.0,0.0) ), f - vec2(0.0,0.0) ),
                      dot( random2(i + vec2(1.0,0.0) ), f - vec2(1.0,0.0) ), u.x),
                 mix( dot( random2(i + vec2(0.0,1.0) ), f - vec2(0.0,1.0) ),
                      dot( random2(i + vec2(1.0,1.0) ), f - vec2(1.0,1.0) ), u.x), u.y);
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.