{
	"name": "denoiser_shader",
	"node_position": {
		"x": 0,
		"y": 0
	},
	"parameters": {
		"ksigma": 4,
		"sigma": 3,
		"size": 10,
		"threshold": 0.7
	},
	"seed": 38722,
	"shader_model": {
		"code": "",
		"global": "",
		"inputs": [
			{
				"default": "0.0",
				"function": true,
				"label": "",
				"name": "in",
				"type": "rgba"
			}
		],
		"instance": [
			"//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~",
			"//  Copyright (c) 2018-2019 Michele Morrone",
			"//  All rights reserved.",
			"//",
			"//  https://michelemorrone.eu - https://BrutPitt.com",
			"//",
			"//  me@michelemorrone.eu - brutpitt@gmail.com",
			"//  twitter: @BrutPitt - github: BrutPitt",
			"//  ",
			"//  https://github.com/BrutPitt/glslSmartDeNoise/",
			"//",
			"//  This software is distributed under the terms of the BSD 2-Clause license",
			"//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~",
			"//  smartDeNoise - parameters",
			"//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~",
			"//",
			"//  sampler2D tex\t - sampler image / texture",
			"//  vec2 uv\t\t   - actual fragment coord",
			"//  float sigma  >  0 - sigma Standard Deviation",
			"//  float kSigma >= 0 - sigma coefficient ",
			"//\t  kSigma * sigma  -->  radius of the circular kernel",
			"//  float threshold   - edge sharpening threshold ",
			"vec4 $(name)_smartDeNoise(vec2 uv, float sigma, float kSigma, float threshold)",
			"{",
			"\tfloat INV_SQRT_OF_2PI = 0.39894228040143267793994605993439; // 1.0/SQRT_OF_2PI",
			"\tfloat INV_PI = 0.31830988618379067153776752674503;",
			"\tfloat radius = round(kSigma*sigma);",
			"\tfloat radQ = radius * radius;",
			"",
			"\tfloat invSigmaQx2 = .5 / (sigma * sigma);\t  // 1.0 / (sigma^2 * 2.0)",
			"\tfloat invSigmaQx2PI = INV_PI * invSigmaQx2;\t// 1/(2 * PI * sigma^2)",
			"",
			"\tfloat invThresholdSqx2 = .5 / (threshold * threshold);\t // 1.0 / (sigma^2 * 2.0)",
			"\tfloat invThresholdSqrt2PI = INV_SQRT_OF_2PI / threshold;   // 1.0 / (sqrt(2*PI) * sigma^2)",
			"",
			"\tvec4 centrPx = $in(uv); ",
			"",
			"\tfloat zBuff = 0.0;",
			"\tvec4 aBuff = vec4(0.0);",
			"\tvec2 size = vec2($size, $size);",
			"",
			"\tfor (float dx=-radius; dx <= radius; dx++) {",
			"\t\tfloat pt = sqrt(radQ-dx*dx);\t   // pt = yRadius: have circular trend",
			"\t\tfor (float dy=-pt; dy <= pt; dy++) {",
			"\t\t\tvec2 d = vec2(dx, dy);",
			"\t\t\tfloat blurFactor = exp( -dot(d , d) * invSigmaQx2 ) * invSigmaQx2PI;",
			"",
			"\t\t\tvec4 walkPx =  $in(uv+d/size);",
			"\t\t\tvec4 dC = walkPx-centrPx;",
			"\t\t\tfloat deltaFactor = exp( -dot(dC, dC) * invThresholdSqx2) * invThresholdSqrt2PI * blurFactor;",
			"",
			"\t\t\tzBuff += deltaFactor;",
			"\t\t\taBuff += deltaFactor*walkPx;",
			"\t\t}",
			"\t}",
			"\treturn aBuff/zBuff;",
			"}"
		],
		"longdesc": "A node that generates several images from a tileable voronoi noise",
		"name": "Denoiser",
		"outputs": [
			{
				"longdesc": "A color pattern that assigns a random color to each cell",
				"rgba": "$(name)_smartDeNoise($uv, $sigma, $ksigma, $threshold)",
				"shortdesc": "Random color",
				"type": "rgba"
			}
		],
		"parameters": [
			{
				"default": 10,
				"first": 0,
				"label": "size",
				"last": 12,
				"longdesc": "The scale along the X axis",
				"name": "size",
				"shortdesc": "Scale.x",
				"type": "size"
			},
			{
				"control": "None",
				"default": 0.5,
				"label": "Sigma",
				"max": 1,
				"min": 0.005,
				"name": "sigma",
				"step": 0.1,
				"type": "float"
			},
			{
				"control": "None",
				"default": 0.5,
				"label": "kSigma",
				"max": 1,
				"min": 0,
				"name": "ksigma",
				"step": 0.1,
				"type": "float"
			},
			{
				"control": "None",
				"default": 0.5,
				"label": "threshold",
				"max": 1,
				"min": 0,
				"name": "threshold",
				"step": 0.1,
				"type": "float"
			}
		],
		"shortdesc": "Voronoi Noise"
	},
	"type": "shader"
}