{
	"name": "mesh",
	"node_position": {
		"x": 0,
		"y": 0
	},
	"parameters": {
		"diagonal": false,
		"shape": 0,
		"tiling": 2
	},
	"seed_int": 0,
	"shader_model": {
		"code": "vec3 $(name_uv)_pattern = $(name)_mesh_pattern($uv);",
		"global": [
			"float mesh_capsule(vec2 uv) {",
			"\tuv = uvmirror_h(uv, 0.25, 1.0);",
			"\treturn sin((1.0 - length(vec2(0.5) - uv) / .25) * 1.57);",
			"}",
			"",
			"float mesh_ridged_bell(vec2 uv) {",
			"\tuv = scale(uv, vec2(0.5), vec2(0.9, 0.5));",
			"\tuv = transform2_clamp(uv);",
			"\tfloat triangle = min(uv.y, 1.0 - uv.y) * 2.0;",
			"\ttriangle = 1.0 - sqrt(1.0 - pow(triangle, 2.0));",
			"\tfloat sine = 0.5 - 0.5 * cos(uv.x * 3.14159265359 * 2.0);",
			"\treturn triangle * sine;",
			"}",
			"",
			"float mesh_screen_blend(float back, float fore) {",
			"\treturn 1.0 - (1.0 - back) * (1.0 - fore);",
			"}"
		],
		"includes": [
			"mirror",
			"scale",
			"transform2"
		],
		"inputs": [
			{
				"default": "0.0",
				"function": true,
				"label": "",
				"longdesc": "Input a custom shape to be turned into a mesh pattern",
				"name": "in",
				"shortdesc": "Custom Shape",
				"type": "f"
			}
		],
		"instance": [
			"vec3 $(name)_mesh_pattern(vec2 uv) {",
			"\tuv *= $tiling;",
			"\tif ($diagonal) {",
			"\t\tuv = transform2(uv, vec2(0.0), 45.0 * 0.01745329251, vec2(1.0 / sqrt(2.0)));",
			"\t}",
			"\t",
			"\tfloat pattern = 0.0;",
			"\tfloat mask = 0.0;",
			"\t",
			"\tif ($shape == 0) {",
			"\t\tpattern = max(pattern, mesh_ridged_bell(fract(uv + vec2(0.5, 0.0))));",
			"\t\tpattern = max(pattern, mesh_ridged_bell(fract(uv + vec2(0.0, 0.5))));",
			"\t\tfloat pattern2 = mesh_ridged_bell(fract(uv.yx));",
			"\t\tpattern2 = max(pattern2, mesh_ridged_bell(fract(uv.yx + vec2(0.5, 0.5))));",
			"\t\tmask = float(pattern > pattern2);",
			"\t\tpattern = mesh_screen_blend(pattern, pattern2);",
			"\t} else if($shape == 1) {",
			"\t\tpattern = max(pattern, mesh_capsule(fract(uv + vec2(0.5, 0.0))));",
			"\t\tpattern = max(pattern, mesh_capsule(fract(uv + vec2(0.0, 0.5))));",
			"\t\tfloat pattern2 = mesh_capsule(fract(uv.yx));",
			"\t\tpattern2 = max(pattern2, mesh_capsule(fract(uv.yx + vec2(0.5, 0.5))));",
			"\t\tmask = float(pattern > pattern2);",
			"\t\tpattern = max(pattern, pattern2);",
			"\t} else if($shape == 2) {",
			"\t\tpattern = max(pattern, $in(fract(uv + vec2(0.5, 0.0))));",
			"\t\tpattern = max(pattern, $in(fract(uv + vec2(0.0, 0.5))));",
			"\t\tfloat pattern2 = $in(fract(uv.yx));",
			"\t\tpattern2 = max(pattern2, $in(fract(uv.yx + vec2(0.5, 0.5))));",
			"\t\tmask = float(pattern > pattern2);",
			"\t\tpattern = max(pattern, pattern2);",
			"\t}",
			"\treturn vec3(pattern, mask, 1.0 - mask);",
			"}"
		],
		"longdesc": "Outputs several mesh patterns",
		"name": "Mesh",
		"outputs": [
			{
				"f": "$(name_uv)_pattern.x",
				"longdesc": "Shows the generated mesh pattern",
				"shortdesc": "Pattern",
				"type": "f"
			},
			{
				"f": "$(name_uv)_pattern.y",
				"longdesc": "Mask for the horizontal shapes",
				"shortdesc": "Horizontal Mask",
				"type": "f"
			},
			{
				"f": "$(name_uv)_pattern.z",
				"longdesc": "Mask for the vertical shapes",
				"shortdesc": "Vertical Mask",
				"type": "f"
			}
		],
		"parameters": [
			{
				"default": 2,
				"label": "Shape",
				"longdesc": "Select between predefined patterns or the input pattern",
				"name": "shape",
				"shortdesc": "Shape",
				"type": "enum",
				"values": [
					{
						"name": "Shape 1",
						"value": "0"
					},
					{
						"name": "Shape 2",
						"value": "1"
					},
					{
						"name": "Input",
						"value": "2"
					}
				]
			},
			{
				"control": "None",
				"default": 1,
				"label": "Tiling",
				"longdesc": "The number of times the pattern tiles",
				"max": 16,
				"min": 1,
				"name": "tiling",
				"shortdesc": "Tiling",
				"step": 1,
				"type": "float"
			},
			{
				"default": false,
				"label": "Diagonal",
				"longdesc": "Rotates the pattern 45 degrees while ensuring tiling",
				"name": "diagonal",
				"shortdesc": "Diagonal",
				"type": "boolean"
			}
		],
		"shortdesc": "Mesh"
	},
	"type": "shader"
}