{
	"connections": [
		{
			"from": "fill_iterate",
			"from_port": 0,
			"to": "iterate_buffer",
			"to_port": 1
		},
		{
			"from": "shape",
			"from_port": 0,
			"to": "gen_outputs",
			"to_port": 0
		},
		{
			"from": "iterate_buffer",
			"from_port": 0,
			"to": "shape",
			"to_port": 0
		},
		{
			"from": "fill_preprocess",
			"from_port": 0,
			"to": "iterate_buffer",
			"to_port": 0
		},
		{
			"from": "iterate_buffer",
			"from_port": 1,
			"to": "fill_iterate",
			"to_port": 0
		},
		{
			"from": "gen_inputs",
			"from_port": 0,
			"to": "buffer_3",
			"to_port": 0
		},
		{
			"from": "buffer_3",
			"from_port": 0,
			"to": "fill_iterate",
			"to_port": 1
		},
		{
			"from": "buffer_3",
			"from_port": 0,
			"to": "fill_preprocess",
			"to_port": 0
		}
	],
	"label": "Fill from Colors",
	"longdesc": "Fills areas defined by different colors in its input",
	"name": "fill_from_colors",
	"node_position": {
		"x": 0,
		"y": 0
	},
	"nodes": [
		{
			"name": "iterate_buffer",
			"node_position": {
				"x": -132.86264,
				"y": -341.841705
			},
			"parameters": {
				"autostop": true,
				"filter": false,
				"iterations": 50,
				"mipmap": false,
				"shrink": false,
				"size": 8
			},
			"seed": 29168,
			"seed_locked": true,
			"type": "iterate_buffer"
		},
		{
			"name": "gen_inputs",
			"node_position": {
				"x": -812.307068,
				"y": -366.662445
			},
			"parameters": {

			},
			"ports": [
				{
					"group_size": 0,
					"longdesc": "The input image whose colored areas must be filled",
					"name": "port0",
					"shortdesc": "Input",
					"type": "rgba"
				}
			],
			"seed": 58064,
			"type": "ios"
		},
		{
			"name": "gen_outputs",
			"node_position": {
				"x": 398.267273,
				"y": -401.662445
			},
			"parameters": {

			},
			"ports": [
				{
					"group_size": 0,
					"longdesc": "Generates fill data, to be connected to a fill companion node",
					"name": "port0",
					"shortdesc": "Output",
					"type": "fill"
				}
			],
			"seed": -4244,
			"type": "ios"
		},
		{
			"name": "gen_parameters",
			"node_position": {
				"x": -228.110138,
				"y": -560.509705
			},
			"parameters": {
				"size": 8
			},
			"seed": 52136,
			"type": "remote",
			"widgets": [
				{
					"label": "",
					"linked_widgets": [
						{
							"node": "iterate_buffer",
							"widget": "size"
						},
						{
							"node": "fill_preprocess",
							"widget": "s"
						},
						{
							"node": "fill_iterate",
							"widget": "s"
						},
						{
							"node": "buffer_3",
							"widget": "size"
						}
					],
					"longdesc": "The resolution of the input image",
					"name": "size",
					"shortdesc": "Size",
					"type": "linked_control"
				}
			]
		},
		{
			"name": "fill_iterate",
			"node_position": {
				"x": -89.524506,
				"y": -203.609192
			},
			"parameters": {
				"s": 8
			},
			"seed": 11778,
			"shader_model": {
				"code": "",
				"global": "",
				"inputs": [
					{
						"default": "vec4(0.0)",
						"function": true,
						"label": "",
						"name": "in",
						"type": "rgba"
					},
					{
						"default": "vec4(0.0)",
						"function": true,
						"label": "",
						"name": "colors",
						"type": "rgba"
					}
				],
				"instance": [
					"vec4 $(name)_fill(vec2 uv) {",
					"\tvec4 ref_color = $colors(uv);",
					"\tfloat size = $s;",
					"\tint iterations = min(int(size), 1024);",
					"\tvec4 color = $in(fract(uv));",
					"\tif (color.z+color.w < 1.0/size) {",
					"\t\treturn vec4(0.0);",
					"\t}",
					"\tvec2 offsets[4] = { vec2(1.0, 1.0), vec2(-1.0, 1.0), vec2(-1.0, -1.0), vec2(1.0, -1.0) };",
					"\tvec2 mult_base = vec2(1.0, 0.0);",
					"\tfor (int o = 0; o < 4; ++o) {",
					"\t\tvec2 offset = offsets[o]/size;",
					"\t\tvec2 mult = mult_base;",
					"\t\tfor (int d = 0; d < 2; ++d) {",
					"\t\t\tvec2 uv2 = uv;",
					"\t\t\tint l = 0;",
					"\t\t\tfor (int i = 1; i < iterations; i += 1) {",
					"\t\t\t\tvec2 uv2_save = uv2;",
					"\t\t\t\tuv2 += offset*mult;",
					"\t\t\t\tvec4 color2 = $in(fract(uv2));",
					"\t\t\t\tif (ref_color != $colors(fract(uv2))) {",
					"\t\t\t\t\tif (l < 1) {",
					"\t\t\t\t\t\tmult = mult.yx;",
					"\t\t\t\t\t\tl += 1;",
					"\t\t\t\t\t\tuv2 = uv2_save;",
					"\t\t\t\t\t\tcontinue;",
					"\t\t\t\t\t}",
					"\t\t\t\t\tbreak;",
					"\t\t\t\t}",
					"\t\t\t\tl = 0;",
					"\t\t\t\tvec2 p1 = color.xy+floor(uv-color.xy);",
					"\t\t\t\tvec2 p2 = color2.xy+floor(uv2-color2.xy);",
					"\t\t\t\tvec2 p = min(p1, p2);",
					"\t\t\t\tvec2 s = max(p1+color.zw, p2+color2.zw)-p;",
					"\t\t\t\tcolor = mix(vec4(0.0, 0.0, 1.0, 1.0), vec4(fract(p), s), step(s.xyxy, vec4(1.0)));",
					"\t\t\t}",
					"\t\t\tmult = mult_base.yx;",
					"\t\t}",
					"\t}",
					"\treturn floor(color*size)/size;",
					"}",
					""
				],
				"name": "Fill iterate",
				"outputs": [
					{
						"rgba": "$(name)_fill($uv)",
						"type": "rgba"
					}
				],
				"parameters": [
					{
						"default": 9,
						"first": 6,
						"label": "",
						"last": 12,
						"name": "s",
						"type": "size"
					}
				]
			},
			"type": "shader"
		},
		{
			"name": "fill_preprocess",
			"node_position": {
				"x": -107.443481,
				"y": -429.202026
			},
			"parameters": {
				"s": 8
			},
			"seed": 24315,
			"shader_model": {
				"code": "",
				"global": "",
				"inputs": [
					{
						"default": "vec4(0.0)",
						"label": "",
						"name": "trigger",
						"type": "rgba"
					}
				],
				"instance": "",
				"name": "Fill preprocess",
				"outputs": [
					{
						"rgba": "vec4(floor($uv*$s)/$s, vec2(1.0/$s))",
						"type": "rgba"
					}
				],
				"parameters": [
					{
						"default": 10,
						"first": 0,
						"label": "",
						"last": 12,
						"name": "s",
						"type": "size"
					}
				]
			},
			"type": "shader"
		},
		{
			"name": "shape",
			"node_position": {
				"x": 176.919922,
				"y": -400.122955
			},
			"parameters": {

			},
			"seed_int": 0,
			"shader_model": {
				"code": "",
				"inputs": [
					{
						"default": "1.0",
						"label": "",
						"name": "in",
						"type": "rgba"
					}
				],
				"instance": "",
				"name": "Fill Convert",
				"outputs": [
					{
						"fill": "$in($(uv))",
						"type": "fill"
					}
				],
				"parameters": [

				]
			},
			"type": "shader"
		},
		{
			"name": "buffer_3",
			"node_position": {
				"x": -407.640808,
				"y": -328.542969
			},
			"parameters": {
				"filter": false,
				"mipmap": false,
				"size": 8
			},
			"seed_int": 0,
			"type": "buffer",
			"version": 2
		}
	],
	"parameters": {
		"size": 8
	},
	"seed_int": 0,
	"shortdesc": "Fill from Colors",
	"type": "graph"
}