{
  "Name": "MultiplyAlpha",
  "_id": "f168564c-8327-46fb-b697-56eda902bfd4",
  "Namespace": "lib.image.adjust",
  "Description": "Mask image1 with Alpha in 2nd image input.",
  "Inputs": [
    {
      "Name": "Code",
      "MetaInstanceID": "649d347c-e070-479b-8824-8843d51a812d",
      "DefaultValue": {
        "Type": "Text",
        "Value": [
          "//>>> _common parameters\r",
          "float4x4 objectToWorldMatrix;",
          "float4x4 worldToCameraMatrix;",
          "float4x4 projMatrix;",
          "Texture2D txDiffuse;",
          "float2 RenderTargetSize;",
          "//<<< _common parameters\r",
          "\r",
          "//>>> _parameters\r",
          "Texture2D Image;",
          "Texture2D Mask;",
          "float MaskMode;",
          "//<<< _parameters\r",
          " \r",
          "//>>> setup\r",
          "SamplerState samNearest\r",
          "{\r",
          "    Filter = MIN_MAG_MIP_POINT;\r",
          "    AddressU = Clamp;\r",
          "    AddressV = Clamp;\r",
          "};\r",
          "//<<< setup\r",
          "\r",
          "//>>> declarations\r",
          "struct VS_IN\r",
          "{\r",
          "    float4 pos : POSITION;\r",
          "    float2 texCoord : TEXCOORD;\r",
          "};\r",
          "\r",
          "struct PS_IN\r",
          "{\r",
          "    float4 pos : SV_POSITION;\r",
          "    float2 texCoord: TEXCOORD0;\t    \r",
          "    float3 worldTViewPos: TEXCOORD1;\r",
          "    float3 worldTViewDir: TEXCOORD2;\r",
          "};\r",
          "//<<< declarations\r",
          "\r",
          "//>>> _GS\r",
          "",
          "//<<< _GS\r",
          "\r",
          "//>>> _VS \r",
          "PS_IN VS( VS_IN input )",
          "{",
          "    PS_IN output = (PS_IN)0;",
          "",
          "    output.pos = mul(input.pos, worldToCameraMatrix);",
          "    output.pos = mul(output.pos, projMatrix);",
          "    output.texCoord = input.texCoord;",
          "",
          "    return output;",
          "}",
          "//<<< _VS\r",
          "\r",
          "//>>> PS\r",
          "\r",
          "\r",
          "float4 PS( PS_IN input ) : SV_Target\r",
          "{\r",
          "    float4 t0 = Image.Sample(samNearest, input.texCoord); \r",
          "    float4 t1 = Mask.Sample(samNearest, input.texCoord);    \r",
          "    \r",
          "    float a = 1;\r",
          "    if(MaskMode < 0.5) {\r",
          "        a= t1.a;\r",
          "    }\r",
          "    else if (MaskMode < 1.5) {\r",
          "        a= (1- t1.a);\r",
          "    }\r",
          "    else if (MaskMode < 2.5) {\r",
          "        a=  (t1.r + t1.g + t1.b) * 0.3333;\r",
          "    }\r",
          "    else {\r",
          "        a=  1 - (t1.r + t1.g + t1.b) * 0.3333;        \r",
          "    }\r",
          "\r",
          "    //float a = t0.a + t1.a - t0.a*t1.a;\r",
          "    //float3 rgb = (1.0 - t1.a)*t0.rgb + t1.a*t1.rgb;   \r",
          "    return float4(t0.rgb, clamp( t0.a * a, 0, 1));\r",
          "    \r",
          "    \r",
          "\r",
          "}\r",
          "//<<< PS\r",
          "\r",
          "//>>> _technique\r",
          "technique10 Render",
          "{",
          "    pass P0",
          "    {",
          "        SetGeometryShader( 0 );",
          "        SetVertexShader( CompileShader( vs_4_0, VS() ) );",
          "        SetPixelShader( CompileShader( ps_4_0, PS() ) );",
          "    }",
          "}",
          "//<<< _technique\r",
          ""
        ]
      },
      "MetaID": "c522a66e-3260-4692-b3e3-79fd0361fa3d",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Image",
      "MetaInstanceID": "7ccf0058-d223-458d-aac4-06c2f2db4f48",
      "DefaultValue": {
        "Type": "Image",
        "Value": "Framefield.Core.Image"
      },
      "MetaID": "9848060d-fd84-45b0-b658-d0d531c61dab",
      "IsMultiInput": "False",
      "Relevance": "Required",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Mask",
      "MetaInstanceID": "8fc02e00-a121-4ce7-9685-5b8f190060b1",
      "DefaultValue": {
        "Type": "Image",
        "Value": "Framefield.Core.Image"
      },
      "MetaID": "9848060d-fd84-45b0-b658-d0d531c61dab",
      "IsMultiInput": "False",
      "Relevance": "Required",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "MaskMode",
      "MetaInstanceID": "c62e8903-09a3-48d4-a67c-0250e25e81c5",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-10000",
      "Max": "10000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": [
        {
          "Name": "Alpha",
          "Value": "0"
        },
        {
          "Name": "AlphaInverted",
          "Value": "1"
        },
        {
          "Name": "Gray",
          "Value": "2"
        },
        {
          "Name": "GrayInverted",
          "Value": "4"
        }
      ]
    }
  ],
  "Outputs": [
    {
      "Name": "Image",
      "MetaInstanceID": "5be9ab13-c521-48ec-be1f-c6904b961adc",
      "MetaID": "9848060d-fd84-45b0-b658-d0d531c61dab"
    }
  ],
  "OperatorParts": [
    {
      "MetaInstanceID": "431a886e-3af5-4a03-bd59-fffd83d91654",
      "MetaID": "47b822ac-6a57-4ab6-b459-7d3407b02df9",
      "Name": "MultiplyAlphaFunc",
      "Version": "7d8f0228-f37a-4494-a462-15a5843600f6",
      "Type": "Float",
      "IsMultiInput": "True",
      "Script": [
        "//>>> _using",
        "using System;",
        "using System.Collections.Generic;",
        "using System.Linq;",
        "using System.Text;",
        "using SharpDX;",
        "using SharpDX.Direct3D11;",
        "using SharpDX.Windows;",
        "//<<< _using",
        "",
        "namespace Framefield.Core.ID47b822ac_6a57_4ab6_b459_7d3407b02df9",
        "{",
        "    public class Class_MultiplyAlpha : FXImageFunction",
        "    {",
        "        //>>> _inputids",
        "        private enum InputId",
        "        {",
        "            Code = 0,",
        "            Image = 1,",
        "            Mask = 2,",
        "            MaskMode = 3",
        "        }",
        "        //<<< _inputids",
        "",
        "        public override OperatorPartContext Eval(OperatorPartContext context, List<OperatorPart> inputs, int outputIdx)",
        "        {",
        "            //>>> _params",
        "            var Code = inputs[(int)InputId.Code].Eval(context).Text;",
        "            var Image = inputs[(int)InputId.Image].Eval(context).Image; // Needs to be checked for null!",
        "            var Mask = inputs[(int)InputId.Mask].Eval(context).Image; // Needs to be checked for null!",
        "            var MaskMode = (int) inputs[(int)InputId.MaskMode].Eval(context).Value;",
        "            //<<< _params",
        "",
        "            return PrepareAndEvalOnChange(context, () => {",
        "                ClearRenderTarget(context, new SharpDX.Color4(0,0,0,0));",
        "",
        "                //>>> _setup",
        "                using (var ImageView = new ShaderResourceView(context.D3DDevice, Image))",
        "                using (var MaskView = new ShaderResourceView(context.D3DDevice, Mask))",
        "                {",
        "                    _effect.GetVariableByName(\"RenderTargetSize\").AsVector().Set(new Vector2(_usedViewport.Width, _usedViewport.Height));",
        "                    _effect.GetVariableByName(\"Image\").AsShaderResource().SetResource(ImageView);",
        "                    _effect.GetVariableByName(\"Mask\").AsShaderResource().SetResource(MaskView);",
        "                    _effect.GetVariableByName(\"MaskMode\").AsScalar().Set(MaskMode);",
        "                //<<< _setup",
        "",
        "                Render(context);",
        "",
        "                //>>> _cleanup",
        "                }",
        "                //<<< _cleanup",
        "            });",
        "        }",
        "",
        "    }",
        "}",
        "",
        ""
      ],
      "AdditionalAssemblies": []
    }
  ],
  "Operators": [],
  "Connections": [
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "431a886e-3af5-4a03-bd59-fffd83d91654",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "5be9ab13-c521-48ec-be1f-c6904b961adc"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "649d347c-e070-479b-8824-8843d51a812d",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "431a886e-3af5-4a03-bd59-fffd83d91654"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "7ccf0058-d223-458d-aac4-06c2f2db4f48",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "431a886e-3af5-4a03-bd59-fffd83d91654"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "8fc02e00-a121-4ce7-9685-5b8f190060b1",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "431a886e-3af5-4a03-bd59-fffd83d91654"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "c62e8903-09a3-48d4-a67c-0250e25e81c5",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "431a886e-3af5-4a03-bd59-fffd83d91654"
    }
  ]
}