Exemplo n.º 1
0
    void AddPerlinNode()
    {
        BaseNode pn = new PerlinNode();

        pn.name = "new Perlin Node";

        nodeList.Add(pn);
        Repaint();
    }
Exemplo n.º 2
0
    //public Texture2D m_Cached;

    public override Node Create(Vector2 pos)
    {
        PerlinNode node = CreateInstance <PerlinNode> ();

        node.rect = new Rect(pos.x, pos.y, 150, 340);
        node.name = "Perlin Noise";

        node.CreateOutput("Texture", "TextureParam", NodeSide.Right, 50);

        return(node);
    }
Exemplo n.º 3
0
    /*
     * private float RecurTreeHelper(PerlinNode[] influencers, VecN[] deviations, VecN w, int iteration)
     * {
     *  if (influencers.Length == 2)
     *  {
     *      //end condition: there are only two items
     *      //  at this time, iteration will equal d-1
     *      //dist dot grad
     *
     *      //l has no x-deviation
     *      VecN l = v.Subtract(influencers[0].coord);
     *      //r has x-deviation of 1, so the subtraction goes the other way
     *      VecN r = influencers[1].coord.Subtract(v);
     *
     *      //lerp the two using the last weight
     *
     *      return Lerp(
     *              l.Dot(influencers[0].gradient),
     *              r.Dot(influencers[1].gradient),
     *              Fade(w.coord[iteration])
     *          );
     *  }
     *
     *  //split the influencers into two halves
     *  PerlinNode[] left = new PerlinNode[influencers.Length / 2];
     *  PerlinNode[] right = new PerlinNode[influencers.Length / 2];
     *  for(int i = 0; i < influencers.Length/2; i++)
     *  {
     *      left[i] = influencers[i];
     *      right[i] = influencers[i + (influencers.Length / 2)];
     *  }
     *
     *  return Lerp(
     *          RecurTreeHelper(left, v, w, iteration + 1),
     *          RecurTreeHelper(right, v, w, iteration + 1),
     *          Fade(w.coord[iteration])
     *      );
     * }*/

    private PerlinNode[] FindAdjacency(PerlinNode p)
    {
        //add the deviations to the base coordinate of p, then fetch corresponding gridpoint
        PerlinNode[] result = new PerlinNode[grid_deviations.Length];
        for (int i = 0; i < grid_deviations.Length; i++)
        {
            //length marker of the deviated grid node = length (p's grid position + grid deviation)
            //the modulo deals with positive overflow, the only possibility is
            //being 1 over w-1 in either coordinates. in that case we want to
            //loop back to 0
            result[i] = nodes[Unwrap(p.coord.Add(grid_deviations[i]).Mod(w))];
        }

        return(result);
    }
Exemplo n.º 4
0
    /*
     * The noise map is noted by a grid of d-dimensional vectors going from:
     * (0, 0, ..., 0), (1, 0, ..., 0), ..., (w-1, 0, ..., 0)
     * (0, 1, ..., 0), (1, 1, ..., 0), ..., (w-1, 1, ..., 0)
     *                               ...(w-1, w-1, ..., w-1)
     * and each vector corresponds to a measurement of length for a space filling curve
     * which works similar to a w-based number:
     *      digit 0 * 1 + digit 1 * w + ... + digit d-1 * w ^ d-1
     */

    //beware that this method is not very efficient as it uses a rectangular grid instead of triangular

    //initialize with flavor specification
    public Perlin(int w, int d, int f)
    {
        this.w = w;
        this.d = d;
        this.f = f;

        //initiate the relative positions of adjacent grids to the basis grid
        //use a cursor going from 0 to 2^n-1 to iterate across all the
        //possible deviations associated with adjacent coordinates
        grid_deviations = new VecN[(int)Mathf.Pow(2, d)];
        for (int i = 0; i < grid_deviations.Length; i++)
        {
            float[] c = new float[d];
            for (int j = 0; j < d; j++)
            {
                c[j] = (i >> j) & 1; //gets the bit value of the j'th digit of i
            }

            grid_deviations[i] = new VecN(c);
        }

        //there are w * ... * w pivots in total, w^d
        nodes = new PerlinNode[(int)Mathf.Pow(w, d)];
        //iterate through the space filling curve by length
        //populate the noise map and configure the adjacency relationships
        for (int i = 0; i < nodes.Length; i++)
        {
            //populate the map and set the gradient vector (see constructor for pn)
            PerlinNode pn = new PerlinNode(Wrap(i));
            nodes[i] = pn;
        }

        for (int i = 0; i < nodes.Length; i++)
        {
            //setup adjacency relationships
            nodes[i].neighbors = FindAdjacency(nodes[i]);
        }

        //Debug.Log(nodes[0].PrintNeighbors());
    }