{
	"name": "blend",
	"node_position": {
		"x": 0,
		"y": 0
	},
	"parameters": {
		"amount": 0.5,
		"blend_type": 0
	},
	"seed_int": 0,
	"shader_model": {
		"code": [
			"vec4 $(name_uv)_s1 = $s1($uv);",
			"vec4 $(name_uv)_s2 = $s2($uv);",
			"float $(name_uv)_a = $amount*$a($uv);",
			""
		],
		"global": [
			"vec3 blend_normal(vec2 uv, vec3 c1, vec3 c2, float opacity) {",
			"\treturn opacity*c1 + (1.0-opacity)*c2;",
			"}",
			"",
			"vec3 blend_dissolve(vec2 uv, vec3 c1, vec3 c2, float opacity) {",
			"\tif (rand(uv) < opacity) {",
			"\t\treturn c1;",
			"\t} else {",
			"\t\treturn c2;",
			"\t}",
			"}",
			"",
			"vec3 blend_multiply(vec2 uv, vec3 c1, vec3 c2, float opacity) {",
			"\treturn opacity*c1*c2 + (1.0-opacity)*c2;",
			"}",
			"",
			"vec3 blend_screen(vec2 uv, vec3 c1, vec3 c2, float opacity) {",
			"\treturn opacity*(1.0-(1.0-c1)*(1.0-c2)) + (1.0-opacity)*c2;",
			"}",
			"",
			"float blend_overlay_f(float c1, float c2) {",
			"\treturn (c1 < 0.5) ? (2.0*c1*c2) : (1.0-2.0*(1.0-c1)*(1.0-c2));",
			"}",
			"",
			"vec3 blend_overlay(vec2 uv, vec3 c1, vec3 c2, float opacity) {",
			"\treturn opacity*vec3(blend_overlay_f(c1.x, c2.x), blend_overlay_f(c1.y, c2.y), blend_overlay_f(c1.z, c2.z)) + (1.0-opacity)*c2;",
			"}",
			"",
			"vec3 blend_hard_light(vec2 uv, vec3 c1, vec3 c2, float opacity) {",
			"\treturn opacity*0.5*(c1*c2+blend_overlay(uv, c1, c2, 1.0)) + (1.0-opacity)*c2;",
			"}",
			"",
			"float blend_soft_light_f(float c1, float c2) {",
			"\treturn (c2 < 0.5) ? (2.0*c1*c2+c1*c1*(1.0-2.0*c2)) : 2.0*c1*(1.0-c2)+sqrt(c1)*(2.0*c2-1.0);",
			"}",
			"",
			"vec3 blend_soft_light(vec2 uv, vec3 c1, vec3 c2, float opacity) {",
			"\treturn opacity*vec3(blend_soft_light_f(c1.x, c2.x), blend_soft_light_f(c1.y, c2.y), blend_soft_light_f(c1.z, c2.z)) + (1.0-opacity)*c2;",
			"}",
			"",
			"float blend_burn_f(float c1, float c2) {",
			"\treturn (c1==0.0)?c1:max((1.0-((1.0-c2)/c1)),0.0);",
			"}",
			"",
			"vec3 blend_burn(vec2 uv, vec3 c1, vec3 c2, float opacity) {",
			"\treturn opacity*vec3(blend_burn_f(c1.x, c2.x), blend_burn_f(c1.y, c2.y), blend_burn_f(c1.z, c2.z)) + (1.0-opacity)*c2;",
			"}",
			"",
			"float blend_dodge_f(float c1, float c2) {",
			"\treturn (c1==1.0)?c1:min(c2/(1.0-c1),1.0);",
			"}",
			"",
			"vec3 blend_dodge(vec2 uv, vec3 c1, vec3 c2, float opacity) {",
			"\treturn opacity*vec3(blend_dodge_f(c1.x, c2.x), blend_dodge_f(c1.y, c2.y), blend_dodge_f(c1.z, c2.z)) + (1.0-opacity)*c2;",
			"}",
			"",
			"vec3 blend_lighten(vec2 uv, vec3 c1, vec3 c2, float opacity) {",
			"\treturn opacity*max(c1, c2) + (1.0-opacity)*c2;",
			"}",
			"",
			"vec3 blend_darken(vec2 uv, vec3 c1, vec3 c2, float opacity) {",
			"\treturn opacity*min(c1, c2) + (1.0-opacity)*c2;",
			"}",
			"",
			"vec3 blend_difference(vec2 uv, vec3 c1, vec3 c2, float opacity) {",
			"\treturn opacity*clamp(c2-c1, vec3(0.0), vec3(1.0)) + (1.0-opacity)*c2;",
			"}",
			"",
			"vec3 blend_additive(vec2 uv, vec3 c1, vec3 c2, float oppacity) {",
			"\treturn c2 + c1 * oppacity;",
			"}",
			"",
			"vec3 blend_addsub(vec2 uv, vec3 c1, vec3 c2, float oppacity) {",
			"\treturn c2 + (c1 - .5) * 2.0 * oppacity;",
			"}"
		],
		"inputs": [
			{
				"default": "vec4($uv.x, 1.0, 1.0, 1.0)",
				"label": "Source1",
				"longdesc": "The foreground input",
				"name": "s1",
				"shortdesc": "Foreground",
				"type": "rgba"
			},
			{
				"default": "vec4(1.0, $uv.y, 1.0, 1.0)",
				"label": "Source2",
				"longdesc": "The background input",
				"name": "s2",
				"shortdesc": "Background",
				"type": "rgba"
			},
			{
				"default": "1.0",
				"label": "Opacity",
				"longdesc": "The optional opacity mask",
				"name": "a",
				"shortdesc": "Mask",
				"type": "f"
			}
		],
		"instance": "",
		"longdesc": "Blends its input, using an optional mask",
		"name": "Blend",
		"outputs": [
			{
				"longdesc": "Shows the result of the blend operation",
				"rgba": "vec4(blend_$blend_type($uv, $(name_uv)_s1.rgb, $(name_uv)_s2.rgb, $(name_uv)_a*$(name_uv)_s1.a), min(1.0, $(name_uv)_s2.a+$(name_uv)_a*$(name_uv)_s1.a))",
				"shortdesc": "Output",
				"type": "rgba"
			}
		],
		"parameters": [
			{
				"default": 13,
				"label": "",
				"longdesc": "The algorithm used to blend the inputs",
				"name": "blend_type",
				"shortdesc": "Blend mode",
				"type": "enum",
				"values": [
					{
						"name": "Normal",
						"value": "normal"
					},
					{
						"name": "Dissolve",
						"value": "dissolve"
					},
					{
						"name": "Multiply",
						"value": "multiply"
					},
					{
						"name": "Screen",
						"value": "screen"
					},
					{
						"name": "Overlay",
						"value": "overlay"
					},
					{
						"name": "Hard Light",
						"value": "hard_light"
					},
					{
						"name": "Soft Light",
						"value": "soft_light"
					},
					{
						"name": "Burn",
						"value": "burn"
					},
					{
						"name": "Dodge",
						"value": "dodge"
					},
					{
						"name": "Lighten",
						"value": "lighten"
					},
					{
						"name": "Darken",
						"value": "darken"
					},
					{
						"name": "Difference",
						"value": "difference"
					},
					{
						"name": "Additive",
						"value": "additive"
					},
					{
						"name": "AddSub",
						"value": "addsub"
					},
					{
						"name": "Linear Light",
						"value": "linear_light"
					}
				]
			},
			{
				"control": "None",
				"default": 0.5,
				"label": "3:",
				"longdesc": "The opacity of the blend operation",
				"max": 1,
				"min": 0,
				"name": "amount",
				"shortdesc": "Opacity",
				"step": 0.01,
				"type": "float"
			}
		],
		"shortdesc": "Blend"
	},
	"type": "shader"
}