Exemplo n.º 1
0
    void CreateTexture()
    {
        System.Diagnostics.Stopwatch timer = System.Diagnostics.Stopwatch.StartNew();
        texture            = new Texture3D(data.size, data.size, data.size, format, false);
        texture.filterMode = filter;
        texture.wrapMode   = wrap;

        int totalPixels = data.size * data.size * data.size;

        //float[] pixels = new float[totalPixels];
        Color[]       pixels = new Color[totalPixels];
        ComputeBuffer cb     = new ComputeBuffer(totalPixels, sizeof(float) * 4);

        cs.SetBuffer(0, "Result", cb);
        cs.SetInt("Size", data.size);
        cs.SetInts("Octaves", data.octaves);
        cs.SetInts("Inverts", data.inverts);
        cs.SetFloats("Freqs", data.freqs);
        cs.Dispatch(0, data.size / 8, data.size / 8, data.size / 8);
        cb.GetData(pixels);
        cb.Release();

        //texture.SetPixelData<float>(pixels, 0);
        texture.SetPixels(pixels);
        texture.Apply();
        pixels = null;
        status = "Completed in: " + timer.Elapsed.ToString();
        timer.Stop();
        CloudPreviewer.ShowTexture(texture);
    }
Exemplo n.º 2
0
    void OnGUI()
    {
        EGL.LabelField("3D Texture properties", EditorStyles.boldLabel);

        int new_size = EGL.IntField("Resolution", data.size);

        new_size  = new_size <= 512 ? new_size : 512;
        new_size  = new_size >= 8 ? new_size : 8;
        data.size = new_size;

        EGL.LabelField("Worley noise");
        data.freqs[0]   = EGL.FloatField("Frequency", data.freqs[0]);
        data.octaves[0] = EGL.IntField("Octaves", data.octaves[0]);
        bool inv = EGL.Toggle("Invert", data.inverts[0] > 0);

        data.inverts[0] = inv ? 1 : 0;

        if (GUILayout.Button("Generate"))
        {
            CreateTexture();
        }

        EGL.HelpBox(status, MessageType.None, true);

        if (GUILayout.Button("Preview"))
        {
            CloudPreviewer.ShowTexture(texture);
        }

        EGL.BeginHorizontal();
        assetName = EGL.TextField("Asset name:", assetName);
        if (GUILayout.Button("Save"))
        {
            AssetDatabase.CreateAsset(texture, "Assets/" + assetName + ".asset");
        }
        EGL.EndHorizontal();
    }