{
  "Name": "RadialBlur",
  "_id": "483e5cab-e176-46dd-a3bf-b818283247d7",
  "Namespace": "lib.image.blur",
  "Description": "does a radial blur arount the given center.\r\ncenter is in texture coordinates:\r\nlower left: 0, 1\r\nupper right: 1, 0",
  "Inputs": [
    {
      "Name": "Code",
      "MetaInstanceID": "68d4b99a-afdf-4d29-8da6-cb8404c72301",
      "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 Brightness;",
          "float Contrast;",
          "float Size;",
          "float2 Center;",
          "float NumberofSamples;",
          "float Offset;",
          "//<<< _parameters\r",
          "\r",
          "//>>> setup\r",
          "SamplerState samLinear\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",
          "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",
          "    float2 r = input.texCoord - Center;    \r",
          "    float4 c= float4(0,0,0,0);\r",
          "    float totalWeight = 0;\r",
          "   \r",
          "\r",
          "    for (int i = 0; i < NumberofSamples; ++i) {\r",
          "        float ir = i/floor(NumberofSamples);\r",
          "        float weightIndex = (int)(abs(ir*2-1)*1 * (NUMWT-1));\r",
          "        float weight = lerp(Gauss[weightIndex], Gauss[(int)weightIndex + 1], frac(weightIndex));\r",
          "    \r",
          "        float f= max(0, (ir - 0.5 + Offset) * 0.01*Size +1);\r",
          "        float2 p = Center + f * r ;\r",
          "        c += Image.Sample(samLinear, p)*weight;\r",
          "        totalWeight += weight;\r",
          "    }\r",
          "\r",
          "    c.rgba = float4(Contrast, Contrast, Contrast, Contrast) + c.rgba/totalWeight*Brightness;\r",
          "    //c.a= c.a;\r",
          "    //c.a = 1.0;\r",
          "    return c;\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": "831e6e45-5904-46ff-8666-beb1776097bd",
      "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": "Brightness",
      "MetaInstanceID": "666ec923-20ee-48c9-a28d-31556903cf0a",
      "DefaultValue": {
        "Type": "Float",
        "Value": "1"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "0.001",
      "Max": "10",
      "Scale": "0.001",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Contrast",
      "MetaInstanceID": "2ed1c987-7bfb-4062-bd3f-a3ca7a4e2bb7",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-10",
      "Max": "10",
      "Scale": "0.001",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Size",
      "MetaInstanceID": "0f0fc554-9444-45f6-814a-88e451f98ad1",
      "DefaultValue": {
        "Type": "Float",
        "Value": "10"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "0",
      "Max": "100",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Center.X",
      "MetaInstanceID": "b9c74537-712d-4db8-9c44-d35831f7591f",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0.5"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-100",
      "Max": "100",
      "Scale": "0.01",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Center.Y",
      "MetaInstanceID": "13e80779-efd1-43af-a10b-a7550511e89f",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0.5"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-100",
      "Max": "100",
      "Scale": "0.01",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Number of Samples",
      "MetaInstanceID": "ce6162cd-64ea-4f41-92a4-63da2e78bfc3",
      "DefaultValue": {
        "Type": "Float",
        "Value": "9"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "0",
      "Max": "100",
      "Scale": "1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Offset",
      "MetaInstanceID": "01d8f0bf-21be-4ed1-a0da-7f4403281923",
      "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": "4de89d28-612f-4407-a279-4b92a3470283",
      "MetaID": "9848060d-fd84-45b0-b658-d0d531c61dab"
    }
  ],
  "OperatorParts": [
    {
      "MetaInstanceID": "292107ce-9737-4b08-8456-cf4c97a21bc3",
      "MetaID": "7302c7eb-85de-4cef-a1cd-9f59550d80a8",
      "Name": "RadialBlurFunc",
      "Version": "cd133754-33ee-41a3-a2fd-98ad1ea45218",
      "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.ID7302c7eb_85de_4cef_a1cd_9f59550d80a8",
        "{",
        "    public class Class_RadialBlur : FXImageFunction",
        "    {",
        "        //>>> _inputids",
        "        private enum InputId",
        "        {",
        "            Code = 0,",
        "            Image = 1,",
        "            Brightness = 2,",
        "            Contrast = 3,",
        "            Size = 4,",
        "            CenterX = 5,",
        "            CenterY = 6,",
        "            NumberofSamples = 7,",
        "            Offset = 8",
        "        }",
        "        //<<< _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 Brightness = inputs[(int)InputId.Brightness].Eval(context).Value;",
        "            var Contrast = inputs[(int)InputId.Contrast].Eval(context).Value;",
        "            var Size = inputs[(int)InputId.Size].Eval(context).Value;",
        "            var CenterX = inputs[(int)InputId.CenterX].Eval(context).Value;",
        "            var CenterY = inputs[(int)InputId.CenterY].Eval(context).Value;",
        "            var Center = new Vector2(CenterX, CenterY);",
        "            var NumberofSamples = inputs[(int)InputId.NumberofSamples].Eval(context).Value;",
        "            var Offset = inputs[(int)InputId.Offset].Eval(context).Value;",
        "            //<<< _params",
        "",
        "            return PrepareAndEvalOnChange(context, () => {",
        "                ClearRenderTarget(context, new SharpDX.Color4(0, 0, 0, 0));",
        "                //_effect.BlendState = OperatorPartContext.DefaultRenderer.DisabledBlendState;",
        "                //ClearRenderTarget(context, new SharpDX.Color4(1, 1, 1, 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(\"Brightness\").AsScalar().Set(Brightness);",
        "                    _effect.GetVariableByName(\"Contrast\").AsScalar().Set(Contrast);",
        "                    _effect.GetVariableByName(\"Size\").AsScalar().Set(Size);",
        "                    _effect.GetVariableByName(\"Center\").AsVector().Set(new Vector2(CenterX, CenterY));",
        "                    _effect.GetVariableByName(\"NumberofSamples\").AsScalar().Set(NumberofSamples);",
        "                    _effect.GetVariableByName(\"Offset\").AsScalar().Set(Offset);",
        "                //<<< _setup",
        "                //_blendState = OperatorPartContext.DefaultRenderer.DisabledBlendState;",
        "",
        "",
        "                var blendStateDescription = new BlendStateDescription();",
        "                blendStateDescription.RenderTarget[0].IsBlendEnabled = true;",
        "                blendStateDescription.RenderTarget[0].SourceBlend = BlendOption.One; //BlendOption.SourceAlpha;",
        "                blendStateDescription.RenderTarget[0].DestinationBlend =  BlendOption.Zero; //BlendOption.InverseSourceAlpha;",
        "                blendStateDescription.RenderTarget[0].BlendOperation = BlendOperation.Add;",
        "                blendStateDescription.RenderTarget[0].SourceAlphaBlend = BlendOption.One;// BlendOption.SourceAlpha;",
        "                blendStateDescription.RenderTarget[0].DestinationAlphaBlend = BlendOption.Zero; //BlendOption.DestinationAlpha;",
        "                blendStateDescription.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add;",
        "                blendStateDescription.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;",
        "                //blendStateDescription.RenderTarget[0].IsBlendEnabled = false;                ",
        "                //blendStateDescription.AlphaToCoverageEnable = true;",
        "                _blendState = new BlendState(D3DDevice.Device, blendStateDescription);",
        "",
        "                ",
        "                Render(context);",
        "",
        "                //>>> _cleanup",
        "                }",
        "                //<<< _cleanup",
        "            });",
        "        }",
        "",
        "    }",
        "}",
        ""
      ],
      "AdditionalAssemblies": []
    }
  ],
  "Operators": [],
  "Connections": [
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "292107ce-9737-4b08-8456-cf4c97a21bc3",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "4de89d28-612f-4407-a279-4b92a3470283"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "68d4b99a-afdf-4d29-8da6-cb8404c72301",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "292107ce-9737-4b08-8456-cf4c97a21bc3"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "831e6e45-5904-46ff-8666-beb1776097bd",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "292107ce-9737-4b08-8456-cf4c97a21bc3"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "666ec923-20ee-48c9-a28d-31556903cf0a",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "292107ce-9737-4b08-8456-cf4c97a21bc3"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "2ed1c987-7bfb-4062-bd3f-a3ca7a4e2bb7",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "292107ce-9737-4b08-8456-cf4c97a21bc3"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "0f0fc554-9444-45f6-814a-88e451f98ad1",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "292107ce-9737-4b08-8456-cf4c97a21bc3"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "b9c74537-712d-4db8-9c44-d35831f7591f",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "292107ce-9737-4b08-8456-cf4c97a21bc3"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "13e80779-efd1-43af-a10b-a7550511e89f",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "292107ce-9737-4b08-8456-cf4c97a21bc3"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "ce6162cd-64ea-4f41-92a4-63da2e78bfc3",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "292107ce-9737-4b08-8456-cf4c97a21bc3"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "01d8f0bf-21be-4ed1-a0da-7f4403281923",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "292107ce-9737-4b08-8456-cf4c97a21bc3"
    }
  ]
}