Exemple #1
0
    public void ApplyPerlinNoise()
    {
        List <Vector3> points = new List <Vector3>();

        foreach (TGeoNode node in xNodes)
        {
            if (!node.transformed)
            {
                points.Add(node.position);
            }
        }
        FBMBatchTask fbmbatch = new FBMBatchTask(xFBM, 6);

        fbmbatch.Start(points.ToArray());

        while (!fbmbatch.Done())
        {
            ;                               // wait for FBM batch
        }
        points = null;
        float[] fbmout = fbmbatch.Output();

        int counter = 0;

        foreach (TGeoNode node in xNodes)
        {
            if (!node.transformed)
            {
                //float n = xFBM.Value(0.2f*node.position.normalized); //xPerlinNoise.Noise( node.position.normalized * 10f );
                float n = fbmout[counter];
                node.position    = node.position.normalized * (1f + 0.8f * n);
                node.radius      = node.position.magnitude;
                node.transformed = true;
                counter++;
            }
        }
    }
    public static void GenerateTexutre(object thisTex)
    {
        int w = (thisTex as ProceduralTextureDisplay).Width;
        int h = (thisTex as ProceduralTextureDisplay).Height;

        float[] field;
        float   fmin = 1000f;
        float   fmax = -1000f;

        FBMBatchTask calcFieldTask = new FBMBatchTask((thisTex as ProceduralTextureDisplay).fbm, 6);

        Vector3[] points = new Vector3[w * h];
        for (int x = 0; x < w; x++)
        {
            for (int y = 0; y < h; y++)
            {
                points[y * h + x] = new Vector3(0.5f * (float)x / (float)w, 0.3f * (float)y / (float)h, 0f);
            }
        }

        calcFieldTask.Start(points);

        // wait
        while (!calcFieldTask.Done())
        {
        }
        ;

        field = calcFieldTask.Output();

        for (int x = 0; x < w; x++)
        {
            for (int y = 0; y < h; y++)
            {
                //float f = (thisTex as ProceduralTextureDisplay).fbm.Value(new Vector3( (float)x/(float)w, (float)y/(float)h, 0f ));

                float f = field[y * h + x];
                if (f < fmin)
                {
                    fmin = f;
                }
                if (f > fmax)
                {
                    fmax = f;
                }
            }
        }

        (thisTex as ProceduralTextureDisplay).TexPixels = new Color[w * h];

        for (int x = 0; x < w; x++)
        {
            for (int y = 0; y < h; y++)
            {
                float f = (field[y * h + x] - fmin) / (fmax - fmin);
                (thisTex as ProceduralTextureDisplay).TexPixels[y * h + x] = new Color(f, f * 0.8f, f * 0.5f);
            }
        }
        (thisTex as ProceduralTextureDisplay).ThreadFinished = true;

        Debug.Log(fmin);
        Debug.Log(fmax);
    }