{
  "Name": "ChromaticAberration",
  "_id": "040013a9-2bf4-4e98-b21b-ecae73af024b",
  "Namespace": "lib.image.adjust",
  "Description": "Some early experiements how to add a color halo fringe to an image.",
  "Inputs": [
    {
      "Name": "Code",
      "MetaInstanceID": "b9b0973d-78b5-4c26-b812-886ddbaff7d8",
      "DefaultValue": {
        "Type": "Text",
        "Value": [
          "//>>> _common parameters\r",
          "float4x4 objectToWorldMatrix;",
          "float4x4 worldToCameraMatrix;",
          "float4x4 projMatrix;",
          "Texture2D txDiffuse;",
          "float2 RenderTargetSize;",
          "//<<< _common parameters\r",
          "\r",
          "//>>> _parameters\r",
          "Texture2D Image1;",
          "float Radius;",
          "float2 Size;",
          "float SampleCount;",
          "//<<< _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",
          "float4 PS( PS_IN input ) : SV_Target\r",
          "{\r",
          "    float2 p=input.texCoord;\r",
          "    \r",
          "    float2 dc = float2(p.x-0.5, p.y-0.5) * Radius;\r",
          "    \r",
          "    float4 c0 = Image1.Sample(samLinear, p-dc); \r",
          "    float4 c1 = Image1.Sample(samLinear, p); \r",
          "    float4 c2 = Image1.Sample(samLinear, p+dc); \r",
          "    \r",
          "    return float4( c0.r, c1.g, c2.b, clamp(c1.a,0,1));    \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": "Image1",
      "MetaInstanceID": "9bbb6bad-4b5d-4217-9cc3-ab8b3782b221",
      "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": "527cfd1d-6896-4e73-9ee5-e6e0d8bc613e",
      "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": "27f816a0-722d-49da-95e7-b7f627b32f95",
      "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": "721d02fa-f72a-4ab6-a189-3ec02e8a2b25",
      "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": "9aac4295-636f-4092-9ddb-01ef2190b894",
      "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": []
    }
  ],
  "Outputs": [
    {
      "Name": "Image",
      "MetaInstanceID": "b6c65f88-6908-40b3-84c5-16ca76309120",
      "MetaID": "9848060d-fd84-45b0-b658-d0d531c61dab"
    }
  ],
  "OperatorParts": [
    {
      "MetaInstanceID": "f20ecc63-bc94-4638-8908-1fe07cc462d5",
      "MetaID": "44ebd8a7-1ccd-403a-af14-d5be95a6dc1f",
      "Name": "ChromaticAberrationFunc",
      "Version": "c3e4d9ac-0359-4e6b-a9ff-03b2ef437c21",
      "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.ID44ebd8a7_1ccd_403a_af14_d5be95a6dc1f",
        "{",
        "    public class Class_ChromaticAberration : FXImageFunction",
        "    {",
        "        //>>> _inputids",
        "        private enum InputId",
        "        {",
        "            Code = 0,",
        "            Image1 = 1,",
        "            Radius = 2,",
        "            SizeX = 3,",
        "            SizeY = 4,",
        "            SampleCount = 5",
        "        }",
        "        //<<< _inputids",
        "        public override OperatorPartContext Eval(OperatorPartContext context, List<OperatorPart> inputs, int outputIdx) {",
        "",
        "            //>>> _params",
        "            var Code = inputs[(int)InputId.Code].Eval(context).Text;",
        "            var Image1 = inputs[(int)InputId.Image1].Eval(context).Image; // Needs to be checked for null!",
        "            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;",
        "            //<<< _params",
        "",
        "            return PrepareAndEvalOnChange(context, () => {",
        "                ClearRenderTarget(context, new SharpDX.Color4(0, 0, 0, 0));",
        "",
        "                //>>> _setup",
        "                using (var Image1View = new ShaderResourceView(context.D3DDevice, Image1))",
        "                {",
        "                    _effect.GetVariableByName(\"RenderTargetSize\").AsVector().Set(new Vector2(_usedViewport.Width, _usedViewport.Height));",
        "                    _effect.GetVariableByName(\"Image1\").AsShaderResource().SetResource(Image1View);",
        "                    _effect.GetVariableByName(\"Radius\").AsScalar().Set(Radius);",
        "                    _effect.GetVariableByName(\"Size\").AsVector().Set(new Vector2(SizeX, SizeY));",
        "                    _effect.GetVariableByName(\"SampleCount\").AsScalar().Set(SampleCount);",
        "                //<<< _setup",
        "",
        "                Render(context);",
        "",
        "                //>>> _cleanup",
        "                }",
        "                //<<< _cleanup",
        "            });",
        "        }",
        "",
        "    }",
        "}",
        "",
        ""
      ],
      "AdditionalAssemblies": []
    }
  ],
  "Operators": [],
  "Connections": [
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "f20ecc63-bc94-4638-8908-1fe07cc462d5",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "b6c65f88-6908-40b3-84c5-16ca76309120"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "b9b0973d-78b5-4c26-b812-886ddbaff7d8",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "f20ecc63-bc94-4638-8908-1fe07cc462d5"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "9bbb6bad-4b5d-4217-9cc3-ab8b3782b221",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "f20ecc63-bc94-4638-8908-1fe07cc462d5"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "527cfd1d-6896-4e73-9ee5-e6e0d8bc613e",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "f20ecc63-bc94-4638-8908-1fe07cc462d5"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "27f816a0-722d-49da-95e7-b7f627b32f95",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "f20ecc63-bc94-4638-8908-1fe07cc462d5"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "721d02fa-f72a-4ab6-a189-3ec02e8a2b25",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "f20ecc63-bc94-4638-8908-1fe07cc462d5"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "9aac4295-636f-4092-9ddb-01ef2190b894",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "f20ecc63-bc94-4638-8908-1fe07cc462d5"
    }
  ]
}