{
	"name": "sdpolygon",
	"node_position": {
		"x": 0,
		"y": 0
	},
	"parameters": {
		"polygon": {
			"points": [
				{
					"x": 0.2,
					"y": 0.2
				},
				{
					"x": 0.4,
					"y": 0.7
				},
				{
					"x": 0.7,
					"y": 0.4
				}
			],
			"type": "Polygon"
		}
	},
	"seed_int": 0,
	"shader_model": {
		"code": "",
		"global": "",
		"inputs": [

		],
		"instance": [
			"float sdPolygon_$(name)(vec2 p) {",
			"\tvec2 v[] = $polygon;",
			"\tint l = v.length();",
			"\tfloat d = dot(p-v[0],p-v[0]);",
			"\tfloat s = 1.0;",
			"\tint j = l-1;",
			"\tfor(int i=0; i<l; i++)",
			"\t{",
			"\t\tvec2 e = v[j] - v[i];",
			"\t\tvec2 w =\tp - v[i];",
			"\t\tvec2 b = w - e*clamp( dot(w,e)/dot(e,e), 0.0, 1.0 );",
			"\t\td = min( d, dot(b,b) );",
			"\t\tbvec3 c = bvec3(p.y>=v[i].y,p.y<v[j].y,e.x*w.y>e.y*w.x);",
			"\t\tif( all(c) || all(not(c)) ) s*=-1.0;",
			"\t\tj=i;",
			"\t}",
			"\treturn s*sqrt(d);",
			"}",
			""
		],
		"longdesc": "A polygon as a signed distance function",
		"name": "sdPolygon",
		"outputs": [
			{
				"longdesc": "The polygon as a signed distance function",
				"sdf2d": "sdPolygon_$(name)($uv)",
				"shortdesc": "Output",
				"type": "sdf2d"
			}
		],
		"parameters": [
			{
				"default": {
					"points": [
						{
							"x": 0.2,
							"y": 0.2
						},
						{
							"x": 0.4,
							"y": 0.7
						},
						{
							"x": 0.7,
							"y": 0.4
						}
					],
					"type": "Polygon"
				},
				"label": "",
				"longdesc": "The polygon to be drawn",
				"name": "polygon",
				"shortdesc": "Polygon",
				"type": "polygon"
			}
		],
		"shortdesc": "sdPolygon"
	},
	"type": "shader"
}