{
	"connections": [
		{
			"from": "6520",
			"from_port": 0,
			"to": "gen_outputs",
			"to_port": 0
		},
		{
			"from": "edge_detect",
			"from_port": 0,
			"to": "1823",
			"to_port": 0
		},
		{
			"from": "gen_inputs",
			"from_port": 0,
			"to": "buffer_2",
			"to_port": 0
		},
		{
			"from": "buffer_2",
			"from_port": 0,
			"to": "6520",
			"to_port": 1
		},
		{
			"from": "buffer_2",
			"from_port": 0,
			"to": "tones_step",
			"to_port": 0
		},
		{
			"from": "tones_step",
			"from_port": 0,
			"to": "edge_detect",
			"to_port": 0
		},
		{
			"from": "1823",
			"from_port": 0,
			"to": "iterate_buffer",
			"to_port": 0
		},
		{
			"from": "2434_8",
			"from_port": 0,
			"to": "iterate_buffer",
			"to_port": 1
		},
		{
			"from": "24282_2",
			"from_port": 0,
			"to": "2434_8",
			"to_port": 0
		},
		{
			"from": "iterate_buffer",
			"from_port": 1,
			"to": "24282_2",
			"to_port": 0
		},
		{
			"from": "iterate_buffer",
			"from_port": 0,
			"to": "shader_2",
			"to_port": 0
		},
		{
			"from": "shader_2",
			"from_port": 0,
			"to": "6520",
			"to_port": 0
		}
	],
	"label": "Mask to SDF",
	"longdesc": "Generates a signed distance image from an image mask",
	"name": "sd_mask_to_sdf",
	"node_position": {
		"x": 0,
		"y": 0
	},
	"nodes": [
		{
			"name": "iterate_buffer",
			"node_position": {
				"x": 9.70000457763672,
				"y": -328.817047119141
			},
			"parameters": {
				"autostop": false,
				"f32": false,
				"filter": false,
				"iterations": 30.0,
				"mipmap": false,
				"shrink": false,
				"size": 10.0
			},
			"seed": 29168.0,
			"seed_locked": true,
			"type": "iterate_buffer"
		},
		{
			"name": "2434_8",
			"node_position": {
				"x": 91.0999908447266,
				"y": -9.03147888183594
			},
			"parameters": {
				"distance": 0.0,
				"size": 10.0
			},
			"seed": -4110.0,
			"shader_model": {
				"code": "",
				"global": "",
				"inputs": [
					{
						"default": "vec3(-1.0)",
						"function": true,
						"label": "",
						"name": "in",
						"type": "rgb"
					}
				],
				"instance": [
					"vec3 $(name)_jump_flood(vec2 uv, float size) {",
					"\tivec2 int_uv = ivec2(uv * size);",
					"\tfloat best_distance = 9999.9;",
					"\tvec2 best_coord = vec2(0.0);",
					"\tfloat iter = $in(uv).b;",
					"\titer += 0.01;",
					"\tfloat step_width = size / 4.0 / (iter * 100.0);",
					"\t",
					"\tfor (int x = -1; x <= 1; x++) {",
					"\t\tfor (int y = -1; y <= 1; y++) {",
					"\t\t\tivec2 offsetUV = int_uv + ivec2(x, y) * int(step_width);",
					"\t\t\tvec2 float_uv = vec2(offsetUV) / size;",
					"\t\t\tvec2 offset_pos = $in(float_uv).rg;",
					"\t\t\t",
					"\t\t\tif (offset_pos.x != 0.0 && offset_pos.y != 0.0) {",
					"\t\t\t\tvec2 diff = offset_pos - uv;",
					"\t\t\t\t//float dist = dot(diff, diff);",
					"\t\t\t\t$distance",
					"\t\t\t\tif (dist < best_distance) {",
					"\t\t\t\t\tbest_distance = dist;",
					"\t\t\t\t\tbest_coord = offset_pos;",
					"\t\t\t\t}",
					"\t\t\t}",
					"\t\t}",
					"\t}",
					"\t",
					"\treturn vec3(best_coord, iter);",
					"}"
				],
				"name": "Jump Flood",
				"outputs": [
					{
						"rgb": "$(name)_jump_flood($uv, $size)",
						"type": "rgb"
					}
				],
				"parameters": [
					{
						"default": 10,
						"first": 0,
						"label": "",
						"last": 13,
						"name": "size",
						"type": "size"
					},
					{
						"default": 0.0,
						"label": "",
						"name": "distance",
						"type": "enum",
						"values": [
							{
								"name": "Euclidean",
								"value": "float dist = dot(diff, diff);"
							},
							{
								"name": "Manhattan",
								"value": "float dist = abs(diff.x) + abs(diff.y);"
							},
							{
								"name": "Chebyshev",
								"value": "float dist = abs(diff.x) > abs(diff.y) ? abs(diff.x) : abs(diff.y);"
							}
						]
					}
				]
			},
			"type": "shader"
		},
		{
			"name": "1823",
			"node_position": {
				"x": -269.899871826172,
				"y": -18.7417659759521
			},
			"parameters": {

			},
			"seed": 45955.0,
			"shader_model": {
				"code": "",
				"global": "",
				"inputs": [
					{
						"default": "1.0",
						"label": "",
						"name": "in",
						"type": "f"
					}
				],
				"instance": "",
				"name": "Mask to UV Mask",
				"outputs": [
					{
						"rgb": "$in($uv) < .5 ? vec3(0.0) : vec3($uv, 0.0)",
						"type": "rgb"
					}
				],
				"parameters": []
			},
			"type": "shader"
		},
		{
			"name": "edge_detect",
			"node_position": {
				"x": -286.951446533203,
				"y": -137.078964233398
			},
			"parameters": {
				"size": 10.0,
				"threshold": 0.4,
				"width": 1.0
			},
			"seed": 50217.0,
			"type": "edge_detect"
		},
		{
			"name": "6520",
			"node_position": {
				"x": 290.156524658203,
				"y": -232.873168945312
			},
			"parameters": {
				"distance": 0.0,
				"tiled": true
			},
			"seed": -16657.0,
			"shader_model": {
				"code": "",
				"global": "",
				"inputs": [
					{
						"default": "vec3(0.0)",
						"function": true,
						"label": "",
						"name": "in",
						"type": "rgb"
					},
					{
						"default": "0.0",
						"function": true,
						"label": "",
						"name": "mask",
						"type": "f"
					}
				],
				"instance": [
					"float $(name)_distance(vec2 uv, bool tiled) {",
					"\tif (tiled) {",
					"\t\tuv = fract(uv);",
					"\t}",
					"\tvec2 custom_uv = $in(uv).xy;",
					"\tvec2 diff = custom_uv != vec2(0.0) ? custom_uv - uv : vec2(1.0);",
					"\t$distance",
					"\tif (!tiled) {",
					"\t\tuv = clamp(uv, 0.0, 1.0);",
					"\t}",
					"\treturn $mask(uv) < 0.5 ? distance : -distance;",
					"}"
				],
				"name": "Calculate Distance",
				"outputs": [
					{
						"sdf2d": "$(name)_distance($uv, $tiled)",
						"type": "sdf2d"
					}
				],
				"parameters": [
					{
						"default": false,
						"label": "Tiled",
						"name": "tiled",
						"type": "boolean"
					},
					{
						"default": 0.0,
						"label": "",
						"name": "distance",
						"type": "enum",
						"values": [
							{
								"name": "Euclidean",
								"value": "float distance = length(diff);"
							},
							{
								"name": "Manhattan",
								"value": "float distance = abs(diff.x) + abs(diff.y);"
							},
							{
								"name": "Chebyshev",
								"value": "float distance = abs(diff.x) > abs(diff.y) ? abs(diff.x) : abs(diff.y);"
							}
						]
					}
				]
			},
			"type": "shader"
		},
		{
			"name": "gen_inputs",
			"node_position": {
				"x": -735.851440429688,
				"y": -352.006774902344
			},
			"parameters": {

			},
			"ports": [
				{
					"group_size": 0.0,
					"longdesc": "The grayscale mask to be converted",
					"name": "mask",
					"shortdesc": "Mask",
					"type": "f"
				}
			],
			"seed": 23391.0,
			"type": "ios"
		},
		{
			"name": "gen_outputs",
			"node_position": {
				"x": 568.25634765625,
				"y": -246.285461425781
			},
			"parameters": {

			},
			"ports": [
				{
					"group_size": 0.0,
					"longdesc": "The genrated distance field",
					"name": "sdf",
					"shortdesc": "Output",
					"type": "sdf2d"
				}
			],
			"seed": -35133.0,
			"type": "ios"
		},
		{
			"name": "gen_parameters",
			"node_position": {
				"x": -47.6795196533203,
				"y": -541.979187011719
			},
			"parameters": {
				"param0": 10.0,
				"param1": 30.0,
				"param2": true,
				"param3": 0.0
			},
			"seed": 46252.0,
			"type": "remote",
			"widgets": [
				{
					"label": "Size",
					"linked_widgets": [
						{
							"node": "iterate_buffer",
							"widget": "size"
						},
						{
							"node": "2434_8",
							"widget": "size"
						},
						{
							"node": "buffer_2",
							"widget": "size"
						},
						{
							"node": "edge_detect",
							"widget": "size"
						}
					],
					"longdesc": "The resolution used for the operation",
					"name": "param0",
					"shortdesc": "Size",
					"type": "linked_control"
				},
				{
					"label": "Iterations",
					"linked_widgets": [
						{
							"node": "iterate_buffer",
							"widget": "iterations"
						}
					],
					"longdesc": "The number of iterations the jump flood algorithm performs to calculate the distances",
					"name": "param1",
					"shortdesc": "Iterations",
					"type": "linked_control"
				},
				{
					"label": "Tiled",
					"linked_widgets": [
						{
							"node": "24282_2",
							"widget": "tiled"
						},
						{
							"node": "6520",
							"widget": "tiled"
						},
						{
							"node": "shader_2",
							"widget": "tiled"
						}
					],
					"name": "param2",
					"type": "linked_control"
				},
				{
					"label": "Distance",
					"linked_widgets": [
						{
							"node": "2434_8",
							"widget": "distance"
						},
						{
							"node": "6520",
							"widget": "distance"
						}
					],
					"name": "param3",
					"shortdesc": "Distance function",
					"type": "linked_control"
				}
			]
		},
		{
			"name": "buffer_2",
			"node_position": {
				"x": -297.702789306641,
				"y": -348.413909912109
			},
			"parameters": {
				"size": 10.0
			},
			"seed": 7085.0,
			"type": "buffer",
			"version": 1
		},
		{
			"name": "tones_step",
			"node_position": {
				"x": -294.947967529297,
				"y": -258.845489501953
			},
			"parameters": {
				"invert": false,
				"value": 0.5,
				"width": 0.0
			},
			"seed": 48280.0,
			"type": "tones_step"
		},
		{
			"name": "24282_2",
			"node_position": {
				"x": 114.391708374023,
				"y": -90.7657318115234
			},
			"parameters": {
				"tiled": true
			},
			"seed": -56216.0,
			"shader_model": {
				"code": [
					"vec3 $(name_uv)_in = $in(fract($uv));",
					"vec3 $(name_uv)_tiled = $(name_uv)_in.xy != vec2(0.0) ? $(name_uv)_in + vec3(floor($uv), 0.0) : $(name_uv)_in;"
				],
				"global": "",
				"inputs": [
					{
						"default": "vec3(1.0)",
						"function": true,
						"label": "",
						"name": "in",
						"type": "rgb"
					}
				],
				"instance": "",
				"name": "Tiling",
				"outputs": [
					{
						"rgb": "$tiled ? $(name_uv)_tiled : $(name_uv)_in",
						"type": "rgb"
					}
				],
				"parameters": [
					{
						"default": false,
						"label": "Tiled",
						"name": "tiled",
						"type": "boolean"
					}
				]
			},
			"type": "shader"
		},
		{
			"name": "shader_2",
			"node_position": {
				"x": 265.37158203125,
				"y": -316.934143066406
			},
			"parameters": {
				"tiled": true
			},
			"seed_int": 0,
			"shader_model": {
				"code": "",
				"global": "",
				"includes": [
					"scale"
				],
				"inputs": [
					{
						"default": "0.0",
						"label": "",
						"name": "in",
						"type": "rgb"
					}
				],
				"instance": "",
				"name": "Fix Untiled",
				"outputs": [
					{
						"rgb": "$tiled ? $in($uv) : $in(clamp($uv,vec2(0.0), vec2(0.999)))",
						"type": "rgb"
					}
				],
				"parameters": [
					{
						"default": false,
						"label": "Tiled",
						"name": "tiled",
						"type": "boolean"
					}
				]
			},
			"type": "shader"
		}
	],
	"parameters": {
		"param0": 10.0,
		"param1": 30.0,
		"param2": true,
		"param3": 0.0
	},
	"seed_int": 0,
	"shortdesc": "Mask to SDF",
	"type": "graph"
}