예제 #1
0
        public static NativeArray <ModuleData> CreateModuleData(BurstModuleBase module)
        {
            List <ModuleData> modules = new List <ModuleData>();

            CreateModuleDataHelper(modules, module);
            return(Array2NativeArray(modules.ToArray()));
        }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of Noise2D.
 /// </summary>
 /// <param name="width">The width of the noise map.</param>
 /// <param name="height">The height of the noise map.</param>
 /// <param name="generator">The generator module.</param>
 public Noise2D(int width, int height, BurstModuleBase generator = null)
     : base(width, height, new Perlin())
 {
     this.generator  = generator;
     heightmapWidth  = width + _ucBorder * 2;
     heightmapHeight = height + _ucBorder * 2;
     this.heightmap  = new NativeArray <float>(heightmapWidth * heightmapHeight, Allocator.Persistent);
 }
    void RenderAndSetImage(BurstModuleBase generator)
    {
        var heightMapBuilder = new Noise2D(Width, Height, generator);

        heightMapBuilder.GeneratePlanar(Noise2D.Left, Noise2D.Right, Noise2D.Top, Noise2D.Bottom);
        // heightMapBuilder.GenerateSpherical(90, -90, -180, 180);
        // heightMapBuilder.GenerateCylindrical(-180, 180, -1, 1);
        var image = heightMapBuilder.GetTexture();

        GetComponent <Renderer>().material.mainTexture = image;

        heightMapBuilder.Dispose();
    }
예제 #4
0
        private static int CreateModuleDataHelper(List <ModuleData> modules, BurstModuleBase module)
        {
            if (module == null)
            {
                return(-1);
            }
            modules.Add(new ModuleData(0, new int[] {}));
            int index = modules.Count - 1;

            int[] sources = new int[((ModuleBase)module).SourceModuleCount];
            for (int i = 0; i < sources.Length; i++)
            {
                sources[i] = CreateModuleDataHelper(modules, module.Source(i)); // add one for the current module
            }
            modules[index] = module.GetData(sources);
            return(index);
        }
예제 #5
0
        private static void GenerateHeightmap(NativeArray <float> heightmap, BurstModuleBase module, GenerateMode generateMode, int width, int height, double p1, double p2, double p3, double p4, bool p5 = false)
        {
            NativeArray <ModuleData> moduleData = CreateModuleData(module);

            var job = new GenerateLibNoiseJob
            {
                moduleData   = moduleData,
                heightmap    = heightmap,
                width        = width,
                height       = height,
                generateMode = generateMode,
                p1           = p1,
                p2           = p2,
                p3           = p3,
                p4           = p4,
                p5           = p5
            };
            JobHandle jobHandle = job.Schedule(heightmap.Length, 256);

            jobHandle.Complete();

            // // create texture
            // Texture2D texture = new Texture2D(Width, Height);
            // float[] heightmapValues = heightmap.ToArray();
            // Color[] colors = new Color[heightmapValues.Length];
            // for (int i = 0; i < heightmapValues.Length; i++) {
            //     float value = heightmapValues[i];
            //     value = (value + 1) / 2;
            //     colors[i] = new Color(value, value, value, 1);
            // }
            // texture.SetPixels(colors);
            // texture.wrapMode = TextureWrapMode.Clamp;
            // texture.Apply();

            // GetComponent<Renderer>().material.mainTexture = texture;

            moduleData.Dispose();
        }
예제 #6
0
 /// <summary>
 /// Initializes a new instance of ScaleBias.
 /// </summary>
 /// <param name="input">The input module.</param>
 public ScaleBias(BurstModuleBase input)
     : base((ModuleBase)input)
 {
 }
예제 #7
0
 /// <summary>
 /// Initializes a new instance of Clamp.
 /// </summary>
 /// <param name="input">The input module.</param>
 /// <param name="min">The minimum value.</param>
 /// <param name="max">The maximum value.</param>
 public Clamp(double min, double max, BurstModuleBase input)
     : base(min, max, (ModuleBase)input)
 {
 }
예제 #8
0
 /// <summary>
 /// Initializes a new instance of Noise2D.
 /// </summary>
 /// <param name="size">The width and height of the noise map.</param>
 /// <param name="generator">The generator module.</param>
 public Noise2D(int size, BurstModuleBase generator)
     : this(size, size, generator)
 {
 }
예제 #9
0
 /// <summary>
 /// Initializes a new instance of Invert.
 /// </summary>
 /// <param name="input">The input module.</param>
 public Invert(BurstModuleBase input)
     : base((ModuleBase)input)
 {
 }
예제 #10
0
 /// <summary>
 /// Initializes a new instance of Exponent.
 /// </summary>
 /// <param name="input">The input module.</param>
 public Exponent(BurstModuleBase input)
     : base((ModuleBase)input)
 {
 }
예제 #11
0
 /// <summary>
 /// Initializes a new instance of Translate.
 /// </summary>
 /// <param name="input">The input module.</param>
 public Translate(BurstModuleBase input)
     : base((ModuleBase)input)
 {
 }
예제 #12
0
 /// <summary>
 /// Initializes a new instance of Displace.
 /// </summary>
 /// <param name="input">The input module.</param>
 /// <param name="x">The displacement module of the x-axis.</param>
 /// <param name="y">The displacement module of the y-axis.</param>
 /// <param name="z">The displacement module of the z-axis.</param>
 public Displace(BurstModuleBase input, BurstModuleBase x, BurstModuleBase y, BurstModuleBase z)
     : base((ModuleBase)input, (ModuleBase)x, (ModuleBase)y, (ModuleBase)z)
 {
 }
예제 #13
0
 public static void GenerateSphericalHeightmap(NativeArray <float> heightmap, BurstModuleBase module, int width, int height, double south, double north, double west, double east)
 {
     GenerateHeightmap(heightmap, module, GenerateMode.Spherical, width, height, south, north, west, east);
 }
예제 #14
0
 public static void GenerateCylindricalHeightmap(NativeArray <float> heightmap, BurstModuleBase module, int width, int height, double angleMin, double angleMax, double heightMin, double heightMax)
 {
     GenerateHeightmap(heightmap, module, GenerateMode.Cylindrical, width, height, angleMin, angleMax, heightMin, heightMax);
 }
예제 #15
0
 public static void GeneratePlanarHeightmap(NativeArray <float> heightmap, BurstModuleBase module, int width, int height, double left, double right, double top, double bottom, bool isSeamless)
 {
     GenerateHeightmap(heightmap, module, GenerateMode.Planar, width, height, left, right, top, bottom, isSeamless);
 }
예제 #16
0
 /// <summary>
 /// Initializes a new instance of ScaleBias.
 /// </summary>
 /// <param name="scale">The scaling factor to apply to the output value from the source module.</param>
 /// <param name="bias">The bias to apply to the scaled output value from the source module.</param>
 /// <param name="input">The input module.</param>
 public ScaleBias(double scale, double bias, BurstModuleBase input)
     : base(scale, bias, (ModuleBase)input)
 {
 }
예제 #17
0
 /// <summary>
 /// Initializes a new instance of Scale.
 /// </summary>
 /// <param name="x">The scaling on the x-axis.</param>
 /// <param name="y">The scaling on the y-axis.</param>
 /// <param name="z">The scaling on the z-axis.</param>
 /// <param name="input">The input module.</param>
 public Scale(double x, double y, double z, BurstModuleBase input)
     : base(x, y, z, (ModuleBase)input)
 {
 }
예제 #18
0
 /// <summary>
 /// Initializes a new instance of Subtract.
 /// </summary>
 /// <param name="lhs">The left hand input module.</param>
 /// <param name="rhs">The right hand input module.</param>
 public Subtract(BurstModuleBase lhs, BurstModuleBase rhs)
     : base((ModuleBase)lhs, (ModuleBase)rhs)
 {
 }
예제 #19
0
 /// <summary>
 /// Initializes a new instance of Translate.
 /// </summary>
 /// <param name="x">The translation on the x-axis.</param>
 /// <param name="y">The translation on the y-axis.</param>
 /// <param name="z">The translation on the z-axis.</param>
 /// <param name="input">The input module.</param>
 public Translate(double x, double y, double z, BurstModuleBase input)
     : base(x, y, z, (ModuleBase)input)
 {
 }
예제 #20
0
 /// <summary>
 /// Initializes a new instance of Blend.
 /// </summary>
 /// <param name="lhs">The left hand input module.</param>
 /// <param name="rhs">The right hand input module.</param>
 /// <param name="controller">The controller of the operator.</param>
 public Blend(BurstModuleBase lhs, BurstModuleBase rhs, BurstModuleBase controller)
     : base((ModuleBase)lhs, (ModuleBase)rhs, (ModuleBase)controller)
 {
 }
예제 #21
0
 /// <summary>
 /// Initializes a new instance of Exponent.
 /// </summary>
 /// <param name="exponent">The exponent to use.</param>
 /// <param name="input">The input module.</param>
 public Exponent(double exponent, BurstModuleBase input)
     : base(exponent, (ModuleBase)input)
 {
 }
예제 #22
0
 /// <summary>
 /// Initializes a new instance of Select.
 /// </summary>
 /// <param name="min">The minimum value.</param>
 /// <param name="max">The maximum value.</param>
 /// <param name="fallOff">The falloff value at the edge transition.</param>
 /// <param name="inputA">The first input module.</param>
 /// <param name="inputB">The second input module.</param>
 public Select(double min, double max, double fallOff, BurstModuleBase inputA, BurstModuleBase inputB)
     : base(min, max, fallOff, (ModuleBase)inputA, (ModuleBase)inputB)
 {
 }
예제 #23
0
 /// <summary>
 /// Initializes a new instance of Max.
 /// </summary>
 /// <param name="lhs">The left hand input module.</param>
 /// <param name="rhs">The right hand input module.</param>
 public Max(BurstModuleBase lhs, BurstModuleBase rhs)
     : base((ModuleBase)lhs, (ModuleBase)rhs)
 {
 }
예제 #24
0
 /// <summary>
 /// Initializes a new instance of Select.
 /// </summary>
 /// <param name="inputA">The first input module.</param>
 /// <param name="inputB">The second input module.</param>
 /// <param name="controller">The controller module.</param>
 public Select(BurstModuleBase inputA, BurstModuleBase inputB, BurstModuleBase controller)
     : base((ModuleBase)inputA, (ModuleBase)inputB, (ModuleBase)controller)
 {
 }
예제 #25
0
 /// <summary>
 /// Initializes a new instance of Multiply.
 /// </summary>
 /// <param name="lhs">The left hand input module.</param>
 /// <param name="rhs">The right hand input module.</param>
 public Multiply(BurstModuleBase lhs, BurstModuleBase rhs)
     : base((ModuleBase)lhs, (ModuleBase)rhs)
 {
 }
예제 #26
0
 /// <summary>
 /// Initializes a new instance of Abs.
 /// </summary>
 /// <param name="input">The input module.</param>
 public Abs(BurstModuleBase input)
     : base((ModuleBase)input)
 {
 }
예제 #27
0
 /// <summary>
 /// Initializes a new instance of Power.
 /// </summary>
 /// <param name="lhs">The left hand input module.</param>
 /// <param name="rhs">The right hand input module.</param>
 public Power(BurstModuleBase lhs, BurstModuleBase rhs)
     : base((ModuleBase)lhs, (ModuleBase)rhs)
 {
 }
예제 #28
0
 /// <summary>
 /// Initializes a new instance of Clamp.
 /// </summary>
 /// <param name="input">The input module.</param>
 public Clamp(BurstModuleBase input)
     : base((ModuleBase)input)
 {
 }