void Generate() { this._noiseTexture = new Texture2D(256, 256, TextureFormat.RGBA32, false); var scale = 1.0f / 256; var noisePerlin = new NoiseTools.PerlinNoise(_frequency, _repeat); var noiseWorley = new NoiseTools.WorleyNoise(_frequency, _repeat); for (int i = 0; i < 256; ++i) { var x = i * scale; for (int j = 0; j < 256; ++j) { var y = j * scale; for (int k = 0; k < 1; ++k) { var z = k * scale; var c = noisePerlin.GetFractal(x, y, z, _fractal); c = _usePerlin?noisePerlin.GetAt(x, y):noiseWorley.GetAt(x, y, z); //c = 1 - c; //c = Mathf.Abs(c * 2 - 1); this._noiseTexture.SetPixel(i, j, new Color(c, c, c, 1)); } } } this._noiseTexture.Apply(); }
void FillTextureData(Texture3D texture) { Assert.IsNotNull(texture); Assert.IsTrue(texture.width == texture.height); //Assert.IsTrue(texture.width == texture.depth); Assert.IsTrue(texture.width == kSizeOfVolume); var perlinNoise = new NoiseTools.PerlinNoise(4, 1, 0); var worleyNoise = new NoiseTools.WorleyNoise(7, 1, 0); var worleyNoiseF1 = new NoiseTools.WorleyNoise(10, 1, 0); var worleyNoiseF2 = new NoiseTools.WorleyNoise(15, 1, 0); var worleyNoiseF3 = new NoiseTools.WorleyNoise(20, 1, 0); this._data = new Particle[kNumberOfBuffer]; var data = new Color[kNumberOfBuffer]; var index = 0; var scale = 1.0f / kSizeOfVolume; var min = float.MaxValue; var max = float.MinValue; for (uint i = 0; i < kSizeOfVolume; ++i) { var x = i * scale; for (uint j = 0; j < kSizeOfVolume; ++j) { var y = j * scale; for (uint k = 0; k < kdepth; ++k) { var z = k * scale; var perlin = perlinNoise.GetFractal(x, y, z, 4); var worley = worleyNoise.GetFractal(x, y, z, 2); var worleyf1 = worleyNoiseF1.GetFractal(x, y, z, 2); var worleyf2 = worleyNoiseF2.GetFractal(x, y, z, 2); var worleyf3 = worleyNoiseF3.GetFractal(x, y, z, 2); var perlin_worley = this.Remap(perlin, -InvertWorley(worley), 1, 0, 1); data[index] = new Color(perlin_worley, InvertWorley(worleyf1), InvertWorley(worleyf2), InvertWorley(worleyf3)); this._data[index].position = new Vector3(i, j, k); this._data[index].color = new Vector4(perlin_worley, worleyf1, worleyf2, worleyf3); index++; //Debug.LogFormat("{0}", c); //max = c > max ? c : max; //min = c < min ? c : min; } } } Debug.LogFormat("{0}, {1}", min, max); this._noiseTexture.SetPixels(data); this._noiseTexture.Apply(); }