{ "name": "blend", "node_position": { "x": 0, "y": 0 }, "parameters": { "amount": 0.5, "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", "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", "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": "A node that 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": 0, "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" } ] }, { "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" }