{
  "Name": "AddPixelNoise",
  "_id": "7d2f35a9-01a4-458b-b23d-ffd0c73b2657",
  "Namespace": "lib.image.generate",
  "Description": "Loads an image.",
  "Inputs": [
    {
      "Name": "Code",
      "MetaInstanceID": "10e037d6-e7c3-4af5-98b0-0ab3ab3b5d6b",
      "DefaultValue": {
        "Type": "Text",
        "Value": [
          "//>>> _common parameters\r",
          "float4x4 objectToWorldMatrix;",
          "float4x4 worldToCameraMatrix;",
          "float4x4 projMatrix;",
          "Texture2D txDiffuse;",
          "float2 RenderTargetSize;",
          "//<<< _common parameters\r",
          "\r",
          "//>>> _parameters\r",
          "float Seed;",
          "float4 Color;",
          "Texture2D Image;",
          "//<<< _parameters\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 )",
          "{",
          "    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",
          "float random( float2 p )\r",
          "{\r",
          "  // We need irrationals for pseudo randomness.\r",
          "  // Most (all?) known transcendental numbers will (generally) work.\r",
          "  const float2 r = float2(\r",
          "    23.1406926327792690,  // e^pi (Gelfond's constant)\r",
          "     2.6651441426902251); // 2^sqrt(2) (Gelfond–Schneider constant)\r",
          "  return frac( cos( fmod( 123456789., 1e-7 + 256. * dot(p,r) ) ) );  \r",
          "}\r",
          "\r",
          "\r",
          "float4 PS(PS_IN input) : SV_Target\r",
          "{\r",
          "    float aspectRatio = RenderTargetSize.x/RenderTargetSize.y;\r",
          "    float4 i= Image.Sample(samLinear, input.texCoord); \r",
          "    float c= random( \r",
          "        float2( input.pos.x * 0.0012 *( fmod(Seed,263)+101), \r",
          "                input.pos.y +  (Seed+101) * 0.013));\r",
          "    return lerp(i, Color,  c* Color.a);\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": "Seed",
      "MetaInstanceID": "d6770214-4a3c-4e5a-b7fc-e13055dc7acf",
      "DefaultValue": {
        "Type": "Float",
        "Value": "1"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Color.R",
      "MetaInstanceID": "4ea39ce7-2d55-4f13-9db9-8a7d2b96cbfa",
      "DefaultValue": {
        "Type": "Float",
        "Value": "1"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "0",
      "Max": "1",
      "Scale": "0.01",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Color.G",
      "MetaInstanceID": "e6db3982-de71-432d-8a81-9fe067b48e13",
      "DefaultValue": {
        "Type": "Float",
        "Value": "1"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "0",
      "Max": "1",
      "Scale": "0.01",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Color.B",
      "MetaInstanceID": "9ee189a6-c45e-4975-bfea-208da89bb74f",
      "DefaultValue": {
        "Type": "Float",
        "Value": "1"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "0",
      "Max": "1",
      "Scale": "0.01",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Color.A",
      "MetaInstanceID": "e5c84012-395e-4247-8cc2-ca5f8aba966f",
      "DefaultValue": {
        "Type": "Float",
        "Value": "1"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "0",
      "Max": "1",
      "Scale": "0.01",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Image",
      "MetaInstanceID": "1d9de9f7-27fe-4b79-9595-7267c9dc7edc",
      "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": []
    }
  ],
  "Outputs": [
    {
      "Name": "Image",
      "MetaInstanceID": "5d9003e2-bcfc-4bfa-bcb5-334abaacd2f9",
      "MetaID": "9848060d-fd84-45b0-b658-d0d531c61dab"
    }
  ],
  "OperatorParts": [
    {
      "MetaInstanceID": "6a4036a8-fb94-4353-b1f2-5fe4e0719325",
      "MetaID": "ed5ee8bb-615f-4f98-ba8e-3961b5116859",
      "Name": "AddPixelNoiseFunc",
      "Version": "efb203d8-e0a8-4db6-b5b5-7178f9d88116",
      "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.IDed5ee8bb_615f_4f98_ba8e_3961b5116859",
        "{",
        "    public class Class_AddPixelNoise : FXImageFunction",
        "    {",
        "        //>>> _inputids",
        "        private enum InputId",
        "        {",
        "            Code = 0,",
        "            Seed = 1,",
        "            ColorR = 2,",
        "            ColorG = 3,",
        "            ColorB = 4,",
        "            ColorA = 5,",
        "            Image = 6",
        "        }",
        "        //<<< _inputids",
        "",
        "        public override OperatorPartContext Eval(OperatorPartContext context, List<OperatorPart> inputs, int outputIdx)",
        "        {",
        "            return PrepareAndEvalOnChange(context, () =>",
        "            {",
        "                //>>> __params",
        "                var Code = inputs[(int)InputId.Code].Eval(context).Text;",
        "                var Seed = inputs[(int)InputId.Seed].Eval(context).Value;",
        "                var ColorR = inputs[(int)InputId.ColorR].Eval(context).Value;",
        "                var ColorG = inputs[(int)InputId.ColorG].Eval(context).Value;",
        "                var ColorB = inputs[(int)InputId.ColorB].Eval(context).Value;",
        "                var ColorA = inputs[(int)InputId.ColorA].Eval(context).Value;",
        "                var Color = new Color4(ColorR, ColorG, ColorB, ColorA);",
        "                var Image = inputs[(int)InputId.Image].Eval(context).Image; if (Image == null) return;",
        "                //<<< __params",
        "",
        "                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(\"Seed\").AsScalar().Set(Seed);",
        "                    _effect.GetVariableByName(\"Color\").AsVector().Set(new Vector4(ColorR, ColorG, ColorB, ColorA));",
        "                    _effect.GetVariableByName(\"Image\").AsShaderResource().SetResource(ImageView);",
        "                //<<< _setup",
        "",
        "                Render(context);",
        "",
        "                //>>> _cleanup",
        "                }",
        "                //<<< _cleanup",
        "            });",
        "        }",
        "",
        "    }",
        "}",
        "",
        ""
      ],
      "AdditionalAssemblies": []
    }
  ],
  "Operators": [],
  "Connections": [
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "6a4036a8-fb94-4353-b1f2-5fe4e0719325",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "5d9003e2-bcfc-4bfa-bcb5-334abaacd2f9"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "10e037d6-e7c3-4af5-98b0-0ab3ab3b5d6b",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "6a4036a8-fb94-4353-b1f2-5fe4e0719325"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "d6770214-4a3c-4e5a-b7fc-e13055dc7acf",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "6a4036a8-fb94-4353-b1f2-5fe4e0719325"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "4ea39ce7-2d55-4f13-9db9-8a7d2b96cbfa",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "6a4036a8-fb94-4353-b1f2-5fe4e0719325"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "e6db3982-de71-432d-8a81-9fe067b48e13",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "6a4036a8-fb94-4353-b1f2-5fe4e0719325"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "9ee189a6-c45e-4975-bfea-208da89bb74f",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "6a4036a8-fb94-4353-b1f2-5fe4e0719325"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "e5c84012-395e-4247-8cc2-ca5f8aba966f",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "6a4036a8-fb94-4353-b1f2-5fe4e0719325"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "1d9de9f7-27fe-4b79-9595-7267c9dc7edc",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "6a4036a8-fb94-4353-b1f2-5fe4e0719325"
    }
  ]
}