{
  "Name": "DetectEdges",
  "_id": "d6760adf-5384-4eea-931f-b5c0714f7632",
  "Namespace": "lib.image.effect",
  "Description": "",
  "Inputs": [
    {
      "Name": "Code",
      "MetaInstanceID": "2ab9e7f0-4e72-4357-ad81-98e983107fe7",
      "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;",
          "float Strength;",
          "float SampleRadius;",
          "float Contrast;",
          "//<<< _parameters\r",
          " \r",
          "//>>> setup\r",
          "SamplerState samLinear\r",
          "{\r",
          "    Filter = MIN_MAG_LINEAR_MIP_POINT;\r",
          "    //Filter = MIN_MAG_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",
          "float4 PS( PS_IN input ) : SV_Target\r",
          "{\r",
          "    float width, height;\r",
          "    Image.GetDimensions(width, height);\r",
          "    \r",
          "    float sx = SampleRadius / width;\r",
          "    float sy = SampleRadius / height;\r",
          "\r",
          "    float4 y1= Image.Sample(samLinear, float2(input.texCoord.x,       input.texCoord.y + sy));\r",
          "    float4 y2= Image.Sample(samLinear, float2(input.texCoord.x,       input.texCoord.y - sy));\r",
          "    \r",
          "    float4 x1= Image.Sample(samLinear,  float2(input.texCoord.x + sx, input.texCoord.y));\r",
          "    float4 x2= Image.Sample(samLinear,  float2(input.texCoord.x - sx, input.texCoord.y)); \r",
          "    float4 m =  Image.Sample(samLinear, float2(input.texCoord.x,      input.texCoord.y)); \r",
          "    //return ((m-y1) + (m-y2) + (m-x1) + (m-x2)) * Strength;\r",
          "    \r",
          "    float average =  (           \r",
          "                    abs(x1.r-m.r) + abs(x2.r-m.r) + abs(y1.r - m.r) +abs(y2.r - m.r) +\r",
          "                    abs(x1.g-m.g) + abs(x2.g-m.g) + abs(y1.g - m.g) +abs(y2.g - m.g) +\r",
          "                    abs(x1.b-m.b) + abs(x2.b-m.b) + abs(y1.b - m.b) +abs(y2.b - m.b)\r",
          "                ) * Strength + Contrast;\r",
          "    \r",
          "    return  clamp(float4(average,average,average,1),0 , 10000);\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": "c2e438ee-873d-4a44-8314-00f1fe463dc1",
      "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": "Strength",
      "MetaInstanceID": "a0646a34-1fd0-4f43-8996-1466a4a9f7ba",
      "DefaultValue": {
        "Type": "Float",
        "Value": "1"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "0.01",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "SampleRadius",
      "MetaInstanceID": "1c0598d9-fe84-409c-84cb-1ba08ec94d95",
      "DefaultValue": {
        "Type": "Float",
        "Value": "1"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "0.01",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Contrast",
      "MetaInstanceID": "f243d2b9-485f-4e34-88ec-7a53bccf7beb",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0.05"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    }
  ],
  "Outputs": [
    {
      "Name": "Image",
      "MetaInstanceID": "95103d9c-ebb6-49d1-a434-493c6d189f53",
      "MetaID": "9848060d-fd84-45b0-b658-d0d531c61dab"
    }
  ],
  "OperatorParts": [
    {
      "MetaInstanceID": "8a1bd457-9c04-43cf-98f3-249732ce0862",
      "MetaID": "7f63c4ac-74c8-4e23-a04d-6c75a9fac787",
      "Name": "DetectEdgesFunc",
      "Version": "f55611be-7fb6-48ef-b506-c8bf57fd35f0",
      "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.ID7f63c4ac_74c8_4e23_a04d_6c75a9fac787",
        "{",
        "    public class Class_DetectEdges : FXImageFunction",
        "    {",
        "        //>>> _inputids",
        "        private enum InputId",
        "        {",
        "            Code = 0,",
        "            Image = 1,",
        "            Strength = 2,",
        "            SampleRadius = 3,",
        "            Contrast = 4",
        "        }",
        "        //<<< _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 Strength = inputs[(int)InputId.Strength].Eval(context).Value;",
        "            var SampleRadius = inputs[(int)InputId.SampleRadius].Eval(context).Value;",
        "            var Contrast = inputs[(int)InputId.Contrast].Eval(context).Value;",
        "            //<<< _params",
        "            ",
        "            if(Image == null)",
        "                return context;",
        "",
        "",
        "            return PrepareAndEvalOnChange(context, () => {",
        "                ClearRenderTarget(context, new SharpDX.Color4(0, 0, 0, 0));",
        "",
        "                //>>> _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(\"Strength\").AsScalar().Set(Strength);",
        "                    _effect.GetVariableByName(\"SampleRadius\").AsScalar().Set(SampleRadius);",
        "                    _effect.GetVariableByName(\"Contrast\").AsScalar().Set(Contrast);",
        "                //<<< _setup",
        "",
        "                Render(context);",
        "",
        "                //>>> _cleanup",
        "                }",
        "                //<<< _cleanup",
        "            });",
        "        }",
        "",
        "    }",
        "}",
        "",
        ""
      ],
      "AdditionalAssemblies": []
    }
  ],
  "Operators": [],
  "Connections": [
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "8a1bd457-9c04-43cf-98f3-249732ce0862",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "95103d9c-ebb6-49d1-a434-493c6d189f53"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "2ab9e7f0-4e72-4357-ad81-98e983107fe7",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "8a1bd457-9c04-43cf-98f3-249732ce0862"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "c2e438ee-873d-4a44-8314-00f1fe463dc1",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "8a1bd457-9c04-43cf-98f3-249732ce0862"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "a0646a34-1fd0-4f43-8996-1466a4a9f7ba",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "8a1bd457-9c04-43cf-98f3-249732ce0862"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "1c0598d9-fe84-409c-84cb-1ba08ec94d95",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "8a1bd457-9c04-43cf-98f3-249732ce0862"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "f243d2b9-485f-4e34-88ec-7a53bccf7beb",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "8a1bd457-9c04-43cf-98f3-249732ce0862"
    }
  ]
}