{
  "Name": "WaveDistort",
  "_id": "38dbf26f-4c45-49bf-8d92-2cfff5e66e32",
  "Namespace": "lib.3d.modify",
  "Description": "Simple GPU-based deformer that distorts the incoming geometry along three sin-waves for the X Y Z axis.\r\n\r\nThe 3 parameter components represent the 3 axis. The usage of the z-axis (into depth) is also added to the y-axis. If this is not what you need, duplicate this shader as a new type and adjust the formular to your needs.\r\n",
  "Inputs": [
    {
      "Name": "Code",
      "MetaInstanceID": "1f506c21-13b0-47a5-9a9e-1ccbe4946fc7",
      "DefaultValue": {
        "Type": "Text",
        "Value": [
          "//>>> _parameters\r",
          "float3 Length;",
          "float3 Amplitude;",
          "float3 Phase;",
          "//<<< _parameters\r",
          "\r",
          "struct Vertex\r",
          "{\r",
          "    float4 pos : POSITION;\r",
          "    float3 normal : NORMAL;\r",
          "    float4 col : COLOR;\r",
          "    float2 texCoord : TEXCOORD0;\r",
          "    float3 tangent : TANGENT0;\r",
          "    float3 binormal : BINORMAL0;\r",
          "};\r",
          "\r",
          "Vertex VertexMain(Vertex input)\r",
          "{\r",
          "    return input;\r",
          "}\r",
          "\r",
          "float _noiseTime=0;\r",
          "float _frequency=0;\r",
          "\r",
          "\r",
          "\r",
          "[maxvertexcount(3)]\r",
          "void GeometryMain(triangle Vertex input[3], inout TriangleStream<Vertex> outputStream)\r",
          "{\r",
          "\r",
          "    \r",
          "    for (int i = 0; i < 3; i++)\r",
          "\t{\r",
          "        Vertex vertex = input[i];\r",
          "        float4 p = vertex.pos;\r",
          "        float3 p2 = sin(p*Length+Phase)*Amplitude;\r",
          "        \r",
          "        vertex.pos.xy += p2.yx;\r",
          "        vertex.pos.y+=p2.z;\r",
          "        \r",
          "        outputStream.Append(vertex);\r",
          "    }\r",
          "    \r",
          "    outputStream.RestartStrip();\r",
          "};\r",
          "\r",
          "\r",
          "GeometryShader pGSComp = CompileShader(gs_5_0, GeometryMain());\r",
          "GeometryShader pGSwSO = ConstructGSWithSO(pGSComp, \"POSITION; NORMAL.xyz; COLOR; TEXCOORD0.xy; TANGENT0.xyz; BINORMAL0.xyz\", NULL, NULL, NULL, 0);\r",
          "\r",
          "\r",
          "technique11 Render\r",
          "{\r",
          "    pass \r",
          "    {\r",
          "        SetVertexShader(CompileShader(vs_5_0, VertexMain()));\r",
          "        SetGeometryShader(pGSwSO);\r",
          "        SetPixelShader(NULL);\r",
          "    }\r",
          "}\r",
          "\r",
          ""
        ]
      },
      "MetaID": "c522a66e-3260-4692-b3e3-79fd0361fa3d",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Scene",
      "MetaInstanceID": "b91b86af-c8ce-4e64-8a00-0373b95d45f5",
      "DefaultValue": {
        "Type": "Scene",
        "Value": "Framefield.Core.Scene"
      },
      "MetaID": "79122951-7bc4-4c68-b085-866eab828248",
      "IsMultiInput": "False",
      "Relevance": "Required",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Length.X",
      "MetaInstanceID": "4002a39a-eeb3-40f8-a279-5cd3a22228e2",
      "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": "Length.Y",
      "MetaInstanceID": "42d2e83a-6482-4c96-8367-98433902771b",
      "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": "Length.Z",
      "MetaInstanceID": "6e0daa3d-72fb-48ca-bcf8-31de0be76256",
      "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": "Amplitude.X",
      "MetaInstanceID": "28bceae3-dc1d-475a-95b6-82f7b4f2301d",
      "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": "Amplitude.Y",
      "MetaInstanceID": "6594223d-6365-492b-9136-19c4260ee6d8",
      "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": "Amplitude.Z",
      "MetaInstanceID": "412aa1b5-4685-4fbf-af13-7eef6263ae6e",
      "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": "Phase.X",
      "MetaInstanceID": "ff0f3df5-e930-435c-bf3b-fd62eedea253",
      "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": "Phase.Y",
      "MetaInstanceID": "deff5266-2b80-44dd-9bd8-516f7f1ab815",
      "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": "Phase.Z",
      "MetaInstanceID": "3686b2c9-ee52-4cf7-ab66-069b112f0435",
      "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": "Scene",
      "MetaInstanceID": "fab0f655-5308-4beb-b645-b5a181329210",
      "MetaID": "79122951-7bc4-4c68-b085-866eab828248"
    }
  ],
  "OperatorParts": [
    {
      "MetaInstanceID": "2fcb61c5-b24f-4148-b950-02b1e5113828",
      "MetaID": "c2db95cb-0eb3-42f0-9fa5-de64d31a0a2a",
      "Name": "WaveDistortFunc",
      "Version": "7f4e2c56-e621-415e-8467-83dd87bdb22d",
      "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 Framefield.Core.OperatorPartTraits;",
        "using Framefield.Core.Rendering;",
        "using Buffer = SharpDX.Direct3D11.Buffer;",
        "using SharpDX.Direct3D;",
        "",
        "namespace Framefield.Core.IDc2db95cb_0eb3_42f0_9fa5_de64d31a0a2a",
        "{",
        "    public class Class_WaveDistort : FXSourceCodeFunction, IFXSceneSourceCode, IMeshSupplier",
        "    {",
        "        //>>> _inputids",
        "        private enum InputId",
        "        {",
        "            Code = 0,",
        "            Scene = 1,",
        "            LengthX = 2,",
        "            LengthY = 3,",
        "            LengthZ = 4,",
        "            AmplitudeX = 5,",
        "            AmplitudeY = 6,",
        "            AmplitudeZ = 7,",
        "            PhaseX = 8,",
        "            PhaseY = 9,",
        "            PhaseZ = 10",
        "        }",
        "        //<<< _inputids",
        "",
        "        public Class_WaveDistort()",
        "        {",
        "            _meshCollector = new MeshCollector(this);",
        "        }",
        "",
        "        public override void Dispose() ",
        "        {",
        "            Utilities.DisposeObj(ref _mesh);",
        "            base.Dispose();",
        "        }",
        "",
        "        public void AddMeshesTo(ICollection<Mesh> meshes)",
        "        {",
        "            UpdateMesh(new OperatorPartContext(), OperatorPart.Connections);",
        "            if (_mesh != null)",
        "                meshes.Add(_mesh);",
        "        }",
        "",
        "        public override OperatorPartContext Eval(OperatorPartContext context, List<OperatorPart> inputs, int outputIdx)",
        "        {",
        "            try",
        "            {",
        "                UpdateMesh(context, inputs);",
        "",
        "                if (_mesh.Vertices != null)",
        "                {",
        "                    // render stream output to screen or whatever target is set",
        "                    context.Renderer.SetupEffect(context);",
        "                    context.Renderer.Render(_mesh, context);",
        "                }",
        "            }",
        "            catch (Exception exception)",
        "            {",
        "                Logger.Error(this, \"Load Effect error: {0}\", exception.Message);",
        "            }",
        "",
        "            return context;",
        "        }",
        "",
        "        bool _firstEval = true;",
        "        private void UpdateMesh(OperatorPartContext context, List<OperatorPart> inputs)",
        "        {",
        "            if (_firstEval)",
        "            {",
        "                for (int i = 0; i < NumCodes(); ++i)",
        "                    Compile(i);",
        "                _firstEval = false;",
        "                Changed = true;",
        "            }",
        "",
        "            if (!Changed && _mesh.Vertices != null)",
        "                return;",
        "",
        "            //>>> _params",
        "            var Code = inputs[(int)InputId.Code].Eval(context).Text;",
        "            var Scene = inputs[(int)InputId.Scene];",
        "            var LengthX = inputs[(int)InputId.LengthX].Eval(context).Value;",
        "            var LengthY = inputs[(int)InputId.LengthY].Eval(context).Value;",
        "            var LengthZ = inputs[(int)InputId.LengthZ].Eval(context).Value;",
        "            var Length = new Vector3(LengthX, LengthY, LengthZ);",
        "            var AmplitudeX = inputs[(int)InputId.AmplitudeX].Eval(context).Value;",
        "            var AmplitudeY = inputs[(int)InputId.AmplitudeY].Eval(context).Value;",
        "            var AmplitudeZ = inputs[(int)InputId.AmplitudeZ].Eval(context).Value;",
        "            var Amplitude = new Vector3(AmplitudeX, AmplitudeY, AmplitudeZ);",
        "            var PhaseX = inputs[(int)InputId.PhaseX].Eval(context).Value;",
        "            var PhaseY = inputs[(int)InputId.PhaseY].Eval(context).Value;",
        "            var PhaseZ = inputs[(int)InputId.PhaseZ].Eval(context).Value;",
        "            var Phase = new Vector3(PhaseX, PhaseY, PhaseZ);",
        "            //<<< _params",
        "",
        "            if (Scene.Func.Changed || _mesh.Vertices == null)",
        "            {",
        "                //Logger.Info(this, \"collect meshes\");",
        "                _meshCollector.Collect(Scene);",
        "                Scene.Func.Changed = false;",
        "            }",
        "",
        "            var inputMesh = _meshCollector.FirstMeshOrDefault;",
        "            if (inputMesh == null)",
        "                return;",
        "",
        "            _mesh.AttributesSize = inputMesh.AttributesSize;",
        "            _mesh.NumTriangles = inputMesh.NumTriangles;",
        "            _mesh.InputElements = inputMesh.InputElements;",
        "            if (_mesh.Vertices == null || _mesh.Vertices.Description.SizeInBytes != inputMesh.Vertices.Description.SizeInBytes)",
        "            {",
        "                if (_mesh.Vertices != null)",
        "                    _mesh.Vertices.Dispose();",
        "",
        "                _mesh.Vertices = new Buffer(D3DDevice.Device, new BufferDescription()",
        "                                                                    {",
        "                                                                        BindFlags = BindFlags.StreamOutput | BindFlags.VertexBuffer,",
        "                                                                        CpuAccessFlags = CpuAccessFlags.None,",
        "                                                                        OptionFlags = ResourceOptionFlags.None,",
        "                                                                        SizeInBytes = _mesh.NumTriangles*inputMesh.AttributesSize*3,",
        "                                                                        Usage = ResourceUsage.Default",
        "                                                                    });",
        "            }",
        "",
        "            _effect.GetVariableByName(\"Length\").AsVector().Set(Length);",
        "            _effect.GetVariableByName(\"Amplitude\").AsVector().Set(Amplitude);",
        "            _effect.GetVariableByName(\"Phase\").AsVector().Set(Phase);",
        "",
        "            context.D3DDevice.ImmediateContext.StreamOutput.SetTargets(new [] { new StreamOutputBufferBinding(_mesh.Vertices, 0) });",
        "            context.D3DDevice.ImmediateContext.OutputMerger.DepthStencilState = new DepthStencilState(context.D3DDevice,",
        "                                                                                                        new DepthStencilStateDescription()",
        "                                                                                                            {",
        "                                                                                                                IsDepthEnabled = false,",
        "                                                                                                                IsStencilEnabled = false",
        "                                                                                                            });",
        "            context.D3DDevice.ImmediateContext.InputAssembler.InputLayout = context.InputLayout;",
        "            context.D3DDevice.ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;",
        "            context.D3DDevice.ImmediateContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(inputMesh.Vertices, inputMesh.AttributesSize, 0));",
        "            var technique = _effect.GetTechniqueByIndex(0);",
        "            technique.GetPassByIndex(0).Apply(context.D3DDevice.ImmediateContext);",
        "            context.D3DDevice.ImmediateContext.Draw(_mesh.NumTriangles*3, 0);",
        "            context.D3DDevice.ImmediateContext.StreamOutput.SetTargets(new [] { new StreamOutputBufferBinding(null, 0) });",
        "",
        "            Changed = false;",
        "        }",
        "",
        "        private Mesh _mesh = new Mesh();",
        "        private MeshCollector _meshCollector;",
        "    }",
        "}",
        "",
        "",
        ""
      ],
      "AdditionalAssemblies": []
    }
  ],
  "Operators": [],
  "Connections": [
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "2fcb61c5-b24f-4148-b950-02b1e5113828",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "fab0f655-5308-4beb-b645-b5a181329210"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "1f506c21-13b0-47a5-9a9e-1ccbe4946fc7",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2fcb61c5-b24f-4148-b950-02b1e5113828"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "b91b86af-c8ce-4e64-8a00-0373b95d45f5",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2fcb61c5-b24f-4148-b950-02b1e5113828"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "4002a39a-eeb3-40f8-a279-5cd3a22228e2",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2fcb61c5-b24f-4148-b950-02b1e5113828"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "42d2e83a-6482-4c96-8367-98433902771b",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2fcb61c5-b24f-4148-b950-02b1e5113828"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "6e0daa3d-72fb-48ca-bcf8-31de0be76256",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2fcb61c5-b24f-4148-b950-02b1e5113828"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "28bceae3-dc1d-475a-95b6-82f7b4f2301d",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2fcb61c5-b24f-4148-b950-02b1e5113828"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "6594223d-6365-492b-9136-19c4260ee6d8",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2fcb61c5-b24f-4148-b950-02b1e5113828"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "412aa1b5-4685-4fbf-af13-7eef6263ae6e",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2fcb61c5-b24f-4148-b950-02b1e5113828"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "ff0f3df5-e930-435c-bf3b-fd62eedea253",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2fcb61c5-b24f-4148-b950-02b1e5113828"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "deff5266-2b80-44dd-9bd8-516f7f1ab815",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2fcb61c5-b24f-4148-b950-02b1e5113828"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "3686b2c9-ee52-4cf7-ab66-069b112f0435",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2fcb61c5-b24f-4148-b950-02b1e5113828"
    }
  ]
}