{
  "Name": "Displace2d",
  "_id": "2e706232-6d85-4922-a60b-ba9a42833bd6",
  "Namespace": "lib.image.adjust",
  "Description": "",
  "Inputs": [
    {
      "Name": "Code",
      "MetaInstanceID": "c3901ddd-c5ed-4e24-8b34-88f4883220e3",
      "DefaultValue": {
        "Type": "Text",
        "Value": [
          "//>>> _common parameters\r",
          "float4x4 objectToWorldMatrix;",
          "float4x4 worldToCameraMatrix;",
          "float4x4 projMatrix;",
          "Texture2D txDiffuse;",
          "float2 RenderTargetSize;",
          "//<<< _common parameters\r",
          "\r",
          "//>>> _parameters\r",
          "Texture2D Displacement;",
          "Texture2D Image;",
          "float Radius;",
          "float2 Size;",
          "float SampleCount;",
          "float2 Shift;",
          "//<<< _parameters\r",
          " \r",
          "//>>> setup\r",
          "SamplerState samLinear\r",
          "{\r",
          "    Filter = MIN_MAG_MIP_LINEAR;\r",
          "    AddressU = Wrap;\r",
          "    AddressV = Wrap;\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",
          "    float2 p=input.texCoord + Shift;\r",
          "    \r",
          "    \r",
          "    float x1=Displacement.Sample(samLinear, float2(p.x + Radius , p.y )).g; \r",
          "    float x2=Displacement.Sample(samLinear, float2(p.x - Radius , p.y )).g; \r",
          "    float y1=Displacement.Sample(samLinear, float2(p.x, p.y + Radius  )).g; \r",
          "    float y2=Displacement.Sample(samLinear, float2(p.x, p.y - Radius  )).g; \r",
          "    \r",
          "    float4 t1= float4(0,0,0,0);\r",
          "    for(float i=-0.5; i< 0.5; i+= 1/SampleCount) {\r",
          "        t1+=Image.Sample(samLinear, input.texCoord + float2( (x1-x2)* Size.x*i, (y1-y2)* Size.y*i )); \r",
          "    }\r",
          "    \r",
          "\r",
          "    //float a = t0.a + t1.a - t0.a * t1.a;\r",
          "    //float3 rgb=  t0.rgb * t1.a * t1.rgb;   \r",
          "    return t1/SampleCount;\r",
          "    //return col1+col2;\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": "Displacement",
      "MetaInstanceID": "99b74aa2-0b38-4af4-bf1f-c0247b9c921f",
      "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": "Image",
      "MetaInstanceID": "a98f2f97-635a-40fb-bf0c-998f85b285fb",
      "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": "Radius",
      "MetaInstanceID": "6b5236de-7b11-4cfb-b5e0-6cf14c946b75",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0.0300003"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Size.X",
      "MetaInstanceID": "8fed1244-c59f-4183-831c-d3652430cc72",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Size.Y",
      "MetaInstanceID": "b94c4f8c-d8c4-4bc7-9507-d883d8f88d74",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "SampleCount",
      "MetaInstanceID": "647e83e5-316f-4e7e-ba81-85059172457d",
      "DefaultValue": {
        "Type": "Float",
        "Value": "1"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "1",
      "Max": "100000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Shift.X",
      "MetaInstanceID": "93fd34ef-6941-4b79-98c4-8fab02b5400b",
      "DefaultValue": {
        "Type": "Float",
        "Value": "1"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-10000",
      "Max": "10000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Shift.Y",
      "MetaInstanceID": "8dcf574e-bedb-4b59-b190-e276fe3423db",
      "DefaultValue": {
        "Type": "Float",
        "Value": "1"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-10000",
      "Max": "10000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    }
  ],
  "Outputs": [
    {
      "Name": "Image",
      "MetaInstanceID": "0659e5db-a3cc-455a-877d-04e184a3a1ec",
      "MetaID": "9848060d-fd84-45b0-b658-d0d531c61dab"
    }
  ],
  "OperatorParts": [
    {
      "MetaInstanceID": "b5657fff-4dc7-4296-a46c-a6892f4e0107",
      "MetaID": "5afe15a6-0014-49e1-855b-d3d83fd20950",
      "Name": "Displace2dFunc",
      "Version": "29778ee9-31ec-4a73-a9f3-673cab0b70a7",
      "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.ID5afe15a6_0014_49e1_855b_d3d83fd20950",
        "{",
        "    public class Class_Displace2d : FXImageFunction",
        "    {",
        "        //>>> _inputids",
        "        private enum InputId",
        "        {",
        "            Code = 0,",
        "            Displacement = 1,",
        "            Image = 2,",
        "            Radius = 3,",
        "            SizeX = 4,",
        "            SizeY = 5,",
        "            SampleCount = 6,",
        "            ShiftX = 7,",
        "            ShiftY = 8",
        "        }",
        "        //<<< _inputids",
        "        public override OperatorPartContext Eval(OperatorPartContext context, List<OperatorPart> inputs, int outputIdx) {",
        "",
        "            //>>> _params",
        "            var Code = inputs[(int)InputId.Code].Eval(context).Text;",
        "            var Displacement = inputs[(int)InputId.Displacement].Eval(context).Image; if (Displacement == null) return context;",
        "            var Image = inputs[(int)InputId.Image].Eval(context).Image; if (Image == null) return context;",
        "            var Radius = inputs[(int)InputId.Radius].Eval(context).Value;",
        "            var SizeX = inputs[(int)InputId.SizeX].Eval(context).Value;",
        "            var SizeY = inputs[(int)InputId.SizeY].Eval(context).Value;",
        "            var Size = new Vector2(SizeX, SizeY);",
        "            var SampleCount = inputs[(int)InputId.SampleCount].Eval(context).Value;",
        "            var ShiftX = inputs[(int)InputId.ShiftX].Eval(context).Value;",
        "            var ShiftY = inputs[(int)InputId.ShiftY].Eval(context).Value;",
        "            var Shift = new Vector2(ShiftX, ShiftY);",
        "            //<<< _params",
        "",
        "            return PrepareAndEvalOnChange(context, () => {",
        "                ClearRenderTarget(context, new SharpDX.Color4(0, 0, 0, 0));",
        "",
        "                //>>> _setup",
        "                using (var DisplacementView = new ShaderResourceView(context.D3DDevice, Displacement))",
        "                using (var ImageView = new ShaderResourceView(context.D3DDevice, Image))",
        "                {",
        "                    _effect.GetVariableByName(\"RenderTargetSize\").AsVector().Set(new Vector2(_usedViewport.Width, _usedViewport.Height));",
        "                    _effect.GetVariableByName(\"Displacement\").AsShaderResource().SetResource(DisplacementView);",
        "                    _effect.GetVariableByName(\"Image\").AsShaderResource().SetResource(ImageView);",
        "                    _effect.GetVariableByName(\"Radius\").AsScalar().Set(Radius);",
        "                    _effect.GetVariableByName(\"Size\").AsVector().Set(new Vector2(SizeX, SizeY));",
        "                    _effect.GetVariableByName(\"SampleCount\").AsScalar().Set(SampleCount);",
        "                    _effect.GetVariableByName(\"Shift\").AsVector().Set(new Vector2(ShiftX, ShiftY));",
        "                //<<< _setup",
        "",
        "                Render(context);",
        "",
        "                //>>> _cleanup",
        "                }",
        "                //<<< _cleanup",
        "            });",
        "        }",
        "",
        "    }",
        "}",
        "",
        ""
      ],
      "AdditionalAssemblies": []
    }
  ],
  "Operators": [],
  "Connections": [
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "b5657fff-4dc7-4296-a46c-a6892f4e0107",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "0659e5db-a3cc-455a-877d-04e184a3a1ec"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "c3901ddd-c5ed-4e24-8b34-88f4883220e3",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "b5657fff-4dc7-4296-a46c-a6892f4e0107"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "99b74aa2-0b38-4af4-bf1f-c0247b9c921f",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "b5657fff-4dc7-4296-a46c-a6892f4e0107"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "a98f2f97-635a-40fb-bf0c-998f85b285fb",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "b5657fff-4dc7-4296-a46c-a6892f4e0107"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "6b5236de-7b11-4cfb-b5e0-6cf14c946b75",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "b5657fff-4dc7-4296-a46c-a6892f4e0107"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "8fed1244-c59f-4183-831c-d3652430cc72",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "b5657fff-4dc7-4296-a46c-a6892f4e0107"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "b94c4f8c-d8c4-4bc7-9507-d883d8f88d74",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "b5657fff-4dc7-4296-a46c-a6892f4e0107"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "647e83e5-316f-4e7e-ba81-85059172457d",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "b5657fff-4dc7-4296-a46c-a6892f4e0107"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "93fd34ef-6941-4b79-98c4-8fab02b5400b",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "b5657fff-4dc7-4296-a46c-a6892f4e0107"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "8dcf574e-bedb-4b59-b190-e276fe3423db",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "b5657fff-4dc7-4296-a46c-a6892f4e0107"
    }
  ]
}