{
	"name": "fill_iterate",
	"node_position": {
		"x": 0,
		"y": 0
	},
	"parameters": {
		"s": 9
	},
	"seed": 11778,
	"shader_model": {
		"code": "",
		"global": "",
		"inputs": [
			{
				"default": "0.0",
				"function": true,
				"label": "",
				"name": "in",
				"type": "rgba"
			}
		],
		"instance": [
			"vec4 $(name)_fill(vec2 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 (color2.z+color2.w == 0.0) {",
			"\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"
}