Skip to content

Commit

Permalink
Fixed skewed uneven bricks (#623, needs to be checked on mac)
Browse files Browse the repository at this point in the history
  • Loading branch information
RodZill4 committed Dec 17, 2023
1 parent 1d7c238 commit b1772a4
Showing 1 changed file with 19 additions and 24 deletions.
43 changes: 19 additions & 24 deletions addons/material_maker/nodes/skewed_uneven_bricks.mmg
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"vec3 $(name_uv)_corner_uv;",
"vec4 $(name_uv)_brick_fill;",
"vec4 $(name_uv)_corner_fill;",
"float $(name_uv)_bricks = skewed_uneve_bricks($uv, vec2($columns, $rows), $randomness, $mortar * $mortar_map($uv), $bevel * $bevel_map($uv), $round * $round_map($uv), $corner, $seed, $(name_uv)_brick_uv, $(name_uv)_corner_uv, $(name_uv)_brick_fill, $(name_uv)_corner_fill);"
"float $(name_uv)_bricks = skewed_uneven_bricks($uv, vec2($columns, $rows), $randomness, $mortar * $mortar_map($uv), $bevel * $bevel_map($uv), $round * $round_map($uv), $corner, $seed, $(name_uv)_brick_uv, $(name_uv)_corner_uv, $(name_uv)_brick_fill, $(name_uv)_corner_fill);"
],
"global": [
"vec4 generate_rect(vec2 a, vec2 b, vec2 c, vec2 d) {",
Expand Down Expand Up @@ -78,18 +78,16 @@
"\treturn ((b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x)) > 0.0;",
"}",
"",
"vec2 skewed_uneven_cut(vec2 x, float randomness) {",
"\tvec2 value = x;",
"\tvalue *= 4096.0;",
"\tvalue = round(value);",
"\tvalue /= 4096.0;",
"\tvalue = 0.5 + (rand2(value) - 0.5) * randomness;",
"\treturn value;",
"vec2 skewed_uneven_cut(vec2 x, vec2 size, float randomness) {",
"\tconst float grid_size = 4096.0;",
"\treturn 0.5 + (rand2(round(mod(x, size)*grid_size)/grid_size) - 0.5) * randomness;",
"}",
"",
"float skewed_uneve_bricks(vec2 uv, vec2 size, float randomness, float mortar, float bevel, float round, float corner, float seed, inout vec3 brick_uv, inout vec3 corner_uv, inout vec4 brick_fill, inout vec4 corner_fill) {",
"\t//Aalgorithm messes up at randomness 0.0",
"\trandomness = abs(randomness) < 0.01 ? 0.01 : randomness;",
"float skewed_uneven_bricks(vec2 uv, vec2 size, float randomness, float mortar, float bevel, float round, float corner, float seed, out vec3 brick_uv, out vec3 corner_uv, out vec4 brick_fill, out vec4 corner_fill) {",
"\tconst float grid_size = 4096.0;",
"\t",
"\t// Algorithm messes up at randomness 0.0",
"\trandomness = abs(randomness) < 0.001 ? 0.001 : randomness;",
"\t",
"\tuv = fract(uv);",
"\tvec2 scaled_uv = uv * size;",
Expand All @@ -100,15 +98,15 @@
"\t// Instead of creaing one value for each tile, we create two that we can use for a line",
"\t// to cut with.",
"\t// Two random values for each cell",
"\tvec2 current = skewed_uneven_cut(cell_id + seed, randomness);",
"\tvec2 top = skewed_uneven_cut( mod( cell_id + vec2(0.0, -1.0), size) + seed, randomness);",
"\tvec2 top_right = skewed_uneven_cut( mod( cell_id + vec2(1.0, -1.0) + seed, size), randomness);",
"\tvec2 right = skewed_uneven_cut( mod( cell_id + vec2(1.0, 0.0), size) + seed, randomness);",
"\tvec2 bottom_right = skewed_uneven_cut( mod( cell_id + vec2(1.0, 1.0) + seed, size), randomness);",
"\tvec2 bottom = skewed_uneven_cut( mod( cell_id + vec2(0.0, 1.0), size) + seed, randomness);",
"\tvec2 bottom_left = skewed_uneven_cut( mod( cell_id + vec2(-1.0, 1.0) + seed, size), randomness);",
"\tvec2 left = skewed_uneven_cut( mod( cell_id + vec2(-1.0, 0.0), size) + seed, randomness);",
"\tvec2 top_left = skewed_uneven_cut( mod( cell_id + vec2(-1.0, -1.0) + seed, size), randomness);",
"\tvec2 current = skewed_uneven_cut(cell_id + seed, size, randomness);",
"\tvec2 top = skewed_uneven_cut( cell_id + vec2(0.0, -1.0) + seed, size, randomness);",
"\tvec2 top_right = skewed_uneven_cut( cell_id + vec2(1.0, -1.0) + seed, size, randomness);",
"\tvec2 right = skewed_uneven_cut( cell_id + vec2(1.0, 0.0) + seed, size, randomness);",
"\tvec2 bottom_right = skewed_uneven_cut( cell_id + vec2(1.0, 1.0) + seed, size, randomness);",
"\tvec2 bottom = skewed_uneven_cut( cell_id + vec2(0.0, 1.0) + seed, size, randomness);",
"\tvec2 bottom_left = skewed_uneven_cut( cell_id + vec2(-1.0, 1.0) + seed, size, randomness);",
"\tvec2 left = skewed_uneven_cut( cell_id + vec2(-1.0, 0.0) + seed, size, randomness);",
"\tvec2 top_left = skewed_uneven_cut( cell_id + vec2(-1.0, -1.0) + seed, size, randomness);",
"",
"\tvec3 color = vec3(0.0);",
"\t",
Expand Down Expand Up @@ -239,10 +237,7 @@
"\tcorner_fill.xy = brick_uv.y < 0.5 ? top_centers : bottom_centers;",
"\tcorner_fill.xy -= half_corner_size;",
"\tcorner_fill.zw = vec2(half_corner_size * 2.0);",
"\tcorner_fill = fract(corner_fill);",
"\tcorner_fill *= 4096.0;",
"\tcorner_fill = round(corner_fill);",
"\tcorner_fill /= 4096.0;",
"\tcorner_fill = fract(round(corner_fill*grid_size)/grid_size);",
"",
"\t// Render the bricks",
"\tbevel /= max(size.x, size.y) / 2.0;",
Expand Down

0 comments on commit b1772a4

Please sign in to comment.