private static void FillTextureWithNoise(Texture2D inputTexture, HeightLayerProps properties)
        {
            int   _resolution = inputTexture.width;
            float _stepSize   = 1f / _resolution;

            Vector3 point00 = new Vector3(-0.5f, -0.5f) + properties.Offset.Vector3;
            Vector3 point10 = new Vector3(0.5f, -0.5f) + properties.Offset.Vector3;
            Vector3 point01 = new Vector3(-0.5f, 0.5f) + properties.Offset.Vector3;
            Vector3 point11 = new Vector3(0.5f, 0.5f) + properties.Offset.Vector3;

            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.Float,
                                                          properties.Amplitude.Float,
                                                          properties.Octaves.Int,
                                                          properties.Lacunarity.Float,
                                                          properties.Persistance.Float);

                    _noiseSample = _noiseSample * 0.5f + 0.5f;
                    Color _noiseColor = Color.white * _noiseSample;
                    inputTexture.SetPixel(x, y, _noiseColor);
                }
            }
            inputTexture.Apply();
        }
        public static Texture2D GeneratedSimplexTexture(Terrain terrain, HeightLayerProps properties)
        {
            Texture2D _working;
            int       _resolution;

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

            return(_working);
        }
Exemplo n.º 3
0
 public HeightLayer(int _position)
 {
     Name            = string.Format("Height Layer {0}", _position);
     Position        = _position;
     LayerProperties = new HeightLayerProps();
 }