{
	"name": "curve",
	"node_position": {
		"x": 0,
		"y": 0
	},
	"parameters": {
		"ax": -0.4,
		"ay": -0.3,
		"bx": -0,
		"by": 0.5,
		"cx": 0.4,
		"cy": -0.3,
		"repeat": 1,
		"width": 0.05
	},
	"seed_int": 0,
	"shader_model": {
		"code": [
			"vec2 $(name_uv)_bezier = sdBezier($uv, vec2($ax+0.5, $ay+0.5), vec2($bx+0.5, $by+0.5), vec2($cx+0.5, $cy+0.5));",
			"vec2 $(name_uv)_uv = vec2($(name_uv)_bezier.x, $(name_uv)_bezier.y/$width+0.5);",
			"vec2 $(name_uv)_uvtest = step(vec2(0.5), abs($(name_uv)_uv-vec2(0.5)));",
			"$(name_uv)_uv = mix(vec2(fract($repeat*$(name_uv)_uv.x), $(name_uv)_uv.y), vec2(0.0), max($(name_uv)_uvtest.x, $(name_uv)_uvtest.y));",
			""
		],
		"global": [
			"float cross2( in vec2 a, in vec2 b ) { return a.x*b.y - a.y*b.x; }",
			"",
			"// signed distance to a quadratic bezier",
			"vec2 sdBezier( in vec2 pos, in vec2 A, in vec2 B, in vec2 C ) {\t",
			"\tvec2 a = B - A;",
			"\tvec2 b = A - 2.0*B + C;",
			"\tvec2 c = a * 2.0;",
			"\tvec2 d = A - pos;",
			"",
			"\tfloat kk = 1.0/dot(b,b);",
			"\tfloat kx = kk * dot(a,b);",
			"\tfloat ky = kk * (2.0*dot(a,a)+dot(d,b))/3.0;",
			"\tfloat kz = kk * dot(d,a);\t  ",
			"",
			"\tfloat res = 0.0;",
			"\tfloat sgn = 0.0;",
			"",
			"\tfloat p = ky - kx*kx;",
			"\tfloat p3 = p*p*p;",
			"\tfloat q = kx*(2.0*kx*kx - 3.0*ky) + kz;",
			"\tfloat h = q*q + 4.0*p3;",
			"\tfloat rvx;",
			"",
			"\tif( h>=0.0 ) { // 1 root",
			"\t\th = sqrt(h);",
			"\t\tvec2 x = (vec2(h,-h)-q)/2.0;",
			"\t\tvec2 uv = sign(x)*pow(abs(x), vec2(1.0/3.0));",
			"\t\trvx = uv.x+uv.y-kx;",
			"\t\tfloat t = clamp(rvx, 0.0, 1.0);",
			"\t\tvec2 q2 = d+(c+b*t)*t;",
			"\t\tres = dot(q2, q2);",
			"\t\tsgn = cross2(c+2.0*b*t, q2);",
			"\t} else {   // 3 roots",
			"\t\tfloat z = sqrt(-p);",
			"\t\tfloat v = acos(q/(p*z*2.0))/3.0;",
			"\t\tfloat m = cos(v);",
			"\t\tfloat n = sin(v)*1.732050808;",
			"\t\tvec3  t = clamp(vec3(m+m,-n-m,n-m)*z-kx, 0.0, 1.0);",
			"\t\tvec2  qx=d+(c+b*t.x)*t.x; float dx=dot(qx, qx), sx = cross2(c+2.0*b*t.x,qx);",
			"\t\tvec2  qy=d+(c+b*t.y)*t.y; float dy=dot(qy, qy), sy = cross2(c+2.0*b*t.y,qy);",
			"\t\tif( dx<dy ) { res=dx; sgn=sx; rvx = t.x; } else { res=dy; sgn=sy; rvx = t.y; }",
			"\t}",
			"\t",
			"\treturn vec2(rvx, sqrt(res)*sign(sgn));",
			"}",
			""
		],
		"inputs": [
			{
				"default": "vec4(vec3(step(abs($uv.y-0.5), 0.4999)), 1.0)",
				"label": "",
				"longdesc": "Input pattern to be drawn along the curve",
				"name": "in",
				"shortdesc": "Pattern",
				"type": "rgba"
			}
		],
		"instance": "",
		"name": "Curve",
		"outputs": [
			{
				"longdesc": "An image showing the specified curve",
				"rgba": "$in($(name_uv)_uv)",
				"shortdesc": "Output",
				"type": "rgba"
			}
		],
		"parameters": [
			{
				"control": "P1.x",
				"default": -0.3,
				"label": "AX",
				"longdesc": "Position on X axis of the first control point",
				"max": 0.5,
				"min": -0.5,
				"name": "ax",
				"shortdesc": "A.x",
				"step": 0.01,
				"type": "float"
			},
			{
				"control": "P1.y",
				"default": -0.1,
				"label": "AY",
				"longdesc": "Position on Y axis of the first control point",
				"max": 0.5,
				"min": -0.5,
				"name": "ay",
				"shortdesc": "A.y",
				"step": 0.01,
				"type": "float"
			},
			{
				"control": "P3.x",
				"default": -0,
				"label": "BX",
				"longdesc": "Position on X axis of the second control point",
				"max": 0.5,
				"min": -0.5,
				"name": "bx",
				"shortdesc": "B.x",
				"step": 0.01,
				"type": "float"
			},
			{
				"control": "P3.y",
				"default": 0.2,
				"label": "BY",
				"longdesc": "Position on Y axis of the second control point",
				"max": 0.5,
				"min": -0.5,
				"name": "by",
				"shortdesc": "B.y",
				"step": 0.01,
				"type": "float"
			},
			{
				"control": "P2.x",
				"default": 0.3,
				"label": "CX",
				"longdesc": "Position on X axis of the third control point",
				"max": 0.5,
				"min": -0.5,
				"name": "cx",
				"shortdesc": "C.x",
				"step": 0.01,
				"type": "float"
			},
			{
				"control": "P2.y",
				"default": -0.1,
				"label": "CY",
				"longdesc": "Position on Y axis of the third control point",
				"max": 0.5,
				"min": -0.5,
				"name": "cy",
				"shortdesc": "C.y",
				"step": 0.01,
				"type": "float"
			},
			{
				"control": "None",
				"default": 0.1,
				"label": "Width",
				"longdesc": "Width of the curve pattern",
				"max": 0.5,
				"min": 0,
				"name": "width",
				"shortdesc": "Width",
				"step": 0.01,
				"type": "float"
			},
			{
				"control": "None",
				"default": 1,
				"label": "Repeat",
				"longdesc": "Number of repetitions of the input pattern",
				"max": 16,
				"min": 1,
				"name": "repeat",
				"shortdesc": "Repeat",
				"step": 1,
				"type": "float"
			}
		],
		"shortdesc": "Curve",
		"longdesc": "Quadratic bezier curve with image mapping"
	},
	"type": "shader"
}