{
	"name": "bricks_uneven",
	"node_position": {
		"x": 0,
		"y": 0
	},
	"parameters": {
		"bevel": 0.01,
		"corner": 0,
		"iterations": 8,
		"min_size": 0.3,
		"mortar": 0.01,
		"randomness": 0.5,
		"round": 0
	},
	"shader_model": {
		"code": "vec4 $(name_uv)_rect = bricks_uneven($uv, int($iterations), $min_size, $randomness, float($seed));\nvec4 $(name_uv) = brick2($uv, $(name_uv)_rect.xy, $(name_uv)_rect.zw, $mortar*$mortar_map($uv), $round*$round_map($uv), max(0.00001, $bevel*$bevel_map($uv)));\n",
		"global": "vec4 brick2(vec2 uv, vec2 bmin, vec2 bmax, float mortar, float round, float bevel) {\n\tfloat color;\n\tvec2 size = bmax - bmin;\n\tvec2 center = 0.5*(bmin+bmax);\n    vec2 d = abs(uv-center)-0.5*(size)+vec2(round+mortar);\n    color = length(max(d,vec2(0))) + min(max(d.x,d.y),0.0)-round;\n\tcolor = clamp(-color/bevel, 0.0, 1.0);\n\tvec2 tiled_brick_pos = mod(bmin, vec2(1.0, 1.0));\n\treturn vec4(color, center, tiled_brick_pos.x+7.0*tiled_brick_pos.y);\n}\n\nvec4 bricks_uneven(vec2 uv, int iterations, float min_size, float randomness, float seed) {\n\tvec2 a = vec2(0.0);\n\tvec2 b = vec2(1.0);\n\t\n\tfor (int i = 0; i < iterations; ++i) {\n\t\tvec2 size = b-a;\n\t\tif (max(size.x, size.y) < min_size) {\n\t\tbreak;\n\t\t}\n\t\tfloat x = rand(rand2(vec2(rand(a+b), seed)))*randomness+(1.0-randomness)*0.5;\n\t\tif (size.x > size.y) {\n\t\t\tx *= size.x;\n\t\t\tif (uv.x > a.x+x) {\n\t\t\t\ta.x += x;\n\t\t\t} else {\n\t\t\t\tb.x = a.x + x;\n\t\t\t}\n\t\t} else {\n\t\t\tx *= size.y;\n\t\t\tif (uv.y > a.y+x) {\n\t\t\t\ta.y += x;\n\t\t\t} else {\n\t\t\t\tb.y = a.y + x;\n\t\t\t}\n\t\t}\n\t}\n\treturn vec4(a, b);\n}\n",
		"includes": [
			"bricks"
		],
		"inputs": [
			{
				"default": "1.0",
				"label": "4:",
				"longdesc": "A map that affects the Mortar parameter",
				"name": "mortar_map",
				"shortdesc": "Mortar map",
				"type": "f"
			},
			{
				"default": "1.0",
				"label": "",
				"longdesc": "A map that affects the Bevel parameter",
				"name": "bevel_map",
				"shortdesc": "Bevel map",
				"type": "f"
			},
			{
				"default": "1.0",
				"label": "",
				"longdesc": "A map that affects the Round parameter",
				"name": "round_map",
				"shortdesc": "Round map",
				"type": "f"
			}
		],
		"instance": "",
		"longdesc": "Generates an uneven bricks pattern.",
		"name": "Uneven Bricks",
		"outputs": [
			{
				"f": "$(name_uv).x",
				"longdesc": "A greyscale image that shows the bricks pattern",
				"shortdesc": "Bricks pattern",
				"type": "f"
			},
			{
				"longdesc": "A random color for each brick",
				"rgb": "rand3(fract($(name_uv)_rect.xy)+rand2(vec2(float($seed))))",
				"shortdesc": "Random color",
				"type": "rgb"
			},
			{
				"f": "$(name_uv).y",
				"longdesc": "The position of each brick along the X axis",
				"shortdesc": "Position.x",
				"type": "f"
			},
			{
				"f": "$(name_uv).z",
				"longdesc": "The position of each brick along the Y axis",
				"shortdesc": "Position.y",
				"type": "f"
			},
			{
				"longdesc": "An UV map output for each brick, to be connected to the Map input of a CustomUV node",
				"rgb": "brick_uv($uv, $(name_uv)_rect.xy, $(name_uv)_rect.zw, float($seed))",
				"shortdesc": "Brick UV",
				"type": "rgb"
			},
			{
				"longdesc": "An UV map output for each brick corner, to be connected to the Map input of a CustomUV node",
				"rgb": "brick_corner_uv($uv, $(name_uv)_rect.xy, $(name_uv)_rect.zw, $mortar*$mortar_map($uv), $corner, float($seed))",
				"shortdesc": "Corner UV",
				"type": "rgb"
			},
			{
				"f": "0.5*(sign($(name_uv)_rect.z-$(name_uv)_rect.x-$(name_uv)_rect.w+$(name_uv)_rect.y)+1.0)",
				"longdesc": "The direction of each brick (white: horizontal, black: vertical)",
				"shortdesc": "Direction",
				"type": "f"
			}
		],
		"parameters": [
			{
				"control": "None",
				"default": 8,
				"label": "Iterations",
				"longdesc": "The number of iterations of the brick split operation",
				"max": 16,
				"min": 1,
				"name": "iterations",
				"shortdesc": "Iterations",
				"step": 1,
				"type": "float"
			},
			{
				"control": "None",
				"default": 0.3,
				"label": "Min size:",
				"longdesc": "The minimum size of a brick",
				"max": 0.5,
				"min": 0,
				"name": "min_size",
				"shortdesc": "Minimum size",
				"step": 0.01,
				"type": "float"
			},
			{
				"control": "None",
				"default": 0.5,
				"label": "Randomness",
				"longdesc": "The randomness of the pattern",
				"max": 1,
				"min": 0,
				"name": "randomness",
				"shortdesc": "Randomness",
				"step": 0.01,
				"type": "float"
			},
			{
				"control": "None",
				"default": 0.05,
				"label": "Mortar:",
				"longdesc": "The width of the space between bricks",
				"max": 0.5,
				"min": 0,
				"name": "mortar",
				"shortdesc": "Mortar",
				"step": 0.001,
				"type": "float"
			},
			{
				"control": "None",
				"default": 0.05,
				"label": "Bevel:",
				"longdesc": "The width of the edge of each brick",
				"max": 0.5,
				"min": 0,
				"name": "bevel",
				"shortdesc": "Bevel",
				"step": 0.001,
				"type": "float"
			},
			{
				"control": "None",
				"default": 0,
				"label": "Round:",
				"longdesc": "The radius of the round corners of bricks",
				"max": 0.5,
				"min": 0,
				"name": "round",
				"shortdesc": "Round",
				"step": 0.01,
				"type": "float"
			},
			{
				"control": "None",
				"default": 0.1,
				"label": "Corner:",
				"longdesc": "The size of the corner part of each brick (only used by the Corner UV output)",
				"max": 0.5,
				"min": 0,
				"name": "corner",
				"shortdesc": "Corner",
				"step": 0.01,
				"type": "float"
			}
		],
		"shortdesc": "Uneven bricks"
	},
	"type": "shader"
}