{
  "Name": "PerlinNoise1d",
  "_id": "e8eb452d-97c3-42e5-8ce2-1b0d205e3a51",
  "Namespace": "lib.math",
  "Description": "Returns the square root of a number. If the number is smaller than 0, it returns 0.",
  "Inputs": [
    {
      "Name": "Value",
      "MetaInstanceID": "42550e05-2e6d-45f3-b026-2700db9a6dbd",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Required",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "0.01",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Seed",
      "MetaInstanceID": "78c92fcf-772b-4d97-a192-be419a67355e",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Period",
      "MetaInstanceID": "928cb5ff-d962-43d0-8b3c-1f5689d9761f",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0.5"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Octaves",
      "MetaInstanceID": "ca0c3f03-fbf7-42f2-8d8e-b7ae24fea3ba",
      "DefaultValue": {
        "Type": "Float",
        "Value": "2"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "1",
      "Max": "32",
      "Scale": "1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Zoom",
      "MetaInstanceID": "93ee8d4b-7df1-4d59-b061-d811876e6c55",
      "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": "Range.Min",
      "MetaInstanceID": "c2907365-3801-4f66-b4ad-596c2dafbac7",
      "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": "Range.Max",
      "MetaInstanceID": "62cffe16-5848-44fe-94e9-9708ade4ef7b",
      "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": []
    }
  ],
  "Outputs": [
    {
      "Name": "Output",
      "MetaInstanceID": "3cfa52eb-fd6c-4b66-b84b-2cf0ed2e36a5",
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506"
    }
  ],
  "OperatorParts": [
    {
      "MetaInstanceID": "99303ece-27f6-4769-a2f9-a81c338ac5c1",
      "MetaID": "2a100d77-f3e2-4a3f-8496-dd6bba025a03",
      "Name": "PerlinNoise1dFunc",
      "Version": "935b8aa5-0cad-4ff9-9d5e-35822062465a",
      "Type": "Float",
      "IsMultiInput": "True",
      "Script": [
        "using System;",
        "using System.Collections.Generic;",
        "using System.Linq;",
        "using System.Text;",
        "using SharpDX;",
        "",
        "namespace Framefield.Core.ID2a100d77_f3e2_4a3f_8496_dd6bba025a03",
        "{",
        "    public class Class_PerlinNoise1d : OperatorPart.Function",
        "    {",
        "        //>>> _inputids",
        "        private enum InputId",
        "        {",
        "            Value = 0,",
        "            Seed = 1,",
        "            Period = 2,",
        "            Octaves = 3,",
        "            Zoom = 4,",
        "            RangeMin = 5,",
        "            RangeMax = 6",
        "        }",
        "        //<<< _inputids",
        "",
        "        public float Noise(int x, int seed) {",
        "            int n = x + seed*137;",
        "            n = (n<<13) ^ n;",
        "            return (float)( 1.0 - ( (n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0); ",
        "        }",
        "        ",
        "        public float Lerp(float a, float b, float t) {",
        "            return a + t * (b - a);",
        "        }",
        "        ",
        "        public float Fade(float t) {",
        "            return t * t * t * (t * (t * 6 - 15) + 10);",
        "        }",
        "        ",
        "        //public float Interpolate(float a, float b, float t) {",
        "        //    float ft=t * 3.1415927f;",
        "        //    float f= (float)(1.0 - Math.Cos(ft))* 0.5f;",
        "        //    return (float)( a*(1.0f-f)+b*f);",
        "        //}",
        "",
        "        public override OperatorPartContext Eval(OperatorPartContext context, List<OperatorPart> inputs, int outputIdx) {",
        "        ",
        "            // >>> _params",
        "            var Value = inputs[(int)InputId.Value].Eval(context).Value;",
        "            var Seed = inputs[(int)InputId.Seed].Eval(context).Value;",
        "            var Period = inputs[(int)InputId.Period].Eval(context).Value;",
        "            var Octaves = inputs[(int)InputId.Octaves].Eval(context).Value;",
        "            var Zoom = inputs[(int)InputId.Zoom].Eval(context).Value;",
        "            var RangeMin = inputs[(int)InputId.RangeMin].Eval(context).Value;",
        "            var RangeMax = inputs[(int)InputId.RangeMax].Eval(context).Value;",
        "            var Range = new Vector2(RangeMin, RangeMax);",
        "            // <<< _params",
        "            ",
        "            ",
        "                int octaves = (int) Octaves;",
        "                float noiseSum =0.0f;",
        "                //float zoom= 2.0f;",
        "                ",
        "                ",
        "                for(int a=0; a<octaves-1; a++) {",
        "                    float frequency = (float)Math.Pow(2,a); ",
        "                    float amplitude = (float)Math.Pow(Period ,a);",
        "",
        "                    float v =  Value * frequency/Zoom  + Seed*12.468f ;",
        "                                                   ",
        "                    noiseSum += Lerp( Noise( (int)v  , (int)Seed ),",
        "                                      Noise( (int)v+1, (int)Seed ),",
        "                                      Fade( v - (float)Math.Floor(v) )",
        "                                )* amplitude;",
        "",
        "                    //noiseSum += Interpolate( Noise( (int)v  , (int)Seed ) - 1,",
        "                    //                         Noise( (int)v+1, (int)Seed ) - 1,",
        "                    //                        v - (float)Math.Floor(v)",
        "                    //            )* amplitude;",
        "",
        "                }",
        "                ",
        "               context.Value = (noiseSum+1f)*0.5f * (RangeMax-RangeMin) + RangeMin;",
        "",
        "            return context;",
        "        }",
        "    }",
        "}",
        ""
      ],
      "AdditionalAssemblies": []
    }
  ],
  "Operators": [],
  "Connections": [
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "42550e05-2e6d-45f3-b026-2700db9a6dbd",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "99303ece-27f6-4769-a2f9-a81c338ac5c1"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "78c92fcf-772b-4d97-a192-be419a67355e",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "99303ece-27f6-4769-a2f9-a81c338ac5c1"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "928cb5ff-d962-43d0-8b3c-1f5689d9761f",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "99303ece-27f6-4769-a2f9-a81c338ac5c1"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "ca0c3f03-fbf7-42f2-8d8e-b7ae24fea3ba",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "99303ece-27f6-4769-a2f9-a81c338ac5c1"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "93ee8d4b-7df1-4d59-b061-d811876e6c55",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "99303ece-27f6-4769-a2f9-a81c338ac5c1"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "c2907365-3801-4f66-b4ad-596c2dafbac7",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "99303ece-27f6-4769-a2f9-a81c338ac5c1"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "62cffe16-5848-44fe-94e9-9708ade4ef7b",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "99303ece-27f6-4769-a2f9-a81c338ac5c1"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "99303ece-27f6-4769-a2f9-a81c338ac5c1",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "3cfa52eb-fd6c-4b66-b84b-2cf0ed2e36a5"
    }
  ]
}