{
  "Name": "StretchedPixelLine",
  "_id": "dd19af21-97a9-4c8b-a63f-2e393c33de4b",
  "Namespace": "lib.image.blur",
  "Description": "Reduces noise (white pixels) in an image",
  "Inputs": [
    {
      "Name": "Code",
      "MetaInstanceID": "c8ec36a0-b9a7-4292-8aa4-f7168df2a571",
      "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;",
          "float2 Position;",
          "float Width;",
          "float Rotate;",
          "//<<< _parameters\r",
          "float4x4 ViewToWorld;\r",
          " \r",
          "//>>> setup\r",
          "SamplerState samLinear\r",
          "{\r",
          "    Filter = MIN_MAG_MIP_POINT;\r",
          "    AddressU = Clamp;\r",
          "    AddressV = Clamp;\r",
          "};\r",
          "//<<< setup\r",
          "\r",
          "BlendState NoBlend \r",
          "{\r",
          "    AlphaToCoverageEnable = FALSE;\r",
          "    BlendEnable[0] = FALSE;\r",
          "};\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",
          "static const int NUMWT = 10;\r",
          "static const float Gauss[NUMWT] = { 0.93, 0.86, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1 };\r",
          "\r",
          "float4 PS( PS_IN input ) : SV_Target\r",
          "{\r",
          "    float width, height;\r",
          "    Image.GetDimensions(width, height);\r",
          "    \r",
          "    float angle = Rotate / 180.0 * 3.141578;\r",
          "    float2 dir = float2( sin( angle ), cos( angle ));\r",
          "\r",
          "    // Calculate distance to line...\r",
          "    float2 p1 = Position; //float2(0.5,0.5);\r",
          "    float2 p2 = p1 + dir * 0.01; // BUG? Without the multiplication, the shader doesn't compile...\r",
          "    float size= length(dir);\r",
          "    float cx = p2.x - p1.x;\r",
          "    float cy = p2.y - p1.y;\r",
          "    float bx = -cy;\r",
          "    float by = cx;\r",
          "    float x= input.texCoord.x;\r",
          "    float y= input.texCoord.y;\r",
          "    float ex = x - p1.x;\r",
          "    float ey = y - p1.y;\r",
          "    float dist = (ex*by - ey*bx) / (sqrt(bx*bx + by*by));\r",
          "\r",
          "    float2 pos = dir;\r",
          "    \r",
          "    dist = clamp( -dist, 0, Width); \r",
          "    \r",
          "    float2 offset = dist * float2(dir.x , dir.y);    \r",
          "    float4 c = Image.Sample(samLinear, input.texCoord + offset);\r",
          "\r",
          "    return c;\r",
          "}\r",
          "//<<< PS\r",
          "\r",
          "//>>> technique\r",
          "technique10 Render",
          "{",
          "    pass P0",
          "    {",
          "    SetBlendState( NoBlend, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );",
          "        SetGeometryShader( 0 );",
          "        SetVertexShader( CompileShader( vs_4_0, VS() ) );",
          "        SetPixelShader( CompileShader( ps_4_0, PS() ) );",
          "    }",
          "}",
          "//<<< _technique\r",
          "\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": "072365d5-52c6-4564-b417-7d50c09a1f3d",
      "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": "Position.X",
      "MetaInstanceID": "f1ee6dfa-f976-4899-9a66-515ef0864bfa",
      "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": "Position.Y",
      "MetaInstanceID": "52759e63-b678-4c3d-979f-c28922db8e05",
      "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": "Width",
      "MetaInstanceID": "a963ca65-172f-4758-bd17-344d1b48bc95",
      "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": "Rotate",
      "MetaInstanceID": "9a6fde74-f1a8-4469-a8fc-aaf5a2cd74d7",
      "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": []
    }
  ],
  "Outputs": [
    {
      "Name": "Image",
      "MetaInstanceID": "85bbca84-cd44-4686-b475-06f035957367",
      "MetaID": "9848060d-fd84-45b0-b658-d0d531c61dab"
    }
  ],
  "OperatorParts": [
    {
      "MetaInstanceID": "90976559-7a51-41db-bcd1-3afccbe40d49",
      "MetaID": "5d7fff04-d099-489b-a972-ab8edd217441",
      "Name": "StretchedPixelLineFunc",
      "Version": "77f02a2b-7bd0-4ef8-95d5-2e1dfa8b4065",
      "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.ID5d7fff04_d099_489b_a972_ab8edd217441",
        "{",
        "    public class Class_StretchedPixelLine : FXImageFunction",
        "    {",
        "        //>>> _inputids",
        "        private enum InputId",
        "        {",
        "            Code = 0,",
        "            Image = 1,",
        "            PositionX = 2,",
        "            PositionY = 3,",
        "            Width = 4,",
        "            Rotate = 5",
        "        }",
        "        //<<< _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; if (Image == null) return context;",
        "            var PositionX = inputs[(int)InputId.PositionX].Eval(context).Value;",
        "            var PositionY = inputs[(int)InputId.PositionY].Eval(context).Value;",
        "            var Position = new Vector2(PositionX, PositionY);",
        "            var Width = inputs[(int)InputId.Width].Eval(context).Value;",
        "            var Rotate = inputs[(int)InputId.Rotate].Eval(context).Value;",
        "            //<<< _params",
        "",
        "            return PrepareAndEvalOnChange(context, () => {",
        "                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(\"Position\").AsVector().Set(new Vector2(PositionX, PositionY));",
        "                    _effect.GetVariableByName(\"Width\").AsScalar().Set(Width);",
        "                    _effect.GetVariableByName(\"Rotate\").AsScalar().Set(Rotate);",
        "                //<<< _setup",
        "",
        "",
        "                Render(context);",
        "",
        "                //>>> _cleanup",
        "                }",
        "                //<<< _cleanup",
        "            });",
        "        }",
        "",
        "    }",
        "}",
        "",
        ""
      ],
      "AdditionalAssemblies": []
    }
  ],
  "Operators": [],
  "Connections": [
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "90976559-7a51-41db-bcd1-3afccbe40d49",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "85bbca84-cd44-4686-b475-06f035957367"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "c8ec36a0-b9a7-4292-8aa4-f7168df2a571",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "90976559-7a51-41db-bcd1-3afccbe40d49"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "072365d5-52c6-4564-b417-7d50c09a1f3d",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "90976559-7a51-41db-bcd1-3afccbe40d49"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "f1ee6dfa-f976-4899-9a66-515ef0864bfa",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "90976559-7a51-41db-bcd1-3afccbe40d49"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "52759e63-b678-4c3d-979f-c28922db8e05",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "90976559-7a51-41db-bcd1-3afccbe40d49"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "a963ca65-172f-4758-bd17-344d1b48bc95",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "90976559-7a51-41db-bcd1-3afccbe40d49"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "9a6fde74-f1a8-4469-a8fc-aaf5a2cd74d7",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "90976559-7a51-41db-bcd1-3afccbe40d49"
    }
  ]
}