public static Turbulence ( float posX, float posY, float posZ, int octaves ) : float | ||
posX | float | |
posY | float | |
posZ | float | |
octaves | int | |
return | float |
public void Generate3DTexture() { float r = 0.3f; texture3D = new Texture3D(n, n, n, TextureFormat.ARGB32, true); int size = n * n * n; Color[] cols = new Color[size]; int idx = 0; Color c = Color.white; float frequency = 0.01f / n; float center = n / 2.0f + 0.5f; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { for (int k = 0; k < n; k++, ++idx) { float dx = center - i; float dy = center - j; float dz = center - k; float off = Mathf.Abs(Perlin.Turbulence(i * frequency, j * frequency, k * frequency, 6)); float d = Mathf.Sqrt(dx * dx + dy * dy + dz * dz) / (n); //c.r = c.g = c.b = c.a = ((d-off) < r)?1.0f:0.0f; float p = d - off; c.r = c.g = c.b = c.a = Mathf.Clamp01(r - p); cols[idx] = c; } } } //for(int i = 0; i < size; i++) // Debug.Log (newC[i]); texture3D.SetPixels(cols); texture3D.Apply(); Renderer renderer = GetComponent <Renderer>().GetComponent <Renderer>(); renderer.material.SetTexture("g_densityTex", texture3D); texture3D.filterMode = FilterMode.Trilinear; texture3D.wrapMode = TextureWrapMode.Clamp; texture3D.anisoLevel = 1; //Color[] cs = texture3D.GetPixels(); //for(int i = 0; i < 10; i++) // Debug.Log (cs[i]); }
public static void Generate3DTexture(ref Texture3D texture3D, int n) { float r = 0.3f; int size = n * n * n; Color[] cols = new Color[size]; int idx = 0; Color c = Color.white; float frequency = 0.01f / n; float center = n / 2.0f + 0.5f; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { for (int k = 0; k < n; k++, ++idx) { float dx = center - i; float dy = center - j; float dz = center - k; float off = Mathf.Abs(Perlin.Turbulence(i * frequency, j * frequency, k * frequency, 6)); float d = Mathf.Sqrt(dx * dx + dy * dy + dz * dz) / (n); //c.r = c.g = c.b = c.a = ((d-off) < r)?1.0f:0.0f; float p = d - off; c.r = c.g = c.b = c.a = Mathf.Clamp01(r - p); cols[idx] = c; } } } //for(int i = 0; i < size; i++) // Debug.Log (newC[i]); texture3D.SetPixels(cols); texture3D.Apply(); texture3D.filterMode = FilterMode.Trilinear; texture3D.wrapMode = TextureWrapMode.Clamp; texture3D.anisoLevel = 1; }