{
	"name": "palettize",
	"node_position": {
		"x": 0,
		"y": 0
	},
	"parameters": {
		"size": 16
	},
	"seed_int": 0,
	"shader_model": {
		"code": [
			"",
			""
		],
		"global": "",
		"inputs": [
			{
				"default": "vec3(0.0)",
				"label": "",
				"longdesc": "The input image",
				"name": "in",
				"shortdesc": "Input",
				"type": "rgb"
			},
			{
				"default": "vec3(0.0)",
				"function": true,
				"label": "",
				"longdesc": "The palette",
				"name": "palette",
				"shortdesc": "Palette",
				"type": "rgb"
			}
		],
		"instance": [
			"vec3 find_color_from_palette_$name(vec3 color, int size) {",
			"\tfloat min_dist = 10.0;",
			"\tvec3 best_color = vec3(0.0);",
			"\tfor (int i = 0; i < size; ++i) {",
			"\t\tfloat x = (float(i)+0.5)/float(size);",
			"\t\tfor (int j = 0; j < size; ++j) {",
			"\t\t\tfloat y = (float(j)+0.5)/float(size);",
			"\t\t\tvec3 c = $palette(vec2(x, y));",
			"\t\t\tfloat l = length(color - c);",
			"\t\t\tif (l < min_dist) {",
			"\t\t\t\tmin_dist = l;",
			"\t\t\t\tbest_color = c;",
			"\t\t\t}",
			"\t\t}",
			"\t}",
			"\treturn best_color;",
			"}"
		],
		"longdesc": "Maps its input image to a palette",
		"name": "Palettize",
		"outputs": [
			{
				"longdesc": "The input image mapped to the palette",
				"rgb": "find_color_from_palette_$name($in($uv), int(min($size, 32.0)))",
				"shortdesc": "Output",
				"type": "rgb"
			}
		],
		"parameters": [
			{
				"control": "None",
				"default": 16,
				"label": "Size",
				"longdesc": "The width and height in pixels of the palette",
				"max": 32,
				"min": 0,
				"name": "size",
				"shortdesc": "Size",
				"step": 1,
				"type": "float"
			}
		],
		"shortdesc": "Palettize"
	},
	"type": "shader"
}