public static Texture2D GeneratedSimplexTexture(Terrain terrain, HeightLayerProperties properties)
        {
            Texture2D _working;
            int       _resolution;

            //_sizeX = _terrain.terrainData.heightmapWidth;
            //_sizeY = _terrain.terrainData.heightmapHeight;
            _resolution       = terrain.terrainData.heightmapResolution;
            _working          = new Texture2D(_resolution, _resolution, TextureFormat.R16, true);
            _working.name     = "Heightmap Noise Texture";
            _working.wrapMode = TextureWrapMode.Clamp;
            FillTextureWithNoise(_resolution, _working, properties);

            return(_working);
        }
        private static void FillTextureWithNoise(int resolution, Texture2D inputTexture, HeightLayerProperties properties)
        {
            int     _resolution = resolution;
            float   _stepSize   = 1f / _resolution;
            Vector3 point00     = new Vector3(-0.5f, -0.5f) + properties.Offset.Value;
            Vector3 point10     = new Vector3(0.5f, -0.5f) + properties.Offset.Value;
            Vector3 point01     = new Vector3(-0.5f, 0.5f) + properties.Offset.Value;
            Vector3 point11     = new Vector3(0.5f, 0.5f) + properties.Offset.Value;

            Vector3 _texturePoint = new Vector2();
            float   _noiseSample;

            for (int y = 0; y < _resolution; y++)
            {
                Vector3 point0 = Vector3.Lerp(point00, point01, (y + 0.5f) * _stepSize);
                Vector3 point1 = Vector3.Lerp(point10, point11, (y + 0.5f) * _stepSize);
                for (int x = 0; x < _resolution; x++)
                {
                    Vector3 point = Vector3.Lerp(point0, point1, (x + 0.5f) * _stepSize);
                    _noiseSample = SimplexNoise.SampleSum(point,
                                                          properties.Frequency.Value,
                                                          properties.Amplitude.Value,
                                                          properties.Octaves.Value,
                                                          properties.Lacunarity.Value,
                                                          properties.Persistance.Value);

                    _noiseSample = _noiseSample * 0.5f + 0.5f;
                    Color _noiseColor = Color.white * _noiseSample;
                    inputTexture.SetPixel(x, y, _noiseColor);
                }
            }
            inputTexture.Apply();
        }
示例#3
0
 public HeightLayer(int _position)
 {
     Name            = string.Format("Height Layer {0}", _position);
     Position        = _position;
     LayerProperties = new HeightLayerProperties();
 }