Beispiel #1
0
 void ReleaseVolumetricData()
 {
     if (volumetricData != null)
     {
         marchingCubesGPU.VolumetricData = null;
         Texture3D.DestroyImmediate(volumetricData);
     }
 }
Beispiel #2
0
    void Apply()
    {
        if (size < 2)
        {
            Debug.LogError("size should at least be 2");
            return;
        }

        if (field == null || field.width != size)
        {
            if (field != null)
            {
                Texture3D.DestroyImmediate(field);
            }
            field = new Texture3D(size, size, size, TextureFormat.ARGB32, false);
        }

        // TODO should compute accMul beforehand?
        var   tensor = new Vector3[size * size * size];
        float accMul = 0;

        if (layers != null)
        {
            foreach (var l in layers)
            {
                if (l.mul > 0)
                {
                    accMul += l.mul;
                    NoiseLayer(tensor, size, l.scale, l.offset, l.mul);
                }
            }
        }

        var texels = new Color[tensor.Length];

        if (accMul > 0)
        {
            for (int i = 0; i != tensor.Length; ++i)
            {
                var tmp = ((tensor[i] / accMul) + Vector3.one) / 2.0f;
                texels[i] = new Color(tmp.x, tmp.y, tmp.z);
            }
        }
        else
        {
            for (int i = 0; i != tensor.Length; ++i)
            {
                // We encode normalized values so 0 is gray
                texels[i] = Color.white / 2.0f;
            }
        }

        field.SetPixels(texels);
        field.Apply();
        GetComponent <ParticleSystemGPGPU> ().velocityField = field;
    }