{
  "Name": "Displace2dAngle",
  "_id": "5a098d06-536e-4aa6-8c65-4da1d9f8c4af",
  "Namespace": "lib.image.adjust",
  "Description": "A new version of displace with angle",
  "Inputs": [
    {
      "Name": "Code",
      "MetaInstanceID": "bcec4ef4-2357-4f64-9aca-00e1f92b8fff",
      "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 SampleRadius;",
          "float DisplaceAmount;",
          "float DisplaceOffset;",
          "float SampleCount;",
          "float2 Shift;",
          "float Angle;",
          "//<<< _parameters\r",
          " \r",
          "//>>> setup\r",
          "SamplerState samLinear\r",
          "{\r",
          "    //Filter = MIN_MAG_LINEAR_MIP_POINT;\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",
          "    //float width, height;\r",
          "    //Image.GetDimensions(width, height);\r",
          "    \r",
          "    float sx = SampleRadius / RenderTargetSize.x;\r",
          "    float sy = SampleRadius / RenderTargetSize.y;\r",
          "    \r",
          "\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",
          "\r",
          "    //float sx = SampleRadius / width;\r",
          "    //float sy = SampleRadius / height;\r",
          "\r",
          "    float4 cy1= Displacement.Sample(samLinear, float2(input.texCoord.x,       input.texCoord.y + sy));\r",
          "    float4 cy2= Displacement.Sample(samLinear, float2(input.texCoord.x,       input.texCoord.y - sy));\r",
          "    \r",
          "    float4 cx1= Displacement.Sample(samLinear,  float2(input.texCoord.x + sx, input.texCoord.y));\r",
          "    float4 cx2= Displacement.Sample(samLinear,  float2(input.texCoord.x - sx, input.texCoord.y)); \r",
          "    float4 c =  Displacement.Sample(samLinear, float2(input.texCoord.x,      input.texCoord.y)); \r",
          "\r",
          "/*\r",
          "    float3 c=Displacement.Sample(samLinear, clamp(float2(p.x , p.y ),0,1)).rgb; \r",
          "    float3 cx1=Displacement.Sample(samLinear, clamp(float2(p.x + sx , p.y ),0,1)).rgb; \r",
          "    float3 cx2=Displacement.Sample(samLinear, clamp(float2(p.x - sx , p.y ),0,1)).rgb; \r",
          "    float3 cy1=Displacement.Sample(samLinear, clamp(float2(p.x, p.y + sy  ),0,1)).rgb; \r",
          "    float3 cy2=Displacement.Sample(samLinear, clamp(float2(p.x, p.y - sy  ),0,1)).rgb; \r",
          "*/\r",
          "/*\r",
          "    float cc= length(c.rgb);\r",
          "    float x1= length(cx1.rgb);\r",
          "    float x2= length(cx2.rgb);\r",
          "    float y1= length(cy1.rgb);\r",
          "    float y2= length(cy2.rgb);\r",
          "    */\r",
          "\r",
          "    float cc= (c.r+ c.g +c.b);\r",
          "    float x1= (cx1.r + cx1.g + cx1.b) / 3;\r",
          "    float x2= (cx2.r + cx2.g + cx2.b) / 3;\r",
          "    float y1= (cy1.r + cy1.g + cy1.b) / 3;\r",
          "    float y2= (cy2.r + cy2.g + cy2.b) / 3;\r",
          "\r",
          "    float4 t1= float4(0,0,0,0);\r",
          "    \r",
          "    //float offset= Size.y;\r",
          "    float2 d = float2( (x1-x2) , (y1-y2));\r",
          "    //float2 d = float2( ( cc-x1 + cc-x2) , ( cc-y1 + cc-y2));\r",
          "    float len = length(d);\r",
          "    float a = length(d) ==0 ? 0 :  atan2(d.x, d.y) + Angle / 180 * 3.14158;\r",
          "\r",
          "    //for(float i=-0.5 + DisplaceOffset; i< 0.5 + DisplaceOffset; i+= 1/SampleCount) {\r",
          "    float2 direction = float2( sin(a), cos(a));\r",
          "    float2 p2 = direction * (DisplaceAmount * len + DisplaceOffset) * float2(RenderTargetSize.y/ RenderTargetSize.x, 1);\r",
          "    \r",
          "    //return float4(p2.x*10+0.5, p2.y*10+0.5, 0,1);\r",
          "    \r",
          "    for(float i=-0.5; i< 0.5; i+= 1.0/SampleCount) {    \r",
          "        t1+=Image.Sample(samLinear, input.texCoord + p2 * 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",
          "    float4 c2=t1/SampleCount;\r",
          "    c2.a = clamp( c2.a, 0.00001,1);\r",
          "    return c2;\r",
          "    //return col1+col2;\r",
          "    \r",
          "}\r",
          "//<<< PS\r",
          "\r",
          "\r",
          "technique10 Render",
          "{",
          "    pass P0",
          "    {",
          "        SetGeometryShader( 0 );",
          "        SetVertexShader( CompileShader( vs_4_0, VS() ) );",
          "        SetPixelShader( CompileShader( ps_5_0, PS() ) );",
          "    }",
          "}",
          "\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": "dca26c6d-4078-46ea-bf38-500f857a8666",
      "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": "Displacement",
      "MetaInstanceID": "4c47cbbc-1942-43ee-8a85-6ca732470a08",
      "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": "SampleRadius",
      "MetaInstanceID": "3388407c-3e37-4917-81ae-c9b02ab219f6",
      "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": "DisplaceAmount",
      "MetaInstanceID": "0734a0ea-b2b1-43df-b342-fb15b487b61d",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0.1"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "0.001",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "DisplaceOffset",
      "MetaInstanceID": "17fa4dd4-18d4-469b-a191-29f78b61aa8e",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "0.01",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "SampleCount",
      "MetaInstanceID": "8d7ea3a7-ccee-4900-827d-99d7b28cac7b",
      "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": "40b5233c-9dd3-4648-8774-3db7acc5a749",
      "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": "Shift.Y",
      "MetaInstanceID": "358997cb-533f-4a45-8beb-148343496172",
      "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": "Angle",
      "MetaInstanceID": "daf27c7a-885c-4a66-a5af-f6ec0a0823d8",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "1",
      "ScaleType": "Linear",
      "EnumValues": []
    }
  ],
  "Outputs": [
    {
      "Name": "Image",
      "MetaInstanceID": "8e8d1ae7-b29d-4ed1-a0e5-eb38dc62db02",
      "MetaID": "9848060d-fd84-45b0-b658-d0d531c61dab"
    }
  ],
  "OperatorParts": [
    {
      "MetaInstanceID": "fbf82e65-9dff-4041-a364-4f8f674851d3",
      "MetaID": "19ffd740-32bb-4f31-a976-2ea9dee64b32",
      "Name": "Displace2dAngleFunc",
      "Version": "22a6803f-315f-4311-a5c5-d3b4e9ce6c81",
      "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.ID19ffd740_32bb_4f31_a976_2ea9dee64b32",
        "{",
        "    public class Class_Displace2dAngle : FXImageFunction",
        "    {",
        "        //>>> _inputids",
        "        private enum InputId",
        "        {",
        "            Code = 0,",
        "            Displacement = 1,",
        "            Image = 2,",
        "            SampleRadius = 3,",
        "            DisplaceAmount = 4,",
        "            DisplaceOffset = 5,",
        "            SampleCount = 6,",
        "            ShiftX = 7,",
        "            ShiftY = 8,",
        "            Angle = 9",
        "        }",
        "        //<<< _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; // Needs to be checked for null!",
        "            var Image = inputs[(int)InputId.Image].Eval(context).Image; // Needs to be checked for null!",
        "            var SampleRadius = inputs[(int)InputId.SampleRadius].Eval(context).Value;",
        "            var DisplaceAmount = inputs[(int)InputId.DisplaceAmount].Eval(context).Value;",
        "            var DisplaceOffset = inputs[(int)InputId.DisplaceOffset].Eval(context).Value;",
        "            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);",
        "            var Angle = inputs[(int)InputId.Angle].Eval(context).Value;",
        "            //<<< _params",
        "",
        "            return PrepareAndEvalOnChange(context, () => {",
        "                ClearRenderTarget(context, new SharpDX.Color4(0, 0, 0, 0));",
        "",
        "                SampleCount = (float)Math.Floor(SampleCount);",
        "                //>>> _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(\"SampleRadius\").AsScalar().Set(SampleRadius);",
        "                    _effect.GetVariableByName(\"DisplaceAmount\").AsScalar().Set(DisplaceAmount);",
        "                    _effect.GetVariableByName(\"DisplaceOffset\").AsScalar().Set(DisplaceOffset);",
        "                    _effect.GetVariableByName(\"SampleCount\").AsScalar().Set(SampleCount);",
        "                    _effect.GetVariableByName(\"Shift\").AsVector().Set(new Vector2(ShiftX, ShiftY));",
        "                    _effect.GetVariableByName(\"Angle\").AsScalar().Set(Angle);",
        "                //<<< _setup",
        "",
        "                Render(context);",
        "",
        "                //>>> _cleanup",
        "                }",
        "                //<<< _cleanup",
        "            });",
        "        }",
        "",
        "    }",
        "}",
        "",
        ""
      ],
      "AdditionalAssemblies": []
    }
  ],
  "Operators": [],
  "Connections": [
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "fbf82e65-9dff-4041-a364-4f8f674851d3",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "8e8d1ae7-b29d-4ed1-a0e5-eb38dc62db02"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "bcec4ef4-2357-4f64-9aca-00e1f92b8fff",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "fbf82e65-9dff-4041-a364-4f8f674851d3"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "4c47cbbc-1942-43ee-8a85-6ca732470a08",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "fbf82e65-9dff-4041-a364-4f8f674851d3"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "dca26c6d-4078-46ea-bf38-500f857a8666",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "fbf82e65-9dff-4041-a364-4f8f674851d3"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "3388407c-3e37-4917-81ae-c9b02ab219f6",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "fbf82e65-9dff-4041-a364-4f8f674851d3"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "0734a0ea-b2b1-43df-b342-fb15b487b61d",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "fbf82e65-9dff-4041-a364-4f8f674851d3"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "17fa4dd4-18d4-469b-a191-29f78b61aa8e",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "fbf82e65-9dff-4041-a364-4f8f674851d3"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "8d7ea3a7-ccee-4900-827d-99d7b28cac7b",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "fbf82e65-9dff-4041-a364-4f8f674851d3"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "40b5233c-9dd3-4648-8774-3db7acc5a749",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "fbf82e65-9dff-4041-a364-4f8f674851d3"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "358997cb-533f-4a45-8beb-148343496172",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "fbf82e65-9dff-4041-a364-4f8f674851d3"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "daf27c7a-885c-4a66-a5af-f6ec0a0823d8",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "fbf82e65-9dff-4041-a364-4f8f674851d3"
    }
  ]
}