Browse Source

Procedural Generation 12/21

Nathan Gusatto 1 month ago
parent
commit
e91496e7f0

File diff suppressed because it is too large
+ 3 - 138
Assets/Scenes/SampleScene.unity


+ 34 - 23
Assets/Scripts/EndlessTerrain.cs

@@ -1,13 +1,14 @@
 using UnityEngine;
+using System.Collections;
 using System.Collections.Generic;
-using Unity.VisualScripting;
 
 public class EndlessTerrain : MonoBehaviour
 {
+
     const float scale = 5f;
 
-    const float viewerMoveThreshHoldForChunkUpdate = 25f;
-    const float sqrViewerMoveThreshHoldForChunkUpdate = viewerMoveThreshHoldForChunkUpdate * viewerMoveThreshHoldForChunkUpdate;
+    const float viewerMoveThresholdForChunkUpdate = 25f;
+    const float sqrViewerMoveThresholdForChunkUpdate = viewerMoveThresholdForChunkUpdate * viewerMoveThresholdForChunkUpdate;
 
     public LODInfo[] detailLevels;
     public static float maxViewDst;
@@ -21,25 +22,25 @@ public class EndlessTerrain : MonoBehaviour
     int chunkSize;
     int chunksVisibleInViewDst;
 
-    Dictionary<Vector2, TerrainChunk> terrainChunkDictionnary = new Dictionary<Vector2, TerrainChunk>();
+    Dictionary<Vector2, TerrainChunk> terrainChunkDictionary = new Dictionary<Vector2, TerrainChunk>();
     static List<TerrainChunk> terrainChunksVisibleLastUpdate = new List<TerrainChunk>();
 
-    private void Start()
+    void Start()
     {
         mapGenerator = FindFirstObjectByType<MapGenerator>();
 
-        maxViewDst = detailLevels[detailLevels.Length-1].visibleDstThreshold;
+        maxViewDst = detailLevels[detailLevels.Length - 1].visibleDstThreshold;
         chunkSize = MapGenerator.mapChunkSize - 1;
         chunksVisibleInViewDst = Mathf.RoundToInt(maxViewDst / chunkSize);
 
         UpdateVisibleChunks();
     }
 
-    private void Update()
+    void Update()
     {
         viewerPosition = new Vector2(viewer.position.x, viewer.position.z) / scale;
 
-        if ((viewerPositionOld - viewerPosition).sqrMagnitude > sqrViewerMoveThreshHoldForChunkUpdate)
+        if ((viewerPositionOld - viewerPosition).sqrMagnitude > sqrViewerMoveThresholdForChunkUpdate)
         {
             viewerPositionOld = viewerPosition;
             UpdateVisibleChunks();
@@ -48,35 +49,38 @@ public class EndlessTerrain : MonoBehaviour
 
     void UpdateVisibleChunks()
     {
+
         for (int i = 0; i < terrainChunksVisibleLastUpdate.Count; i++)
         {
             terrainChunksVisibleLastUpdate[i].SetVisible(false);
         }
         terrainChunksVisibleLastUpdate.Clear();
 
-        int currentChunkCoordX = Mathf.RoundToInt(viewerPosition.x /  chunkSize);
-        int currentChunkCoordY = Mathf.RoundToInt(viewerPosition.y /  chunkSize);
+        int currentChunkCoordX = Mathf.RoundToInt(viewerPosition.x / chunkSize);
+        int currentChunkCoordY = Mathf.RoundToInt(viewerPosition.y / chunkSize);
 
-        for (int yOffset = -chunksVisibleInViewDst; yOffset <=chunksVisibleInViewDst; yOffset++)
+        for (int yOffset = -chunksVisibleInViewDst; yOffset <= chunksVisibleInViewDst; yOffset++)
         {
             for (int xOffset = -chunksVisibleInViewDst; xOffset <= chunksVisibleInViewDst; xOffset++)
             {
-                Vector2 viewedChunkCoord = new(currentChunkCoordX + xOffset, currentChunkCoordY + yOffset);
+                Vector2 viewedChunkCoord = new Vector2(currentChunkCoordX + xOffset, currentChunkCoordY + yOffset);
 
-                if (terrainChunkDictionnary.ContainsKey(viewedChunkCoord))
+                if (terrainChunkDictionary.ContainsKey(viewedChunkCoord))
                 {
-                    terrainChunkDictionnary[viewedChunkCoord].UpdateTerrainChunk();
+                    terrainChunkDictionary[viewedChunkCoord].UpdateTerrainChunk();
                 }
                 else
                 {
-                    terrainChunkDictionnary.Add(viewedChunkCoord, new TerrainChunk(viewedChunkCoord, chunkSize, detailLevels, transform, mapMaterial));
+                    terrainChunkDictionary.Add(viewedChunkCoord, new TerrainChunk(viewedChunkCoord, chunkSize, detailLevels, transform, mapMaterial));
                 }
+
             }
         }
     }
 
     public class TerrainChunk
     {
+
         GameObject meshObject;
         Vector2 position;
         Bounds bounds;
@@ -87,7 +91,7 @@ public class EndlessTerrain : MonoBehaviour
         LODInfo[] detailLevels;
         LODMesh[] lodMeshes;
 
-        MapData mapData; 
+        MapData mapData;
         bool mapDataReceived;
         int previousLODIndex = -1;
 
@@ -97,9 +101,9 @@ public class EndlessTerrain : MonoBehaviour
 
             position = coord * size;
             bounds = new Bounds(position, Vector2.one * size);
-            Vector3 positionV3 = new(position.x, 0, position.y);
+            Vector3 positionV3 = new Vector3(position.x, 0, position.y);
 
-            meshObject = new GameObject("TerrainChunk");
+            meshObject = new GameObject("Terrain Chunk");
             meshRenderer = meshObject.AddComponent<MeshRenderer>();
             meshFilter = meshObject.AddComponent<MeshFilter>();
             meshRenderer.material = material;
@@ -110,7 +114,7 @@ public class EndlessTerrain : MonoBehaviour
             SetVisible(false);
 
             lodMeshes = new LODMesh[detailLevels.Length];
-            for (int i = 0; i < detailLevels.Length; i++) 
+            for (int i = 0; i < detailLevels.Length; i++)
             {
                 lodMeshes[i] = new LODMesh(detailLevels[i].lod, UpdateTerrainChunk);
             }
@@ -129,12 +133,14 @@ public class EndlessTerrain : MonoBehaviour
             UpdateTerrainChunk();
         }
 
+
+
         public void UpdateTerrainChunk()
         {
             if (mapDataReceived)
             {
-                float viewDstFromNearestEdge = Mathf.Sqrt(bounds.SqrDistance(viewerPosition));
-                bool visible = viewDstFromNearestEdge <= maxViewDst;
+                float viewerDstFromNearestEdge = Mathf.Sqrt(bounds.SqrDistance(viewerPosition));
+                bool visible = viewerDstFromNearestEdge <= maxViewDst;
 
                 if (visible)
                 {
@@ -142,7 +148,7 @@ public class EndlessTerrain : MonoBehaviour
 
                     for (int i = 0; i < detailLevels.Length - 1; i++)
                     {
-                        if (viewDstFromNearestEdge > detailLevels[i].visibleDstThreshold)
+                        if (viewerDstFromNearestEdge > detailLevels[i].visibleDstThreshold)
                         {
                             lodIndex = i + 1;
                         }
@@ -151,6 +157,7 @@ public class EndlessTerrain : MonoBehaviour
                             break;
                         }
                     }
+
                     if (lodIndex != previousLODIndex)
                     {
                         LODMesh lodMesh = lodMeshes[lodIndex];
@@ -181,10 +188,12 @@ public class EndlessTerrain : MonoBehaviour
         {
             return meshObject.activeSelf;
         }
+
     }
 
     class LODMesh
     {
+
         public Mesh mesh;
         public bool hasRequestedMesh;
         public bool hasMesh;
@@ -210,6 +219,7 @@ public class EndlessTerrain : MonoBehaviour
             hasRequestedMesh = true;
             mapGenerator.RequestMeshData(mapData, lod, OnMeshDataReceived);
         }
+
     }
 
     [System.Serializable]
@@ -218,4 +228,5 @@ public class EndlessTerrain : MonoBehaviour
         public int lod;
         public float visibleDstThreshold;
     }
-}
+
+}

+ 32 - 31
Assets/Scripts/MapGenerator.cs

@@ -1,4 +1,5 @@
 using UnityEngine;
+using System.Collections;
 using System;
 using System.Threading;
 using System.Collections.Generic;
@@ -6,27 +7,25 @@ using System.Collections.Generic;
 public class MapGenerator : MonoBehaviour
 {
 
-    public enum DrawMode { NoiseMap, ColourMap, Mesh, FallOff};
+    public enum DrawMode { NoiseMap, ColourMap, Mesh, FalloffMap };
     public DrawMode drawMode;
 
     public Noise.NormalizeMode normalizeMode;
 
-    public const int mapChunkSize = 241;
-
-    [Range(0,6)]
+    public const int mapChunkSize = 239;
+    [Range(0, 6)]
     public int editorPreviewLOD;
     public float noiseScale;
 
     public int octaves;
-
-    [Range(0,1)]
+    [Range(0, 1)]
     public float persistance;
     public float lacunarity;
 
     public int seed;
     public Vector2 offset;
 
-    public bool useFallOff;
+    public bool useFalloff;
 
     public float meshHeightMultiplier;
     public AnimationCurve meshHeightCurve;
@@ -35,14 +34,14 @@ public class MapGenerator : MonoBehaviour
 
     public TerrainType[] regions;
 
-    float[,] fallOffMap;
+    float[,] falloffMap;
 
     Queue<MapThreadInfo<MapData>> mapDataThreadInfoQueue = new Queue<MapThreadInfo<MapData>>();
     Queue<MapThreadInfo<MeshData>> meshDataThreadInfoQueue = new Queue<MapThreadInfo<MeshData>>();
 
-    private void Awake()
+    void Awake()
     {
-        fallOffMap = FallOffGenerator.GenerateFallOffMap(mapChunkSize);
+        falloffMap = FallOffGenerator.GenerateFallOffMap(mapChunkSize);
     }
 
     public void DrawMapInEditor()
@@ -50,7 +49,6 @@ public class MapGenerator : MonoBehaviour
         MapData mapData = GenerateMapData(Vector2.zero);
 
         MapDisplay display = FindFirstObjectByType<MapDisplay>();
-
         if (drawMode == DrawMode.NoiseMap)
         {
             display.DrawTexture(TextureGenerator.TextureFromHeightMap(mapData.heightMap));
@@ -62,7 +60,8 @@ public class MapGenerator : MonoBehaviour
         else if (drawMode == DrawMode.Mesh)
         {
             display.DrawMesh(MeshGenerator.GenerateTerrainMesh(mapData.heightMap, meshHeightMultiplier, meshHeightCurve, editorPreviewLOD), TextureGenerator.TextureFromColourMap(mapData.colourMap, mapChunkSize, mapChunkSize));
-        }else if (drawMode ==DrawMode.FallOff)
+        }
+        else if (drawMode == DrawMode.FalloffMap)
         {
             display.DrawTexture(TextureGenerator.TextureFromHeightMap(FallOffGenerator.GenerateFallOffMap(mapChunkSize)));
         }
@@ -70,8 +69,7 @@ public class MapGenerator : MonoBehaviour
 
     public void RequestMapData(Vector2 centre, Action<MapData> callback)
     {
-        ThreadStart threadStart = delegate
-        {
+        ThreadStart threadStart = delegate {
             MapDataThread(centre, callback);
         };
 
@@ -89,8 +87,7 @@ public class MapGenerator : MonoBehaviour
 
     public void RequestMeshData(MapData mapData, int lod, Action<MeshData> callback)
     {
-        ThreadStart threadStart = delegate
-        {
+        ThreadStart threadStart = delegate {
             MeshDataThread(mapData, lod, callback);
         };
 
@@ -106,7 +103,7 @@ public class MapGenerator : MonoBehaviour
         }
     }
 
-    private void Update()
+    void Update()
     {
         if (mapDataThreadInfoQueue.Count > 0)
         {
@@ -116,9 +113,10 @@ public class MapGenerator : MonoBehaviour
                 threadInfo.callback(threadInfo.parameter);
             }
         }
+
         if (meshDataThreadInfoQueue.Count > 0)
         {
-            for(int i = 0; i < meshDataThreadInfoQueue.Count; i++)
+            for (int i = 0; i < meshDataThreadInfoQueue.Count; i++)
             {
                 MapThreadInfo<MeshData> threadInfo = meshDataThreadInfoQueue.Dequeue();
                 threadInfo.callback(threadInfo.parameter);
@@ -128,24 +126,23 @@ public class MapGenerator : MonoBehaviour
 
     MapData GenerateMapData(Vector2 centre)
     {
-        float[,] noiseMap = Noise.GenerateNoiseMap(mapChunkSize, mapChunkSize, seed, noiseScale, octaves, persistance, lacunarity, centre + offset, normalizeMode);
+        float[,] noiseMap = Noise.GenerateNoiseMap(mapChunkSize + 2, mapChunkSize + 2, seed, noiseScale, octaves, persistance, lacunarity, centre + offset, normalizeMode);
 
         Color[] colourMap = new Color[mapChunkSize * mapChunkSize];
-
-        for(int y=0; y<mapChunkSize; y++)
+        for (int y = 0; y < mapChunkSize; y++)
         {
-            for (int x=0; x<mapChunkSize; x++)
+            for (int x = 0; x < mapChunkSize; x++)
             {
-                if (useFallOff)
+                if (useFalloff)
                 {
-                    noiseMap[x, y] = Mathf.Clamp(noiseMap[x, y] - fallOffMap[x, y], 0, 1);
+                    noiseMap[x, y] = Mathf.Clamp01(noiseMap[x, y] - falloffMap[x, y]);
                 }
                 float currentHeight = noiseMap[x, y];
                 for (int i = 0; i < regions.Length; i++)
                 {
-                    if(currentHeight >= regions[i].height)
+                    if (currentHeight >= regions[i].height)
                     {
-                        colourMap[y*mapChunkSize + x] = regions[i].colour;
+                        colourMap[y * mapChunkSize + x] = regions[i].colour;
                     }
                     else
                     {
@@ -154,21 +151,23 @@ public class MapGenerator : MonoBehaviour
                 }
             }
         }
+
+
         return new MapData(noiseMap, colourMap);
     }
 
-    private void OnValidate()
+    void OnValidate()
     {
         if (lacunarity < 1)
         {
             lacunarity = 1;
         }
-
-        if(octaves < 0)
+        if (octaves < 0)
         {
             octaves = 0;
         }
-        fallOffMap = FallOffGenerator.GenerateFallOffMap(mapChunkSize);
+
+        falloffMap = FallOffGenerator.GenerateFallOffMap(mapChunkSize);
     }
 
     struct MapThreadInfo<T>
@@ -181,7 +180,9 @@ public class MapGenerator : MonoBehaviour
             this.callback = callback;
             this.parameter = parameter;
         }
+
     }
+
 }
 
 [System.Serializable]
@@ -202,4 +203,4 @@ public struct MapData
         this.heightMap = heightMap;
         this.colourMap = colourMap;
     }
-}
+}

+ 159 - 32
Assets/Scripts/MeshGenerator.cs

@@ -1,34 +1,69 @@
-using JetBrains.Annotations;
 using UnityEngine;
+using System.Collections;
 
 public static class MeshGenerator
 {
+
     public static MeshData GenerateTerrainMesh(float[,] heightMap, float heightMultiplier, AnimationCurve _heightCurve, int levelOfDetail)
     {
         AnimationCurve heightCurve = new AnimationCurve(_heightCurve.keys);
-        
-        int width = heightMap.GetLength(0);
-        int height = heightMap.GetLength(1);
-        float topLeftX = (width - 1) / -2f;
-        float topLeftZ = (height - 1) / 2f;
 
-        int meshSimplficationIncrement = (levelOfDetail == 0) ? 1 : levelOfDetail * 2;
-        int verticesPerLine = (width - 1) / meshSimplficationIncrement + 1;
+        int meshSimplificationIncrement = (levelOfDetail == 0) ? 1 : levelOfDetail * 2;
+
+        int borderedSize = heightMap.GetLength(0);
+        int meshSize = borderedSize - 2 * meshSimplificationIncrement;
+        int meshSizeUnsimplified = borderedSize - 2;
+
+        float topLeftX = (meshSizeUnsimplified - 1) / -2f;
+        float topLeftZ = (meshSizeUnsimplified - 1) / 2f;
+
 
-        MeshData meshData = new(verticesPerLine, verticesPerLine);
-        int vertexIndex = 0;
+        int verticesPerLine = (meshSize - 1) / meshSimplificationIncrement + 1;
+
+        MeshData meshData = new MeshData(verticesPerLine);
+
+        int[,] vertexIndicesMap = new int[borderedSize, borderedSize];
+        int meshVertexIndex = 0;
+        int borderVertexIndex = -1;
+
+        for (int y = 0; y < borderedSize; y += meshSimplificationIncrement)
+        {
+            for (int x = 0; x < borderedSize; x += meshSimplificationIncrement)
+            {
+                bool isBorderVertex = y == 0 || y == borderedSize - 1 || x == 0 || x == borderedSize - 1;
+
+                if (isBorderVertex)
+                {
+                    vertexIndicesMap[x, y] = borderVertexIndex;
+                    borderVertexIndex--;
+                }
+                else
+                {
+                    vertexIndicesMap[x, y] = meshVertexIndex;
+                    meshVertexIndex++;
+                }
+            }
+        }
 
-        for(int y=0; y<height; y += meshSimplficationIncrement)
+        for (int y = 0; y < borderedSize; y += meshSimplificationIncrement)
         {
-            for(int x=0; x<width; x += meshSimplficationIncrement)
+            for (int x = 0; x < borderedSize; x += meshSimplificationIncrement)
             {
-                meshData.vertices[vertexIndex] = new Vector3(topLeftX + x, heightCurve.Evaluate(heightMap[x, y]) * heightMultiplier, topLeftZ - y);
-                meshData.uvs[vertexIndex] = new Vector2(x/(float)width, y/(float)height);
+                int vertexIndex = vertexIndicesMap[x, y];
+                Vector2 percent = new Vector2((x - meshSimplificationIncrement) / (float)meshSize, (y - meshSimplificationIncrement) / (float)meshSize);
+                float height = heightCurve.Evaluate(heightMap[x, y]) * heightMultiplier;
+                Vector3 vertexPosition = new Vector3(topLeftX + percent.x * meshSizeUnsimplified, height, topLeftZ - percent.y * meshSizeUnsimplified);
+
+                meshData.AddVertex(vertexPosition, percent, vertexIndex);
 
-                if (x < width - 1 && y < height - 1)
+                if (x < borderedSize - 1 && y < borderedSize - 1)
                 {
-                    meshData.AddTriangle(vertexIndex, vertexIndex + verticesPerLine + 1, vertexIndex + verticesPerLine);
-                    meshData.AddTriangle(vertexIndex + verticesPerLine + 1, vertexIndex, vertexIndex + 1);
+                    int a = vertexIndicesMap[x, y];
+                    int b = vertexIndicesMap[x + meshSimplificationIncrement, y];
+                    int c = vertexIndicesMap[x, y + meshSimplificationIncrement];
+                    int d = vertexIndicesMap[x + meshSimplificationIncrement, y + meshSimplificationIncrement];
+                    meshData.AddTriangle(a, d, c);
+                    meshData.AddTriangle(d, a, b);
                 }
 
                 vertexIndex++;
@@ -36,41 +71,133 @@ public static class MeshGenerator
         }
 
         return meshData;
+
     }
 }
 
 public class MeshData
 {
-    public Vector3[] vertices;
-    public int[] triangles;
-    public Vector2[] uvs;
+    Vector3[] vertices;
+    int[] triangles;
+    Vector2[] uvs;
+
+    Vector3[] borderVertices;
+    int[] borderTriangles;
 
     int triangleIndex;
+    int borderTriangleIndex;
 
-    public MeshData(int meshWidth, int meshHeight)
+    public MeshData(int verticesPerLine)
     {
-        vertices = new Vector3[meshWidth * meshHeight];
-        uvs = new Vector2[meshWidth * meshHeight];
-        triangles = new int[(meshWidth - 1) * (meshHeight - 1) * 6];
+        vertices = new Vector3[verticesPerLine * verticesPerLine];
+        uvs = new Vector2[verticesPerLine * verticesPerLine];
+        triangles = new int[(verticesPerLine - 1) * (verticesPerLine - 1) * 6];
+
+        borderVertices = new Vector3[verticesPerLine * 4 + 4];
+        borderTriangles = new int[24 * verticesPerLine];
+    }
+
+    public void AddVertex(Vector3 vertexPosition, Vector2 uv, int vertexIndex)
+    {
+        if (vertexIndex < 0)
+        {
+            borderVertices[-vertexIndex - 1] = vertexPosition;
+        }
+        else
+        {
+            vertices[vertexIndex] = vertexPosition;
+            uvs[vertexIndex] = uv;
+        }
     }
 
     public void AddTriangle(int a, int b, int c)
     {
-        triangles[triangleIndex] = a;
-        triangles[triangleIndex+1] = b;
-        triangles[triangleIndex+2] = c;
+        if (a < 0 || b < 0 || c < 0)
+        {
+            borderTriangles[borderTriangleIndex] = a;
+            borderTriangles[borderTriangleIndex + 1] = b;
+            borderTriangles[borderTriangleIndex + 2] = c;
+            borderTriangleIndex += 3;
+        }
+        else
+        {
+            triangles[triangleIndex] = a;
+            triangles[triangleIndex + 1] = b;
+            triangles[triangleIndex + 2] = c;
+            triangleIndex += 3;
+        }
+    }
+
+    Vector3[] CalculateNormals()
+    {
+
+        Vector3[] vertexNormals = new Vector3[vertices.Length];
+        int triangleCount = triangles.Length / 3;
+        for (int i = 0; i < triangleCount; i++)
+        {
+            int normalTriangleIndex = i * 3;
+            int vertexIndexA = triangles[normalTriangleIndex];
+            int vertexIndexB = triangles[normalTriangleIndex + 1];
+            int vertexIndexC = triangles[normalTriangleIndex + 2];
+
+            Vector3 triangleNormal = SurfaceNormalFromIndices(vertexIndexA, vertexIndexB, vertexIndexC);
+            vertexNormals[vertexIndexA] += triangleNormal;
+            vertexNormals[vertexIndexB] += triangleNormal;
+            vertexNormals[vertexIndexC] += triangleNormal;
+        }
+
+        int borderTriangleCount = borderTriangles.Length / 3;
+        for (int i = 0; i < borderTriangleCount; i++)
+        {
+            int normalTriangleIndex = i * 3;
+            int vertexIndexA = borderTriangles[normalTriangleIndex];
+            int vertexIndexB = borderTriangles[normalTriangleIndex + 1];
+            int vertexIndexC = borderTriangles[normalTriangleIndex + 2];
+
+            Vector3 triangleNormal = SurfaceNormalFromIndices(vertexIndexA, vertexIndexB, vertexIndexC);
+            if (vertexIndexA >= 0)
+            {
+                vertexNormals[vertexIndexA] += triangleNormal;
+            }
+            if (vertexIndexB >= 0)
+            {
+                vertexNormals[vertexIndexB] += triangleNormal;
+            }
+            if (vertexIndexC >= 0)
+            {
+                vertexNormals[vertexIndexC] += triangleNormal;
+            }
+        }
+
+
+        for (int i = 0; i < vertexNormals.Length; i++)
+        {
+            vertexNormals[i].Normalize();
+        }
+
+        return vertexNormals;
+
+    }
+
+    Vector3 SurfaceNormalFromIndices(int indexA, int indexB, int indexC)
+    {
+        Vector3 pointA = (indexA < 0) ? borderVertices[-indexA - 1] : vertices[indexA];
+        Vector3 pointB = (indexB < 0) ? borderVertices[-indexB - 1] : vertices[indexB];
+        Vector3 pointC = (indexC < 0) ? borderVertices[-indexC - 1] : vertices[indexC];
 
-        triangleIndex += 3;
+        Vector3 sideAB = pointB - pointA;
+        Vector3 sideAC = pointC - pointA;
+        return Vector3.Cross(sideAB, sideAC).normalized;
     }
 
     public Mesh CreateMesh()
     {
-        Mesh mesh = new();
+        Mesh mesh = new Mesh();
         mesh.vertices = vertices;
         mesh.triangles = triangles;
         mesh.uv = uvs;
-        mesh.RecalculateNormals();
-
+        mesh.normals = CalculateNormals();
         return mesh;
     }
-}
+
+}

+ 7 - 3
Assets/Scripts/TextureGenerator.cs

@@ -1,10 +1,12 @@
 using UnityEngine;
+using System.Collections;
 
 public static class TextureGenerator
 {
+
     public static Texture2D TextureFromColourMap(Color[] colourMap, int width, int height)
     {
-        Texture2D texture = new(width, height);
+        Texture2D texture = new Texture2D(width, height);
         texture.filterMode = FilterMode.Point;
         texture.wrapMode = TextureWrapMode.Clamp;
         texture.SetPixels(colourMap);
@@ -12,13 +14,13 @@ public static class TextureGenerator
         return texture;
     }
 
+
     public static Texture2D TextureFromHeightMap(float[,] heightMap)
     {
         int width = heightMap.GetLength(0);
         int height = heightMap.GetLength(1);
 
         Color[] colourMap = new Color[width * height];
-
         for (int y = 0; y < height; y++)
         {
             for (int x = 0; x < width; x++)
@@ -26,6 +28,8 @@ public static class TextureGenerator
                 colourMap[y * width + x] = Color.Lerp(Color.black, Color.white, heightMap[x, y]);
             }
         }
+
         return TextureFromColourMap(colourMap, width, height);
     }
-}
+
+}

Some files were not shown because too many files changed in this diff