{
  "Name": "ChromaticAbberation2",
  "_id": "a3f743ae-0e5b-48cb-9d9c-b62565e45e74",
  "Namespace": "lib.image",
  "Description": "A combination of blur, lense distort, chromatic abberation.",
  "Inputs": [
    {
      "Name": "Code",
      "MetaInstanceID": "a827ea83-9fc4-4e72-997e-9e61af369ddc",
      "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 Size;",
          "float2 CenterOffset;",
          "float2 Bulge;",
          "float Samples;",
          "float Scale;",
          "float Intensity;",
          "//<<< _parameters\r",
          "\r",
          "//Texture2D txDepth;\r",
          "float4x4 viewToCamera;\r",
          " \r",
          "//>>> _setup\r",
          "SamplerState samLinear",
          "{",
          "    Filter = MIN_MAG_MIP_LINEAR;",
          "    AddressU = Clamp;",
          "    AddressV = Clamp;",
          "};",
          "//<<< _setup\r",
          "\r",
          "//>>> _declarations\r",
          "struct VS_IN",
          "{",
          "    float4 pos : POSITION;",
          "    float2 texCoord : TEXCOORD;",
          "};",
          "",
          "struct PS_IN",
          "{",
          "    float4 pos : SV_POSITION;",
          "    float2 texCoord: TEXCOORD0;",
          "};",
          "//<<< _declarations\r",
          "\r",
          "//>>> _GS\r",
          "",
          "//<<< _GS\r",
          "\r",
          "//>>> VS \r",
          "PS_IN VS( VS_IN input )\r",
          "{\r",
          "    PS_IN output = (PS_IN)0;\r",
          "\r",
          "    input.pos = mul(input.pos, objectToWorldMatrix); \r",
          "    output.pos = mul(input.pos, worldToCameraMatrix);\r",
          "    output.pos = mul(output.pos, projMatrix);\r",
          "    output.texCoord = input.texCoord;\r",
          "\r",
          "    return output;\r",
          "}\r",
          "//<<< VS\r",
          "\r",
          "\r",
          "//>>> PS\r",
          "\r",
          "float4 chromaShift(float4 c, float range) {\r",
          "    return float4(\r",
          "        c.r * clamp( 1.5 - abs(range + 1), 0,1) * 2,\r",
          "        c.g * clamp( 1.5 - abs(range ), 0,1),\r",
          "        c.b * clamp( 1.5 - abs(range - 1), 0,1) * 2,\r",
          "        c.a\r",
          "    );\r",
          "}\r",
          "\r",
          "\r",
          "float4 chromaShift2(float4 c, float range) {\r",
          "    range = (range+0.0); \r",
          "    //range = range * 2 +0.5 ;\r",
          "    return float4(\r",
          "        c.r * (sin(( clamp(range,0,0.5)-0.75) * 3.1415 * 2)/ 2+0.5) * 4,\r",
          "        c.g * (sin((range-0.25) * 3.1415 * 2)/ 2+0.5)*2,\r",
          "        c.b * (sin(( clamp(range,0.5,1)-0.75) * 3.1415 * 2)/ 2+0.5)*4,\r",
          "        c.a\r",
          "    );\r",
          "}\r",
          "\r",
          "\r",
          "\r",
          "float4 psGodRays( PS_IN input ) : SV_Target\r",
          "{\r",
          "    float2 p = input.texCoord;\r",
          "    \r",
          "    float2 d = (float2(0.5, 0.5) + CenterOffset - p) / Scale;\r",
          "    float l = length(d) + Bulge.y;\r",
          "\r",
          "    float bulge= Bulge.x;\r",
          "    float s2= 1;\r",
          "    if( bulge < 0) {\r",
          "        s2 = 1+bulge*0.5;\r",
          "    }\r",
          "    else {\r",
          "        s2 = 1+bulge*0.5;\r",
          "    }\r",
          "    \r",
          "    float2 sampleDir = (d *  pow(l, Bulge.x) * s2);\r",
          "    p = float2(0.5, 0.5) + CenterOffset - sampleDir;\r",
          "    \r",
          "\r",
          "    float sampleStep = 1;    \r",
          "    float samplesFloored = floor(Samples);\r",
          "    \r",
          "    float radialStrength= Size * pow(sampleDir.Length,0.3)/ 100;\r",
          "    float2 dir = sampleStep * radialStrength /Samples*sampleDir;\r",
          "\r",
          "    float2 pos = -dir* Samples/2;\r",
          "    float distanceToCenter;\r",
          "    float4 c= float4(0,0,0,0);\r",
          "    float4 c2 = float4(0,0,0,0);\r",
          "    for (int i = 0; i < samplesFloored; ++i)\r",
          "    {\r",
          "        float2 p2 = p + pos;\r",
          "        float4 cP2 = Image.SampleLevel(samLinear, p2, 0);\r",
          "        c += chromaShift(cP2, (i+0.5) / Samples - 0.5)  / Samples;\r",
          "        //c += chromaShift2(cP2, (i+0.5) / samplesFloored)  / samplesFloored;\r",
          "        \r",
          "        c2+= cP2 / samplesFloored;\r",
          "        pos += dir;\r",
          "    }\r",
          "    \r",
          "    //float4 corg = Image.SampleLevel(samLinear, p, 0);\r",
          "    c.rgb = lerp(c2.rgb, c.rgb, Intensity);\r",
          "    return c;\r",
          "}\r",
          "//<<< PS\r",
          "\r",
          "\r",
          "//>>> __technique\r",
          "technique10 GodRays",
          "{",
          "    pass GodRays",
          "    {",
          "        SetGeometryShader( 0 );",
          "        SetVertexShader( CompileShader( vs_4_0, VS() ) );",
          "        SetPixelShader( CompileShader( ps_4_0, psGodRays() ) );",
          "    }",
          "}",
          "//<<< __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": "87384be8-e9dc-4378-9159-a3ca3e915f0e",
      "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": "Size",
      "MetaInstanceID": "5228393b-96be-40bb-a195-27793fe94aa8",
      "DefaultValue": {
        "Type": "Float",
        "Value": "20"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "CenterOffset.X",
      "MetaInstanceID": "248aff30-630d-4b97-8f4f-889e72cb11cd",
      "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": "CenterOffset.Y",
      "MetaInstanceID": "d036b8a2-1d03-456d-9c0c-52a6198d973b",
      "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": "Bulge.Amount",
      "MetaInstanceID": "9c357c81-58a0-4e6a-8b2d-81570b88cf54",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-10000",
      "Max": "10000",
      "Scale": "0.01",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Bulge.Offset",
      "MetaInstanceID": "6cb35d4e-09f7-4e09-b654-17443b095b3c",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0.03000004"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-10000",
      "Max": "10000",
      "Scale": "0.01",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Samples",
      "MetaInstanceID": "f63b5f17-d540-45fe-a91e-a44303af5884",
      "DefaultValue": {
        "Type": "Float",
        "Value": "30"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-10000",
      "Max": "10000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Scale",
      "MetaInstanceID": "340843d8-18c4-4a0a-a608-985b49f03380",
      "DefaultValue": {
        "Type": "Float",
        "Value": "1"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-10000",
      "Max": "10000",
      "Scale": "0.001",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Intensity",
      "MetaInstanceID": "b229800d-23a0-45e0-827f-3c364301e919",
      "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": []
    }
  ],
  "Outputs": [
    {
      "Name": "Image",
      "MetaInstanceID": "633d5fb9-60a3-4cb0-9e4a-8e25344b47b4",
      "MetaID": "9848060d-fd84-45b0-b658-d0d531c61dab"
    }
  ],
  "OperatorParts": [
    {
      "MetaInstanceID": "251c27bf-5ad9-4824-8255-2b67734c399e",
      "MetaID": "17edb483-8ac4-4de6-af55-da4f0cd357be",
      "Name": "ChromaticAbberation2Func",
      "Version": "80aaec4f-4f3c-44f4-92db-b6d954271f21",
      "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",
        "using SharpDX.DXGI;",
        "using SharpDX.D3DCompiler;",
        "using SharpDX.Direct3D; ",
        "using Framefield.Core.Rendering;",
        "using System.Dynamic;",
        "using Framefield.Core;",
        "",
        "namespace Framefield.Core.ID17edb483_8ac4_4de6_af55_da4f0cd357be",
        "{",
        "    public class Class_ChromaticAbberation2 : FXImageFunction",
        "    {",
        "        //>>> _inputids",
        "        private enum InputId",
        "        {",
        "            Code = 0,",
        "            Image = 1,",
        "            Size = 2,",
        "            CenterOffsetX = 3,",
        "            CenterOffsetY = 4,",
        "            BulgeAmount = 5,",
        "            BulgeOffset = 6,",
        "            Samples = 7,",
        "            Scale = 8,",
        "            Intensity = 9",
        "        }",
        "        //<<< _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 Size = inputs[(int)InputId.Size].Eval(context).Value;",
        "            var CenterOffsetX = inputs[(int)InputId.CenterOffsetX].Eval(context).Value;",
        "            var CenterOffsetY = inputs[(int)InputId.CenterOffsetY].Eval(context).Value;",
        "            var CenterOffset = new Vector2(CenterOffsetX, CenterOffsetY);",
        "            var BulgeAmount = inputs[(int)InputId.BulgeAmount].Eval(context).Value;",
        "            var BulgeOffset = inputs[(int)InputId.BulgeOffset].Eval(context).Value;",
        "            var Bulge = new Vector2(BulgeAmount, BulgeOffset);",
        "            var Samples = inputs[(int)InputId.Samples].Eval(context).Value;",
        "            var Scale = inputs[(int)InputId.Scale].Eval(context).Value;",
        "            var Intensity = inputs[(int)InputId.Intensity].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(\"Size\").AsScalar().Set(Size);",
        "                    _effect.GetVariableByName(\"CenterOffset\").AsVector().Set(new Vector2(CenterOffsetX, CenterOffsetY));",
        "                    _effect.GetVariableByName(\"Bulge\").AsVector().Set(new Vector2(BulgeAmount, BulgeOffset));",
        "                    _effect.GetVariableByName(\"Samples\").AsScalar().Set(Samples);",
        "                    _effect.GetVariableByName(\"Scale\").AsScalar().Set(Scale);",
        "                    _effect.GetVariableByName(\"Intensity\").AsScalar().Set(Intensity);",
        "                //<<< _setup",
        "",
        "                Render(context);",
        "",
        "                //>>> _cleanup",
        "                }",
        "                //<<< _cleanup",
        "            });",
        "        }",
        "",
        "    }",
        "}",
        "",
        ""
      ],
      "AdditionalAssemblies": []
    }
  ],
  "Operators": [],
  "Connections": [
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "251c27bf-5ad9-4824-8255-2b67734c399e",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "633d5fb9-60a3-4cb0-9e4a-8e25344b47b4"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "a827ea83-9fc4-4e72-997e-9e61af369ddc",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "251c27bf-5ad9-4824-8255-2b67734c399e"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "87384be8-e9dc-4378-9159-a3ca3e915f0e",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "251c27bf-5ad9-4824-8255-2b67734c399e"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "5228393b-96be-40bb-a195-27793fe94aa8",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "251c27bf-5ad9-4824-8255-2b67734c399e"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "248aff30-630d-4b97-8f4f-889e72cb11cd",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "251c27bf-5ad9-4824-8255-2b67734c399e"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "d036b8a2-1d03-456d-9c0c-52a6198d973b",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "251c27bf-5ad9-4824-8255-2b67734c399e"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "9c357c81-58a0-4e6a-8b2d-81570b88cf54",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "251c27bf-5ad9-4824-8255-2b67734c399e"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "6cb35d4e-09f7-4e09-b654-17443b095b3c",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "251c27bf-5ad9-4824-8255-2b67734c399e"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "f63b5f17-d540-45fe-a91e-a44303af5884",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "251c27bf-5ad9-4824-8255-2b67734c399e"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "340843d8-18c4-4a0a-a608-985b49f03380",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "251c27bf-5ad9-4824-8255-2b67734c399e"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "b229800d-23a0-45e0-827f-3c364301e919",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "251c27bf-5ad9-4824-8255-2b67734c399e"
    }
  ]
}