perlin noise function

This commit is contained in:
Rakarake 2025-12-27 14:34:02 +01:00
parent 69d3319a4e
commit d5829527c1

View file

@ -48,14 +48,7 @@ float fade(float t) {
return ((6.0*t - 15.0)*t + 10.0)*t*t*t; return ((6.0*t - 15.0)*t + 10.0)*t*t*t;
} }
float perlin_noise(vec2 uv) {
void main() {
vec2 uv = gl_FragCoord.xy / WindowSize;
// We'll make origin in the top-left.
uv.y = 1.0 - uv.y;
float frac = WindowSize.x / WindowSize.y;
uv.x *= frac;
vec2 grid_edge_offset = mod(uv, cell_size); vec2 grid_edge_offset = mod(uv, cell_size);
// c: corner // c: corner
vec2 c_tl = uv - grid_edge_offset; vec2 c_tl = uv - grid_edge_offset;
@ -74,6 +67,15 @@ void main() {
float u = fade(tile_uv.x); float u = fade(tile_uv.x);
float v = fade(tile_uv.y); float v = fade(tile_uv.y);
float val = lerp(lerp(c_tl_dot, c_bl_dot, v), lerp(c_tr_dot, c_br_dot, v), u); float val = lerp(lerp(c_tl_dot, c_bl_dot, v), lerp(c_tr_dot, c_br_dot, v), u);
float out_val = val /2.0 + 0.5; return val /2.0 + 0.5;
}
void main() {
vec2 uv = gl_FragCoord.xy / WindowSize;
// We'll make origin in the top-left.
uv.y = 1.0 - uv.y;
uv.x *= WindowSize.x / WindowSize.y;
float out_val = perlin_noise(uv);
color = vec4(out_val, out_val, out_val, 1.0); color = vec4(out_val, out_val, out_val, 1.0);
} }