{
	"name": "fast_blur_shader",
	"node_position": {
		"x": 0,
		"y": 0
	},
	"parameters": {
		"quality": 1,
		"sigma": 100,
		"strength": 1
	},
	"seed_int": 0,
	"shader_model": {
		"code": "vec4 $(name_uv)_blurred = $(name)_blur($uv, vec2(1.0)/$in.size, max(1.0, floor($sigma*$in.size/2048.0)), int($quality));",
		"global": "",
		"inputs": [
			{
				"default": "vec4(1.0)",
				"function": true,
				"label": "",
				"name": "in",
				"type": "rgba"
			}
		],
		"instance": [
			"vec4 $(name)_blur(vec2 uv, vec2 scale, float sigma, int quality) {",
			"\tvec4 O = vec4(0.0);",
			"\tfloat samples = sigma * 4.0; ",
			"\tint LOD = max(0, int(log2(float(samples)))-quality-2);",
			"\tint sLOD = 1 << LOD;",
			"\tint s = max(1, int(samples/float(sLOD)));",
			"\tfloat sum = 0.0;",
			"\tfor (int i = 0; i < s*s; i++) {",
			"\t\tvec2 d = vec2(float(i%s), float(i/s))*float(sLOD) - 0.5*float(samples);",
			"\t\tvec2 dd = d / sigma;",
			"\t\tfloat g = exp(-.5*dot(dd,dd))/(6.28*sigma*sigma);",
			"\t\tO += g * textureLod($in.texture, uv + scale * d, float(LOD));",
			"\t\tsum += g;",
			"\t}",
			"\t",
			"\treturn O / sum;",
			"}",
			""
		],
		"name": "Fast Blur",
		"outputs": [
			{
				"rgba": "$(name_uv)_blurred",
				"shortdesc": "Low Pass",
				"type": "rgba"
			},
			{
				"rgba": "($in($uv) - $(name_uv)_blurred) * $strength",
				"shortdesc": "High Pass",
				"type": "rgba"
			},
			{
				"rgba": "($in($uv) - $(name_uv)_blurred) * ($strength+1.0) + $(name_uv)_blurred",
				"shortdesc": "Sharpened",
				"type": "rgba"
			}
		],
		"parameters": [
			{
				"control": "None",
				"default": 1,
				"label": "",
				"max": 256,
				"min": 1,
				"name": "sigma",
				"step": 1,
				"type": "float"
			},
			{
				"control": "None",
				"default": 1,
				"label": "",
				"max": 3,
				"min": 0,
				"name": "quality",
				"step": 1,
				"type": "float"
			},
			{
				"control": "None",
				"default": 2,
				"label": "",
				"max": 10,
				"min": 0,
				"name": "strength",
				"step": 0.1,
				"type": "float"
			}
		]
	},
	"type": "shader"
}