{
  "Name": "Mosaic",
  "_id": "a285ff18-6925-4fda-9237-8bad07e6826c",
  "Namespace": "lib.image.effects",
  "Description": "Rasterizes the incoming image",
  "Inputs": [
    {
      "Name": "Code",
      "MetaInstanceID": "3d477698-663f-4431-96fb-c8f77c470e70",
      "DefaultValue": {
        "Type": "Text",
        "Value": [
          "//>>> _common parameters\r",
          "float4x4 objectToWorldMatrix;",
          "float4x4 worldToCameraMatrix;",
          "float4x4 projMatrix;",
          "Texture2D txDiffuse;",
          "float2 RenderTargetSize;",
          "//<<< _common parameters\r",
          "\r",
          "//>>> _parameters\r",
          "Texture2D Displacement;",
          "Texture2D Image;",
          "float2 Size;",
          "float2 Shift;",
          "//<<< _parameters\r",
          " \r",
          "//>>> setup\r",
          "SamplerState samLinear\r",
          "{\r",
          "    //Filter = MIN_MAG_MIP_LINEAR;\r",
          "    Filter = MIN_MAG_MIP_POINT;\r",
          "    AddressU = Wrap;\r",
          "    AddressV = Wrap;\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=round(input.texCoord * Size)/Size;\r",
          "    float2 p = input.texCoord + 1/(RenderTargetSize)*0.5;\r",
          "    \r",
          "    \r",
          "    //float2 tile = float2( p.x % (1.0/Size.x) * Size.x  , 1);\r",
          "    float2 tileFrag = (p+Shift) % (1.0/Size) * Size;\r",
          "    if(tileFrag.x < 0) tileFrag.x += 1.0/Size.x;\r",
          "    if(tileFrag.y < 0) tileFrag.y += 1.0/Size.y;\r",
          "    \r",
          "    float2 tile= p - tileFrag/Size + 0.5/(RenderTargetSize);\r",
          "\r",
          "    float4 c= Displacement.Sample(samLinear, tile); \r",
          "    float gray = (c.r+c.g+c.b)/3;\r",
          "\r",
          "    return c;\r",
          "    //return float4( tile.x, tile.y,0,1);\r",
          "    \r",
          "    \r",
          "    //float tile=0.1;\r",
          "    //if( gray < 0.4) {\r",
          "    //    tile=1;\r",
          "    //}\r",
          "    //else if (gray < 0.6) {\r",
          "    //    tile = ((p*Size).x + (p*Size).y % 4)  ;\r",
          "    //}\r",
          "\r",
          "    //return Image.Sample( samLinear, p+tile/8);\r",
          "    \r",
          "\r",
          "    //float a = t0.a + t1.a - t0.a * t1.a;\r",
          "    //float3 rgb=  t0.rgb * t1.a * t1.rgb;   \r",
          "    \r",
          "    //return col1+col2;\r",
          "    \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": "Displacement",
      "MetaInstanceID": "c1d959a9-604a-422a-a658-8d2e0265640f",
      "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": "Image",
      "MetaInstanceID": "0edb2a0e-4145-45aa-b03e-bbd27e26e611",
      "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": "Size.X",
      "MetaInstanceID": "4d68d461-b841-48be-b831-ff0f96d7a679",
      "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": "465a7781-e704-4afe-af0f-8296aefbce80",
      "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": "Shift.X",
      "MetaInstanceID": "1b1727cf-c60a-4ec9-b126-837a975250b1",
      "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": "Shift.Y",
      "MetaInstanceID": "65931cf5-694d-4adf-8392-2ca80bdf99eb",
      "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": []
    }
  ],
  "Outputs": [
    {
      "Name": "Image",
      "MetaInstanceID": "1cc74c19-f782-46af-bee3-f095b697179d",
      "MetaID": "9848060d-fd84-45b0-b658-d0d531c61dab"
    }
  ],
  "OperatorParts": [
    {
      "MetaInstanceID": "6bb8fcbf-8466-43de-8f69-2d71d13e7702",
      "MetaID": "7bcb0a21-6930-4622-87a9-86a45c3c588a",
      "Name": "MosaicFunc",
      "Version": "45f37cdb-17f0-4206-b03a-03ae8a1a937f",
      "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.ID7bcb0a21_6930_4622_87a9_86a45c3c588a",
        "{",
        "    public class Class_Mosaic : FXImageFunction",
        "    {",
        "        //>>> _inputids",
        "        private enum InputId",
        "        {",
        "            Code = 0,",
        "            Displacement = 1,",
        "            Image = 2,",
        "            SizeX = 3,",
        "            SizeY = 4,",
        "            ShiftX = 5,",
        "            ShiftY = 6",
        "        }",
        "        //<<< _inputids",
        "        public override OperatorPartContext Eval(OperatorPartContext context, List<OperatorPart> inputs, int outputIdx) {",
        "",
        "            //>>> _params",
        "            var Code = inputs[(int)InputId.Code].Eval(context).Text;",
        "            var Displacement = inputs[(int)InputId.Displacement].Eval(context).Image; if (Displacement == null) return context;",
        "            var Image = inputs[(int)InputId.Image].Eval(context).Image; if (Image == null) return context;",
        "            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 ShiftX = inputs[(int)InputId.ShiftX].Eval(context).Value;",
        "            var ShiftY = inputs[(int)InputId.ShiftY].Eval(context).Value;",
        "            var Shift = new Vector2(ShiftX, ShiftY);",
        "            //<<< _params",
        "",
        "            return PrepareAndEvalOnChange(context, () => {",
        "                ClearRenderTarget(context, new SharpDX.Color4(0, 0, 0, 0));",
        "",
        "                //>>> _setup",
        "                using (var DisplacementView = new ShaderResourceView(context.D3DDevice, Displacement))",
        "                using (var ImageView = new ShaderResourceView(context.D3DDevice, Image))",
        "                {",
        "                    _effect.GetVariableByName(\"RenderTargetSize\").AsVector().Set(new Vector2(_usedViewport.Width, _usedViewport.Height));",
        "                    _effect.GetVariableByName(\"Displacement\").AsShaderResource().SetResource(DisplacementView);",
        "                    _effect.GetVariableByName(\"Image\").AsShaderResource().SetResource(ImageView);",
        "                    _effect.GetVariableByName(\"Size\").AsVector().Set(new Vector2(SizeX, SizeY));",
        "                    _effect.GetVariableByName(\"Shift\").AsVector().Set(new Vector2(ShiftX, ShiftY));",
        "                //<<< _setup",
        "",
        "                Render(context);",
        "",
        "                //>>> _cleanup",
        "                }",
        "                //<<< _cleanup",
        "            });",
        "        }",
        "",
        "    }",
        "}",
        "",
        ""
      ],
      "AdditionalAssemblies": []
    }
  ],
  "Operators": [],
  "Connections": [
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "6bb8fcbf-8466-43de-8f69-2d71d13e7702",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "1cc74c19-f782-46af-bee3-f095b697179d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "3d477698-663f-4431-96fb-c8f77c470e70",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "6bb8fcbf-8466-43de-8f69-2d71d13e7702"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "c1d959a9-604a-422a-a658-8d2e0265640f",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "6bb8fcbf-8466-43de-8f69-2d71d13e7702"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "0edb2a0e-4145-45aa-b03e-bbd27e26e611",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "6bb8fcbf-8466-43de-8f69-2d71d13e7702"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "4d68d461-b841-48be-b831-ff0f96d7a679",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "6bb8fcbf-8466-43de-8f69-2d71d13e7702"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "465a7781-e704-4afe-af0f-8296aefbce80",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "6bb8fcbf-8466-43de-8f69-2d71d13e7702"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "1b1727cf-c60a-4ec9-b126-837a975250b1",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "6bb8fcbf-8466-43de-8f69-2d71d13e7702"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "65931cf5-694d-4adf-8392-2ca80bdf99eb",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "6bb8fcbf-8466-43de-8f69-2d71d13e7702"
    }
  ]
}