material-maker/addons/material_maker/nodes/blend.mmg

126 lines
4.7 KiB
Plaintext
Raw Normal View History

2019-10-27 14:36:16 +01:00
{
"name": "blend",
"node_position": {
"x": 0,
"y": 0
},
"parameters": {
2020-09-26 17:13:09 +02:00
"amount": 0.5,
2019-10-27 14:36:16 +01:00
"blend_type": 0
},
"shader_model": {
"code": "vec4 $(name_uv)_s1 = $s1($uv);\nvec4 $(name_uv)_s2 = $s2($uv);\nfloat $(name_uv)_a = $amount*$a($uv);\n",
2019-10-27 14:36:16 +01:00
"global": "vec3 blend_normal(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*c1 + (1.0-opacity)*c2;\n}\n\nvec3 blend_dissolve(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\tif (rand(uv) < opacity) {\n\t\treturn c1;\n\t} else {\n\t\treturn c2;\n\t}\n}\n\nvec3 blend_multiply(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*c1*c2 + (1.0-opacity)*c2;\n}\n\nvec3 blend_screen(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*(1.0-(1.0-c1)*(1.0-c2)) + (1.0-opacity)*c2;\n}\n\nfloat blend_overlay_f(float c1, float c2) {\n\treturn (c1 < 0.5) ? (2.0*c1*c2) : (1.0-2.0*(1.0-c1)*(1.0-c2));\n}\n\nvec3 blend_overlay(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\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;\n}\n\nvec3 blend_hard_light(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*0.5*(c1*c2+blend_overlay(uv, c1, c2, 1.0)) + (1.0-opacity)*c2;\n}\n\nfloat blend_soft_light_f(float c1, float c2) {\n\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);\n}\n\nvec3 blend_soft_light(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\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;\n}\n\nfloat blend_burn_f(float c1, float c2) {\n\treturn (c1==0.0)?c1:max((1.0-((1.0-c2)/c1)),0.0);\n}\n\nvec3 blend_burn(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\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;\n}\n\nfloat blend_dodge_f(float c1, float c2) {\n\treturn (c1==1.0)?c1:min(c2/(1.0-c1),1.0);\n}\n\nvec3 blend_dodge(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\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;\n}\n\nvec3 blend_lighten(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*max(c1, c2) + (1.0-opacity)*c2;\n}\n\nvec3 blend_darken(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*min(c1, c2) + (1.0-opacity)*c2;\n}\n\nvec3 blend_difference(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*clamp(c2-c1, vec3(0.0), vec3(1.0)) + (1.0-opacity)*c2;\n}\n",
"inputs": [
{
"default": "vec4($uv.x, 1.0, 1.0, 1.0)",
"label": "Source1",
2020-09-26 17:13:09 +02:00
"longdesc": "The foreground input",
2019-10-27 14:36:16 +01:00
"name": "s1",
2020-09-26 17:13:09 +02:00
"shortdesc": "Foreground",
2019-10-27 14:36:16 +01:00
"type": "rgba"
},
{
"default": "vec4(1.0, $uv.y, 1.0, 1.0)",
"label": "Source2",
2020-09-26 17:13:09 +02:00
"longdesc": "The background input",
2019-10-27 14:36:16 +01:00
"name": "s2",
2020-09-26 17:13:09 +02:00
"shortdesc": "Background",
2019-10-27 14:36:16 +01:00
"type": "rgba"
},
{
"default": "1.0",
"label": "Opacity",
2020-09-26 17:13:09 +02:00
"longdesc": "The optional opacity mask",
2019-10-27 14:36:16 +01:00
"name": "a",
2020-09-26 17:13:09 +02:00
"shortdesc": "Mask",
2019-10-27 14:36:16 +01:00
"type": "f"
}
],
"instance": "",
2020-09-26 17:13:09 +02:00
"longdesc": "A node that blends its input, using an optional mask",
2019-10-27 14:36:16 +01:00
"name": "Blend",
"outputs": [
{
2020-09-26 17:13:09 +02:00
"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))",
2020-09-26 17:13:09 +02:00
"shortdesc": "Output",
2019-10-27 14:36:16 +01:00
"type": "rgba"
}
],
"parameters": [
{
"default": 0,
"label": "",
2020-09-26 17:13:09 +02:00
"longdesc": "The algorithm used to blend the inputs",
2019-10-27 14:36:16 +01:00
"name": "blend_type",
2020-09-26 17:13:09 +02:00
"shortdesc": "Blend mode",
2019-10-27 14:36:16 +01:00
"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"
}
]
},
{
"control": "None",
2019-10-27 14:36:16 +01:00
"default": 0.5,
"label": "3:",
2020-09-26 17:13:09 +02:00
"longdesc": "The opacity of the blend operation",
2019-10-27 14:36:16 +01:00
"max": 1,
"min": 0,
"name": "amount",
2020-09-26 17:13:09 +02:00
"shortdesc": "Opacity",
"step": 0.01,
2019-10-27 14:36:16 +01:00
"type": "float"
}
2020-09-26 17:13:09 +02:00
],
"shortdesc": "Blend"
},
"type": "shader"
2019-10-27 14:36:16 +01:00
}