{
	"name": "perlin",
	"node_position": {
		"x": 0,
		"y": 0
	},
	"parameters": {
		"iterations": 3,
		"persistence": 0.5,
		"scale_x": 4,
		"scale_y": 4
	},
	"seed_int": 0,
	"shader_model": {
		"code": "",
		"global": [
			"float perlin(vec2 uv, vec2 size, int iterations, float persistence, float seed) {",
			"\tvec2 seed2 = rand2(vec2(seed, 1.0-seed));",
			"\tfloat rv = 0.0;",
			"\tfloat coef = 1.0;",
			"\tfloat acc = 0.0;",
			"\tfor (int i = 0; i < iterations; ++i) {",
			"\t\tvec2 step = vec2(1.0)/size;",
			"\t\tvec2 xy = floor(uv*size);",
			"\t\tfloat f0 = rand(seed2+mod(xy, size));",
			"\t\tfloat f1 = rand(seed2+mod(xy+vec2(1.0, 0.0), size));",
			"\t\tfloat f2 = rand(seed2+mod(xy+vec2(0.0, 1.0), size));",
			"\t\tfloat f3 = rand(seed2+mod(xy+vec2(1.0, 1.0), size));",
			"\t\tvec2 mixval = smoothstep(0.0, 1.0, fract(uv*size));",
			"\t\trv += coef * mix(mix(f0, f1, mixval.x), mix(f2, f3, mixval.x), mixval.y);",
			"\t\tacc += coef;",
			"\t\tsize *= 2.0;",
			"\t\tcoef *= persistence;",
			"\t}",
			"\t",
			"\treturn rv / acc;",
			"}",
			""
		],
		"inputs": [

		],
		"instance": "",
		"longdesc": "Generates several octaves of grayscale value noise",
		"name": "Value Noise",
		"outputs": [
			{
				"f": "perlin($(uv), vec2($(scale_x), $(scale_y)), int($(iterations)), $(persistence), $(seed))",
				"longdesc": "Shows a grayscale value noise",
				"shortdesc": "Output",
				"type": "f"
			}
		],
		"parameters": [
			{
				"control": "None",
				"default": 4,
				"label": "Scale X",
				"longdesc": "The scale along the X axis",
				"max": 32,
				"min": 1,
				"name": "scale_x",
				"shortdesc": "Scale.x",
				"step": 1,
				"type": "float"
			},
			{
				"control": "None",
				"default": 4,
				"label": "Scale Y",
				"longdesc": "The scale along the Y axis",
				"max": 32,
				"min": 1,
				"name": "scale_y",
				"shortdesc": "Scale.y",
				"step": 1,
				"type": "float"
			},
			{
				"control": "None",
				"default": 3,
				"label": "Iterations",
				"longdesc": "The number of octaves (higher values might affect performance)",
				"max": 10,
				"min": 1,
				"name": "iterations",
				"shortdesc": "Octaves",
				"step": 1,
				"type": "float"
			},
			{
				"control": "None",
				"default": 0.5,
				"label": "Persistence",
				"longdesc": "The persistence between two consecutive octaves",
				"max": 1,
				"min": 0,
				"name": "persistence",
				"shortdesc": "Persistence",
				"step": 0.05,
				"type": "float"
			}
		],
		"shortdesc": "Value Noise"
	},
	"type": "shader"
}