{
	"name": "pixelize",
	"node_position": {
		"x": 0,
		"y": 0
	},
	"parameters": {
		"c": 8,
		"d": 0.5,
		"x": 16,
		"y": 16
	},
	"seed_int": 0,
	"shader_model": {
		"code": [
			"vec2 $(name_uv)_uv = floor(($uv*vec2($x, $y)))+vec2(0.5);",
			"vec3 $(name_uv)_dither = $t;",
			""
		],
		"global": [
			"float bayer_matrix(vec2 uv, int rounds) {",
			"\tivec2 iuv = ivec2(uv);",
			"\tint b[4] = int[4]( 0, 2, 3, 1 );",
			"\tfloat divisor = 1.0;",
			"\tint rv = 0;",
			"\tfor (int i = 0; i < rounds; ++i) {",
			"\t\trv *= 4;",
			"\t\tdivisor *= 4.0;",
			"\t\trv += b[(iuv.x%2)+2*(iuv.y%2)];",
			"\t\tiuv >>= 1;",
			"\t}",
			"\treturn float(rv)/divisor;",
			"}"
		],
		"inputs": [
			{
				"default": "vec3(1.0)",
				"label": "",
				"longdesc": "The image to be pixelated",
				"name": "i",
				"shortdesc": "Input",
				"type": "rgb"
			}
		],
		"instance": "",
		"longdesc": "Creates a pixelated image from its input, and also quantifies the colors with optional dithering.",
		"name": "Pixelize",
		"outputs": [
			{
				"longdesc": "A pixelated version of the input image",
				"rgb": "floor($i($(name_uv)_uv/vec2($x, $y))*$c+$d*($(name_uv)_dither))/$c",
				"shortdesc": "Output",
				"type": "rgb"
			}
		],
		"parameters": [
			{
				"control": "None",
				"default": 4,
				"label": "Columns",
				"longdesc": "Number of pixel columns of the output",
				"max": 256,
				"min": 1,
				"name": "x",
				"shortdesc": "Columns",
				"step": 1,
				"type": "float"
			},
			{
				"control": "None",
				"default": 4,
				"label": "Rows",
				"longdesc": "Number of pixel rows of the output",
				"max": 256,
				"min": 1,
				"name": "y",
				"shortdesc": "Rows",
				"step": 1,
				"type": "float"
			},
			{
				"control": "None",
				"default": 4,
				"label": "Levels",
				"longdesc": "Number of color levels for each channel",
				"max": 32,
				"min": 2,
				"name": "c",
				"shortdesc": "Levels",
				"step": 1,
				"type": "float"
			},
			{
				"control": "None",
				"default": 0.5,
				"label": "Dither",
				"longdesc": "Amount of dithering in the output image",
				"max": 1,
				"min": 0,
				"name": "d",
				"shortdesc": "Dithering",
				"step": 0.01,
				"type": "float"
			},
			{
				"default": 0,
				"label": "Dither type",
				"name": "t",
				"type": "enum",
				"values": [
					{
						"name": "Random",
						"value": "fract(vec3(dot(vec2(171.0, 231.0), $(name_uv)_uv))/vec3(103.0, 71.0, 97.0))"
					},
					{
						"name": "Bayer 2x2",
						"value": "vec3(bayer_matrix($(name_uv)_uv, 1))"
					},
					{
						"name": "Bayer 4x4",
						"value": "vec3(bayer_matrix($(name_uv)_uv, 2))"
					},
					{
						"name": "Bayer 8x8",
						"value": "vec3(bayer_matrix($(name_uv)_uv, 3))"
					},
					{
						"name": "Bayer 16x16",
						"value": "vec3(bayer_matrix($(name_uv)_uv, 4))"
					}
				]
			}
		]
	},
	"type": "shader"
}