{
	"name": "roman_numerals3",
	"node_position": {
		"x": 0,
		"y": 0
	},
	"parameters": {
		"a": 0.5,
		"bevel": 0.1,
		"h": 0.75,
		"n": 5,
		"r": 0.05,
		"s": 0,
		"w": 0.5
	},
	"seed_int": 0,
	"shader_model": {
		"code": "",
		"global": [
			"float roman2_num(vec2 p, float w, float h, float s, int n) {",
			"\tif (n == 0) { // I",
			"\t\tfloat d = sdLine(abs(p), vec2(w*1.7,h), vec2(0,h)).x;",
			"\t\treturn min(d,sdLine(vec2(p.x,abs(p.y)), vec2(0,h), vec2(0,0)).x);",
			"\t} else if (n == 1) { // V",
			"\t\tp.x = abs(p.x);",
			"\t\tfloat d = sdLine(p, vec2(0,h), vec2(w,-h)).x;",
			"\t\treturn min(d, sdLine(vec2(abs(p.x-w),p.y+h), vec2(w*0.8,0), vec2(0,0)).x);",
			"\t} else if (n == 2) { // X",
			"\t\tp = abs(p);",
			"\t\tfloat d = sdLine(p, vec2(w,h), vec2(0,0)).x;",
			"\t\treturn min(d, sdLine(abs(p-vec2(w,h)), vec2(w*0.8,0), vec2(0,0)).x);",
			"\t} else if (n == 3) { // L",
			"\t\tfloat w2 = w*1.5;",
			"\t\tfloat d = sdLine(p, vec2(-w2,h), vec2(-w2,-h)).x;",
			"\t\treturn min(d, sdLine(p, vec2(-w2,h), vec2(w2,h)).x);",
			"\t} else if (n == 4) { // C",
			"\t\tvec2 b = vec2(w*1.5, h);",
			"\t\tvec4 r = 1.6*min(w, h)*vec4(1.0, 1.0, 1.0, 1.0);",
			"\t\tfloat d = sdRoundedBox(p, b, r);",
			"\t\treturn length(vec2(d, mix(clamp((p.x-abs(2.0*p.y)+h-w)/2.0, 0.0, 1.0), 0.0, step(p.x, 0.0))));",
			"\t} else if (n == 5) { // D",
			"\t\tvec2 b = vec2(w*1.5, h);",
			"\t\tvec4 r = 1.5*min(w, h)*vec4(1.0, 1.0, 0.0, 0.0);",
			"\t\treturn abs(sdRoundedBox(p, b, r));",
			"\t} else if (n == 6) { // M",
			"\t\tfloat w2 = w*1.5;",
			"\t\tfloat d = sdLine(p, vec2(-w2,h), vec2(-w2,-h)).x;",
			"\t\td = min(d, sdLine(p, vec2(w2,h), vec2(w2,-h)).x);",
			"\t\td = min(d, sdLine(p, vec2(w2,-h), vec2(0.0, 0.0)).x);",
			"\t\td = min(d, sdLine(p, vec2(-w2,-h), vec2(0.0, 0.0)).x);",
			"\t\treturn d;",
			"\t} else {",
			"\t\treturn 1.0;",
			"\t}",
			"}",
			"",
			"float roman2(vec2 p, float w, float h, int n, float bevel, float r, float s, float a)",
			"{",
			"\tp -= 0.5;",
			"\th *= 0.5;",
			"\tw *= 0.25;",
			"\tconst int val[] = { 1000, 900, 500, 400, 100, 90, 50, 40, 10,  9,  5,  4,  1};",
			"\tconst int c1[]  = {\t6,   4,   5,   4,   4,  2,  3,  2,  2,  0,  1,  0,  0};",
			"\tconst int c2[]  = {   -1,   6,  -1,   5,  -1,  4, -1,  3, -1,  2, -1,  1, -1};",
			"\tfloat res = 1.0;",
			"\tint n_clamped = clamp(n, 0, 3999);",
			"\tn = n_clamped;",
			"\tfloat total_width = 0.0;",
			"\tfor (int i = 0; i < 13; ++i) {",
			"\t\twhile (n - val[i] >= 0) {",
			"\t\t\ttotal_width += s;",
			"\t\t\tif (c2[i] != -1) {",
			"\t\t\t\ttotal_width += s;",
			"\t\t\t}",
			"\t\t\tn -= val[i]; ",
			"\t\t}",
			"\t}",
			"\tn = n_clamped;",
			"\tp.x += total_width*a;",
			"\tp.x -= 0.5*s;",
			"\tfor (int i = 0; i < 13; ++i) {",
			"\t\twhile (n - val[i] >= 0) {",
			"\t\t\tres = min(res, roman2_num(p,w,h,s,c1[i]));",
			"\t\t\tp -= vec2(s,0);",
			"\t\t\tif (c2[i] != -1) {",
			"\t\t\t\tres = min(res, roman2_num(p,w,h,s,c2[i]));",
			"\t\t\t\tp -= vec2(s,0);",
			"\t\t\t}",
			"\t\t\tn -= val[i]; ",
			"\t\t}",
			"\t}",
			"\treturn clamp(0.0-(res-0.5*r)/max(bevel*r, 1e-4), 0, 1);",
			"}"
		],
		"includes": [
			"sdline2",
			"sdroundedbox"
		],
		"inputs": [
			{
				"default": "1.0",
				"label": "4:",
				"longdesc": "Map that affects the number parameter",
				"name": "number_map",
				"shortdesc": "Number Map",
				"type": "f"
			},
			{
				"default": "1.0",
				"label": "5:",
				"longdesc": "Map that affects the bevel parameter",
				"name": "bevel_map",
				"shortdesc": "Bevel Map",
				"type": "f"
			}
		],
		"instance": "",
		"name": "Roman Numerals",
		"outputs": [
			{
				"f": "roman2($uv, $w, $h, int($n*$number_map($uv)), $bevel*$bevel_map($uv), $r*min($w, $h), (1.0+$s)*$w, $a)",
				"shortdesc": "Output",
				"type": "f"
			}
		],
		"parameters": [
			{
				"control": "None",
				"default": 0.5,
				"label": "Width",
				"max": 1,
				"min": 0,
				"name": "w",
				"shortdesc": "Glyph Width",
				"step": 0.01,
				"type": "float"
			},
			{
				"control": "None",
				"default": 0.5,
				"label": "Height",
				"max": 1,
				"min": 0,
				"name": "h",
				"shortdesc": "Glyph Height",
				"step": 0.01,
				"type": "float"
			},
			{
				"control": "None",
				"default": 0.5,
				"label": "Thickness",
				"max": 1,
				"min": 0,
				"name": "r",
				"shortdesc": "Glyph Thickness",
				"step": 0.01,
				"type": "float"
			},
			{
				"control": "None",
				"default": 1,
				"label": "Number",
				"max": 399,
				"min": 1,
				"name": "n",
				"shortdesc": "Roman number to display",
				"step": 1,
				"type": "float"
			},
			{
				"control": "None",
				"default": 0.5,
				"label": "Bevel",
				"max": 1,
				"min": 0,
				"name": "bevel",
				"shortdesc": "Glyph edge width",
				"step": 0.01,
				"type": "float"
			},
			{
				"control": "None",
				"default": 0.5,
				"label": "Spacing",
				"max": 1,
				"min": 0,
				"name": "s",
				"shortdesc": "Spacing between glyphs",
				"step": 0.01,
				"type": "float"
			},
			{
				"control": "None",
				"default": 0.5,
				"label": "Align",
				"max": 1,
				"min": 0,
				"name": "a",
				"step": 0.01,
				"type": "float"
			}
		],
		"shortdesc": "Roman Numerals"
	},
	"type": "shader"
}
