This commit is contained in:
Rakarake 2025-12-11 23:47:18 +01:00
parent 90d565ff8d
commit d5e30cb0d5

View file

@ -7,7 +7,27 @@ float rand(vec2 co){
return fract(sin(dot(co, vec2(12.9898, 78.233))) * 43758.5453); return fract(sin(dot(co, vec2(12.9898, 78.233))) * 43758.5453);
} }
float cell_size = 0.1; float cell_size = 0.05;
#define PI 3.1415926538
// whatever that corner contributes
float c_dot(vec2 point, vec2 corner) {
float angle = rand(corner) * 2*PI;
vec2 random_corner_vec = vec2(cos(angle), sin(angle));
vec2 offset = point - corner;
float dot_product = dot(random_corner_vec, offset);
// for now just return something
return dot_product;
}
float lerp(float a, float b, float x) {
return a + x*(b-a);
}
float fade(float t) {
return ((6*t - 15)*t + 10)*t*t*t;
}
void main() { void main() {
// We'll make origin in the top-left. // We'll make origin in the top-left.
@ -19,16 +39,22 @@ void main() {
vec2 c_tr = uv - grid_edge_offset + vec2(cell_size, 0); vec2 c_tr = uv - grid_edge_offset + vec2(cell_size, 0);
vec2 c_bl = uv - grid_edge_offset + vec2(0, cell_size); vec2 c_bl = uv - grid_edge_offset + vec2(0, cell_size);
vec2 c_br = uv - grid_edge_offset + vec2(cell_size, cell_size); vec2 c_br = uv - grid_edge_offset + vec2(cell_size, cell_size);
// random vectors float c_tl_dot = c_dot(uv, c_tl);
vec2 c_tl_ran = rand(c_tl); float c_tr_dot = c_dot(uv, c_tr);
vec2 c_tr_ran = rand(c_tr); float c_bl_dot = c_dot(uv, c_bl);
vec2 c_bl_ran = rand(c_bl); float c_br_dot = c_dot(uv, c_br);
vec2 c_br_ran = rand(c_br);
// offset vectors
vec2 c_tl_off = c_tl - uv;
vec2 c_tr_off = c_tr - uv;
vec2 c_bl_off = c_bl - uv;
vec2 c_br_off = c_br - uv;
FragColor = // lerp index
vec2 tile_uv = (uv - c_tl) / cell_size;
float u = fade(tile_uv.x);
float v = fade(tile_uv.y);
//float val = smoothstep(tile_uv.x, smoothstep(tile_uv.y, c_bl_dot, c_tl_dot), smoothstep(tile_uv.y, c_br_dot, c_tr_dot));
float val = lerp(lerp(c_tl_dot, c_bl_dot, v), lerp(c_tr_dot, c_br_dot, v), u);
//float val = tile_uv.y;
//float val = c_bl_dot*2 + 0.5;
val = val * 20;
FragColor = vec4(val, val, val, 1);
//float yes = 0.5 + (c_dot(uv, c_tl) + c_dot(uv, c_tr) + c_dot(uv, c_bl) + c_dot(uv, c_br)) / 2;
//FragColor = vec4(yes, yes, yes, 1);
} }