Skip to content

Commit

Permalink
Managed to have final view, but still precision issues when grid x is…
Browse files Browse the repository at this point in the history
… high
  • Loading branch information
vhiribarren committed Dec 16, 2023
1 parent 35398fc commit 04c2f64
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/app/sketches/voronoi-stretched/fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,32 @@ varying vec2 v_uv;

const float INFINITY = 1.0 / 0.0;
const float FREQUENCE = 31.0;
const float LINE_PRECISION = 0.5;
const float LINE_PRECISION = 0.1;


ivec2 uv_to_grid(vec2 uv) {
//return ivec2(uv/2.0);
//return ivec2(uv.x, log2(uv.y + 1.0));
return ivec2(uv.x, log2(uv.y + 1.0));
int grid_y = int(log2(uv.y + 1.0));
int grid_x = int(float(uv.x) / exp2(float(grid_y))) ;
return ivec2(grid_x, grid_y);
}

vec2 gen_cell_at_grid(int x, int y) {
//return 2.0*(vec2(x, y) + 0.5);
//return vec2(float(x), exp2(float(y))-1.0)*(vec2(1.0, 1.0));
//return vec2(float(x)+0.5, exp2(float(y-1))-1.0) + vec2(0.0, 0.5) * vec2(float(x), exp2(float(y-1)));
return vec2(float(x), exp2(float(y-1))-1.0) + vec2(random(vec2(y, x)), random(vec2(x, y))) * vec2(1.0, exp2(float(y-1)));
//return vec2(float(x)+0.0, exp2(float(y-1))-1.0) + vec2(0.0, 0.0) * vec2(float(x), exp2(float(y-1)));
return vec2(float(x) * exp2(float(y -1)), exp2(float(y-1))-1.0) + vec2(random(vec2(y, x)), random(vec2(x, y))) * vec2(exp2(float(y-1)), exp2(float(y-1)));
//return vec2(float(x) * exp2(float(y -1)), exp2(float(y-1))-1.0);

}

void main() {
vec2 canvas_size = gl_FragCoord.xy / v_uv;
float canvas_ratio = canvas_size.x / canvas_size.y;
vec2 uv = v_uv;
//uv.y = 1.0 - uv.y;
//uv -= 0.01;
uv *= vec2(canvas_ratio, 1.0); // Cancel screen deformation

//TODO faire aussi du voronoi avec des octaves, des grosses cellules replies de petites cellules avec un coeff de ligne qui baisse
Expand All @@ -35,9 +40,9 @@ void main() {
float min_dist = INFINITY;
float snd_min_dist = INFINITY;
vec2 min_vcell;
int scan_max = int(exp2(float(grid.y))); // 1;
for (int i = -scan_max; i <= scan_max; i++) {
for (int j = -scan_max; j <= scan_max; j++) {
int scan_max = 2; //int(exp2(float(grid.y))); // 1;
for (int i = -30; i <= 10; i++) {
for (int j = -1; j <= 2; j++) {
vec2 current_vcell = gen_cell_at_grid(grid.x + i, grid.y + j);
float vcell_dist = distance(uv, current_vcell);
if (vcell_dist < min_dist) {
Expand All @@ -56,7 +61,7 @@ void main() {
web_col = 1.0;
}
// Worley field
float worley_col = 0.4*min_dist;
float worley_col = 0.02*min_dist;
// Grid
float grid_col = step(0.98, fract(uv.y)) + step(0.98, fract(uv.x));

Expand Down

0 comments on commit 04c2f64

Please sign in to comment.