{
	"name": "bricks3",
	"node_position": {
		"x": 0,
		"y": 0
	},
	"parameters": {
		"bevel": 0.1,
		"columns": 3,
		"corner": 0.3,
		"mortar": 0.1,
		"pattern": 0,
		"repeat": 1,
		"round": 0,
		"row_offset": 0.5,
		"rows": 6
	},
	"seed_int": 0,
	"shader_model": {
		"code": [
			"vec4 $(name_uv)_rect = bricks_$pattern($uv, vec2($columns, $rows), $repeat, $row_offset);",
			"vec4 $(name_uv) = brick($uv, $(name_uv)_rect.xy, $(name_uv)_rect.zw, $mortar*$mortar_map($uv), $round*$round_map($uv), max(0.001, $bevel*$bevel_map($uv)), 1.0 / $rows);"
		],
		"global": [
			"vec4 brick(vec2 uv, vec2 bmin, vec2 bmax, float mortar, float round_radius, float bevel, float brick_height) {",
			"\tfloat color;",
			"\tvec2 size = bmax - bmin;",
			"\tfloat min_size = min(size.x, size.y);",
			"",
			"\tmortar *= brick_height;",
			"\tbevel *= brick_height;",
			"\tround_radius *= brick_height;",
			"",
			"\tvec2 center = 0.5*(bmin+bmax);",
			"\tvec2 d = abs(uv-center)-0.5*(size)+vec2(round_radius+mortar);",
			"\tcolor = length(max(d,vec2(0))) + min(max(d.x,d.y),0.0)-round_radius;",
			"\tcolor = clamp(-color/bevel, 0.0, 1.0);",
			"\tvec2 tiled_brick_pos = mod(bmin, vec2(1.0, 1.0));",
			"\treturn vec4(color, center, tiled_brick_pos.x+7.0*tiled_brick_pos.y);",
			"}",
			"",
			"vec4 brick_corner_bb(vec2 uv, vec2 bmin, vec2 bmax, float mortar, float corner, float brick_height) {",
			"\tvec2 center = 0.5*(bmin + bmax);",
			"\tvec2 size = bmax - bmin;",
			"\tfloat max_size = max(size.x, size.y);",
			"\tfloat min_size = min(size.x, size.y);",
			"",
			"\tmortar *= brick_height;",
			"\tcorner *= brick_height;",
			"\t",
			"\tvec2 corner1 = vec2(bmin + mortar);",
			"\tvec2 corner2 = vec2(bmax.x - mortar - corner, bmin.y + mortar);",
			"\tvec2 corner3 = vec2(bmin.x + mortar, bmax.y - mortar - corner);",
			"\tvec2 corner4 = vec2(bmax - mortar - corner);",
			"\tvec2 top = uv.x < center.x ? corner1 : corner2;",
			"\tvec2 bottom = uv.x < center.x ? corner3 : corner4;",
			"\tvec2 positions = uv.y < center.y ? top : bottom;",
			"\treturn vec4(round(fract(positions)*4096.0)/4096.0, corner, corner);",
			"}",
			"",
			"vec4 bricks_rb(vec2 uv, vec2 count, float repeat, float offset) {",
			"\tcount *= repeat;",
			"\tfloat x_offset = offset*step(0.5, fract(uv.y*count.y*0.5));",
			"\tvec2 bmin = floor(vec2(uv.x*count.x-x_offset, uv.y*count.y));",
			"\tbmin.x += x_offset;",
			"\tbmin /= count;",
			"\treturn vec4(bmin, bmin+vec2(1.0)/count);",
			"}",
			"",
			"vec4 bricks_rb2(vec2 uv, vec2 count, float repeat, float offset) {",
			"\tcount *= repeat;",
			"\tfloat x_offset = offset*step(0.5, fract(uv.y*count.y*0.5));",
			"\tcount.x = count.x*(1.0+step(0.5, fract(uv.y*count.y*0.5)));",
			"\tvec2 bmin = floor(vec2(uv.x*count.x-x_offset, uv.y*count.y));",
			"\tbmin.x += x_offset;",
			"\tbmin /= count;",
			"\treturn vec4(bmin, bmin+vec2(1.0)/count);",
			"}",
			"",
			"vec4 bricks_rb3(vec2 uv, vec2 count, float repeat, float offset) {",
			"\tvec4 bb = bricks_rb(uv, count, repeat, offset);",
			"\t",
			"\tif ( (uv.x - bb.x) / (bb.z - bb.x) < 1.0/3.0) {",
			"\t\tbb.z = bb.x + (bb.z - bb.x) / 3.0;",
			"\t} else {",
			"\t\tbb.x = bb.x + (bb.z - bb.x) / 3.0;",
			"\t}",
			"\treturn bb;",
			"}",
			"",
			"vec4 bricks_hb(vec2 uv, vec2 count, float repeat, float offset) {",
			"\tfloat pc = count.x+count.y;",
			"\tfloat c = pc*repeat;",
			"\tvec2 corner = floor(uv*c);",
			"\tfloat cdiff = mod(corner.x-corner.y, pc);",
			"\tif (cdiff < count.x) {",
			"\t\treturn vec4((corner-vec2(cdiff, 0.0))/c, (corner-vec2(cdiff, 0.0)+vec2(count.x, 1.0))/c);",
			"\t} else {",
			"\t\treturn vec4((corner-vec2(0.0, pc-cdiff-1.0))/c, (corner-vec2(0.0, pc-cdiff-1.0)+vec2(1.0, count.y))/c);",
			"\t}",
			"}",
			"",
			"vec4 bricks_bw(vec2 uv, vec2 count, float repeat, float offset) {",
			"\tvec2 c = 2.0*count*repeat;",
			"\tfloat mc = max(c.x, c.y);",
			"\tvec2 corner1 = floor(uv*c);",
			"\tvec2 corner2 = count*floor(repeat*2.0*uv);",
			"\tfloat cdiff = mod(dot(floor(repeat*2.0*uv), vec2(1.0)), 2.0);",
			"\tvec2 corner;",
			"\tvec2 size;",
			"\tif (cdiff == 0.0) {",
			"\t\tcorner = vec2(corner1.x, corner2.y);",
			"\t\tsize = vec2(1.0, count.y);",
			"\t} else {",
			"\t\tcorner = vec2(corner2.x, corner1.y);",
			"\t\tsize = vec2(count.x, 1.0);",
			"\t}",
			"\treturn vec4(corner/c, (corner+size)/c);",
			"}",
			"",
			"vec4 bricks_sb(vec2 uv, vec2 count, float repeat, float offset) {",
			"\tvec2 c = (count+vec2(1.0)) * repeat;",
			"\tfloat mc = max(c.x, c.y);",
			"\tvec2 corner1 = floor(uv*c);",
			"\tvec2 corner2 = (count+vec2(1.0))*floor(repeat*uv);",
			"\tvec2 rcorner = corner1 - corner2;",
			"\tvec2 corner;",
			"\tvec2 size;",
			"\tif (rcorner.x == 0.0 && rcorner.y < count.y) {",
			"\t\tcorner = corner2;",
			"\t\tsize = vec2(1.0, count.y);",
			"\t} else if (rcorner.y == 0.0) {",
			"\t\tcorner = corner2+vec2(1.0, 0.0);",
			"\t\tsize = vec2(count.x, 1.0);",
			"\t} else if (rcorner.x == count.x) {",
			"\t\tcorner = corner2+vec2(count.x, 1.0);",
			"\t\tsize = vec2(1.0, count.y);",
			"\t} else if (rcorner.y == count.y) {",
			"\t\tcorner = corner2+vec2(0.0, count.y);",
			"\t\tsize = vec2(count.x, 1.0);",
			"\t} else {",
			"\t\tcorner = corner2+vec2(1.0);",
			"\t\tsize = vec2(count.x-1.0, count.y-1.0);",
			"\t}",
			"\treturn vec4(corner/c, (corner+size)/c);",
			"}"
		],
		"inputs": [
			{
				"default": "1.0",
				"label": "6:",
				"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 different bricks patterns, with many useful outputs.",
		"name": "Bricks",
		"outputs": [
			{
				"f": "$(name_uv).x",
				"longdesc": "A grayscale image that shows the bricks pattern",
				"shortdesc": "Bricks pattern",
				"type": "f"
			},
			{
				"fill": "round(vec4(fract($(name_uv)_rect.xy), $(name_uv)_rect.zw - $(name_uv)_rect.xy)*4096.0)/4096.0",
				"longdesc": "An output that should be plugged into a Fill companion node",
				"shortdesc": "Brick Fill",
				"type": "fill"
			},
			{
				"fill": "brick_corner_bb($uv, $(name_uv)_rect.xy, $(name_uv)_rect.zw, $mortar*$mortar_map($uv), $corner, 1.0 / $rows)",
				"longdesc": "An output that should be plugged into a Fill companion node",
				"shortdesc": "Corner Fill",
				"type": "fill"
			}
		],
		"parameters": [
			{
				"default": 2,
				"label": "",
				"longdesc": "The type of brick pattern",
				"name": "pattern",
				"shortdesc": "Pattern",
				"type": "enum",
				"values": [
					{
						"name": "Running Bond",
						"value": "rb"
					},
					{
						"name": "English Bond",
						"value": "rb2"
					},
					{
						"name": "Flemish Bond",
						"value": "rb3"
					},
					{
						"name": "Herringbone",
						"value": "hb"
					},
					{
						"name": "Basket Weave",
						"value": "bw"
					},
					{
						"name": "Spanish Bond",
						"value": "sb"
					}
				]
			},
			{
				"control": "None",
				"default": 1,
				"label": "Repeat",
				"longdesc": "The number of repetitions of the whole pattern",
				"max": 8,
				"min": 1,
				"name": "repeat",
				"shortdesc": "Repeat",
				"step": 1,
				"type": "float"
			},
			{
				"control": "None",
				"default": 6,
				"label": "Rows",
				"longdesc": "The number of rows of a pattern",
				"max": 64,
				"min": 1,
				"name": "rows",
				"shortdesc": "Rows",
				"step": 1,
				"type": "float"
			},
			{
				"control": "None",
				"default": 3,
				"label": "Columns",
				"longdesc": "The number of columns of a pattern",
				"max": 64,
				"min": 1,
				"name": "columns",
				"shortdesc": "Columns",
				"step": 1,
				"type": "float"
			},
			{
				"control": "None",
				"default": 0.5,
				"label": "Offset",
				"longdesc": "The offset of the pattern (not useful for all patterns)",
				"max": 1,
				"min": 0,
				"name": "row_offset",
				"shortdesc": "Offset",
				"step": 0.01,
				"type": "float"
			},
			{
				"control": "None",
				"default": 0.1,
				"label": "Mortar",
				"longdesc": "The width of the space between bricks",
				"max": 0.5,
				"min": 0,
				"name": "mortar",
				"shortdesc": "Mortar",
				"step": 0.01,
				"type": "float"
			},
			{
				"control": "None",
				"default": 0.1,
				"label": "Bevel",
				"longdesc": "The width of the edge of each brick",
				"max": 0.5,
				"min": 0,
				"name": "bevel",
				"shortdesc": "Bevel",
				"step": 0.01,
				"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": "Simple bricks patterns"
	},
	"type": "shader"
}