{
  "Name": "LimitColorRange",
  "_id": "85d58251-b7a2-41ff-afae-f9d5739b916e",
  "Namespace": "lib.image.adjust",
  "Description": "Helper to key the value range of an image Image.\r\nOnly uses red-channel.\r\nReturns white if inside the range.",
  "Inputs": [
    {
      "Name": "Code",
      "MetaInstanceID": "a5771ed7-f6cb-405d-bd03-8b3e32a37fb3",
      "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;",
          "float4 MinColor;",
          "float4 MaxColor;",
          "//<<< _parameters\r",
          "\r",
          "//>>> setup\r",
          "SamplerState samNearest\r",
          "{\r",
          "    Filter = MIN_MAG_MIP_LINEAR;\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",
          "const float PI= 3.141578;\r",
          "const float toRad= 3.141578/180;\r",
          "\r",
          "float4 PS( PS_IN input ) : SV_Target\r",
          "{\r",
          "   \r",
          "    float4 c=Image.Sample(samNearest, input.texCoord);\r",
          "    \r",
          "    if( c.r >= MinColor.r && c.r <= MaxColor.r) {\r",
          "        c= float4(1,1,1,1);\r",
          "    }\r",
          "    else {\r",
          "        c= float4(0,0,0,1);\r",
          "    }\r",
          "    c.a=1;\r",
          "    return c;\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": "04142c02-a899-4676-b9ac-0b66ffacb37a",
      "DefaultValue": {
        "Type": "Image",
        "Value": "Framefield.Core.Image"
      },
      "MetaID": "9848060d-fd84-45b0-b658-d0d531c61dab",
      "IsMultiInput": "False",
      "Relevance": "Required",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "MinColor.R",
      "MetaInstanceID": "cb83c3c6-832a-48e2-9dd9-88325b8b9abd",
      "DefaultValue": {
        "Type": "Float",
        "Value": "1"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "0",
      "Max": "1",
      "Scale": "0.01",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "MinColor.G",
      "MetaInstanceID": "eba6ce4b-046d-48bb-a225-4c8e25d7f470",
      "DefaultValue": {
        "Type": "Float",
        "Value": "1"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "0",
      "Max": "1",
      "Scale": "0.01",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "MinColor.B",
      "MetaInstanceID": "3fb4b5c8-2555-45f4-9e56-d2a007391c65",
      "DefaultValue": {
        "Type": "Float",
        "Value": "1"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "0",
      "Max": "1",
      "Scale": "0.01",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "MinColor.A",
      "MetaInstanceID": "9135d05c-1ba8-41b4-b9e7-703fac1c25d8",
      "DefaultValue": {
        "Type": "Float",
        "Value": "1"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "0",
      "Max": "1",
      "Scale": "0.01",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "MaxColor.R",
      "MetaInstanceID": "1d9ba74f-482f-4050-9f10-4d440f48ddbf",
      "DefaultValue": {
        "Type": "Float",
        "Value": "1"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "0",
      "Max": "1",
      "Scale": "0.01",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "MaxColor.G",
      "MetaInstanceID": "47dab691-81fa-4ef1-9dbf-daca4615c7aa",
      "DefaultValue": {
        "Type": "Float",
        "Value": "1"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "0",
      "Max": "1",
      "Scale": "0.01",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "MaxColor.B",
      "MetaInstanceID": "e720adb0-53be-4c47-9981-10c1710c5124",
      "DefaultValue": {
        "Type": "Float",
        "Value": "1"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "0",
      "Max": "1",
      "Scale": "0.01",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "MaxColor.A",
      "MetaInstanceID": "77f6bca2-5912-4d9a-bcc0-4b7f63ddde86",
      "DefaultValue": {
        "Type": "Float",
        "Value": "1"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "0",
      "Max": "1",
      "Scale": "0.01",
      "ScaleType": "Linear",
      "EnumValues": []
    }
  ],
  "Outputs": [
    {
      "Name": "Image",
      "MetaInstanceID": "ede36d64-a890-4e01-a336-2b25ed27d362",
      "MetaID": "9848060d-fd84-45b0-b658-d0d531c61dab"
    }
  ],
  "OperatorParts": [
    {
      "MetaInstanceID": "63c11260-1931-4683-bfc6-a981262cc34d",
      "MetaID": "e781042f-1032-40e7-a85f-16263c355c1a",
      "Name": "LimitColorRangeFunc",
      "Version": "25ff305d-3539-4698-90e7-e80c3a938846",
      "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.IDe781042f_1032_40e7_a85f_16263c355c1a",
        "{",
        "    public class Class_LimitColorRange : FXImageFunction",
        "    {",
        "        //>>> _inputids",
        "        private enum InputId",
        "        {",
        "            Code = 0,",
        "            Image = 1,",
        "            MinColorR = 2,",
        "            MinColorG = 3,",
        "            MinColorB = 4,",
        "            MinColorA = 5,",
        "            MaxColorR = 6,",
        "            MaxColorG = 7,",
        "            MaxColorB = 8,",
        "            MaxColorA = 9",
        "        }",
        "        //<<< _inputids",
        "",
        "        public override OperatorPartContext Eval(OperatorPartContext context, List<OperatorPart> inputs, int outputIdx)",
        "        {",
        "            return PrepareAndEvalOnChange(context, () =>",
        "            {",
        "                //>>> __params",
        "                var Code = inputs[(int)InputId.Code].Eval(context).Text;",
        "                var Image = inputs[(int)InputId.Image].Eval(context).Image; ",
        "                var MinColorR = inputs[(int)InputId.MinColorR].Eval(context).Value;",
        "                var MinColorG = inputs[(int)InputId.MinColorG].Eval(context).Value;",
        "                var MinColorB = inputs[(int)InputId.MinColorB].Eval(context).Value;",
        "                var MinColorA = inputs[(int)InputId.MinColorA].Eval(context).Value;",
        "                var MinColor = new Color4(MinColorR, MinColorG, MinColorB, MinColorA);",
        "                var MaxColorR = inputs[(int)InputId.MaxColorR].Eval(context).Value;",
        "                var MaxColorG = inputs[(int)InputId.MaxColorG].Eval(context).Value;",
        "                var MaxColorB = inputs[(int)InputId.MaxColorB].Eval(context).Value;",
        "                var MaxColorA = inputs[(int)InputId.MaxColorA].Eval(context).Value;",
        "                var MaxColor = new Color4(MaxColorR, MaxColorG, MaxColorB, MaxColorA);",
        "                //<<< __params",
        "",
        "                if (Image == null)",
        "                    return;",
        "",
        "                ClearRenderTarget(context, new SharpDX.Color4(0, 0, 0, 1));",
        "",
        "                //>>> __setup",
        "                using (var ImageView = new ShaderResourceView(context.D3DDevice, Image))",
        "                {",
        "                    _effect.GetVariableByName(\"RenderTargetSize\").AsVector().Set(new Vector2(_usedViewport.Width, _usedViewport.Height));",
        "                    _effect.GetVariableByName(\"Image\").AsShaderResource().SetResource(ImageView);",
        "                    _effect.GetVariableByName(\"MinColor\").AsVector().Set(MinColor);",
        "                    _effect.GetVariableByName(\"MaxColor\").AsVector().Set(MaxColor);",
        "                //<<< __setup",
        "",
        "                var prevBlendState = context.BlendState;",
        "                context.BlendState = OperatorPartContext.DefaultRenderer.DisabledBlendState;",
        "",
        "                Render(context);",
        "",
        "                context.BlendState = prevBlendState;",
        "",
        "                //>>> _cleanup",
        "                }",
        "                //<<< _cleanup",
        "            });",
        "        }",
        "",
        "    }",
        "}",
        ""
      ],
      "AdditionalAssemblies": []
    }
  ],
  "Operators": [],
  "Connections": [
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "63c11260-1931-4683-bfc6-a981262cc34d",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "ede36d64-a890-4e01-a336-2b25ed27d362"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "a5771ed7-f6cb-405d-bd03-8b3e32a37fb3",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "63c11260-1931-4683-bfc6-a981262cc34d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "04142c02-a899-4676-b9ac-0b66ffacb37a",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "63c11260-1931-4683-bfc6-a981262cc34d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "cb83c3c6-832a-48e2-9dd9-88325b8b9abd",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "63c11260-1931-4683-bfc6-a981262cc34d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "eba6ce4b-046d-48bb-a225-4c8e25d7f470",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "63c11260-1931-4683-bfc6-a981262cc34d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "3fb4b5c8-2555-45f4-9e56-d2a007391c65",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "63c11260-1931-4683-bfc6-a981262cc34d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "9135d05c-1ba8-41b4-b9e7-703fac1c25d8",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "63c11260-1931-4683-bfc6-a981262cc34d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "1d9ba74f-482f-4050-9f10-4d440f48ddbf",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "63c11260-1931-4683-bfc6-a981262cc34d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "47dab691-81fa-4ef1-9dbf-daca4615c7aa",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "63c11260-1931-4683-bfc6-a981262cc34d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "e720adb0-53be-4c47-9981-10c1710c5124",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "63c11260-1931-4683-bfc6-a981262cc34d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "77f6bca2-5912-4d9a-bcc0-4b7f63ddde86",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "63c11260-1931-4683-bfc6-a981262cc34d"
    }
  ]
}