From 22eb24a7d8ac1bde2b787ee044e68f04dcf9c8ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomislav=20Reki=C4=87?= <44620759+tomislavrekic@users.noreply.github.com> Date: Fri, 12 Jan 2024 08:55:32 +0100 Subject: [PATCH 1/2] Fixed map size, reworked assets and terrain generation Added fixed map size which can be changed in the MapGenerator. FallOffGenerator is used to create a boundary around the map. HeightMapSettings reworked to allow stacking of multiple layers of noise. NoiseSettings now a standalone asset. --- Proc Gen E21/Assets/Editor.meta | 5 +- Proc Gen E21/Assets/Materials.meta | 5 +- Proc Gen E21/Assets/Materials/Map Mat.mat | Bin 4892 -> 2071 bytes .../Assets/Materials/Map Mat.mat.meta | 6 +- Proc Gen E21/Assets/Materials/Mesh Mat.mat | Bin 5188 -> 2572 bytes .../Assets/Materials/Mesh Mat.mat.meta | 6 +- Proc Gen E21/Assets/Scenes.meta | 5 +- Proc Gen E21/Assets/Scripts.meta | 5 +- Proc Gen E21/Assets/Scripts/Data.meta | 5 +- .../Assets/Scripts/Data/HeightMapSettings.cs | 26 ++--- .../Scripts/Data/HeightMapSettings.cs.meta | 5 +- .../Assets/Scripts/Data/MeshSettings.cs.meta | 5 +- .../Assets/Scripts/Data/NoiseSettings.cs | 41 +++++++ .../Assets/Scripts/Data/NoiseSettings.cs.meta | 11 ++ .../Assets/Scripts/Data/TextureData.cs.meta | 5 +- .../Assets/Scripts/Data/UpdatableData.cs.meta | 5 +- .../Assets/Scripts/FalloffGenerator.cs | 107 +++++++++++++++--- .../Assets/Scripts/FalloffGenerator.cs.meta | 5 +- .../Assets/Scripts/HeightMapGenerator.cs | 51 ++++++--- .../Assets/Scripts/HeightMapGenerator.cs.meta | 5 +- .../Assets/Scripts/HideOnPlay.cs.meta | 5 +- Proc Gen E21/Assets/Scripts/MapPreview.cs | 19 +++- .../Assets/Scripts/MapPreview.cs.meta | 5 +- .../Assets/Scripts/MeshGenerator.cs.meta | 5 +- Proc Gen E21/Assets/Scripts/Noise.cs | 49 +------- Proc Gen E21/Assets/Scripts/Noise.cs.meta | 5 +- Proc Gen E21/Assets/Scripts/Terrain.shader | 8 +- .../Assets/Scripts/Terrain.shader.meta | 6 +- Proc Gen E21/Assets/Scripts/TerrainChunk.cs | 10 +- .../Assets/Scripts/TerrainChunk.cs.meta | 5 +- .../Assets/Scripts/TerrainGenerator.cs | 59 +++++++++- .../Assets/Scripts/TerrainGenerator.cs.meta | 5 +- .../Assets/Scripts/TextureGenerator.cs.meta | 5 +- .../Scripts/ThreadedDataRequester.cs.meta | 5 +- Proc Gen E21/Assets/Standard Assets.meta | 5 +- Proc Gen E21/Assets/Terrain Assets.meta | 5 +- .../Assets/Terrain Assets/Boulders.asset | 46 ++++++++ .../Assets/Terrain Assets/Boulders.asset.meta | 8 ++ .../Terrain Assets/Continentalness.asset | 82 ++++++++++++++ .../Terrain Assets/Continentalness.asset.meta | 8 ++ .../Terrain Assets/Default Texture.asset | Bin 4452 -> 1789 bytes .../Assets/Terrain Assets/HMSettings.asset | 48 ++++++++ ...tings.asset.meta => HMSettings.asset.meta} | 0 .../Assets/Terrain Assets/Mesh Settings.asset | 19 ++++ ...gs.asset.meta => Mesh Settings.asset.meta} | 0 .../New Height Map Settings.asset | Bin 4328 -> 0 bytes .../Terrain Assets/New Mesh Settings.asset | Bin 4204 -> 0 bytes .../Assets/Terrain Assets/PeaksValleys.asset | 64 +++++++++++ .../Terrain Assets/PeaksValleys.asset.meta | 8 ++ Proc Gen E21/Assets/Textures.meta | 5 +- 50 files changed, 618 insertions(+), 174 deletions(-) create mode 100644 Proc Gen E21/Assets/Scripts/Data/NoiseSettings.cs create mode 100644 Proc Gen E21/Assets/Scripts/Data/NoiseSettings.cs.meta create mode 100644 Proc Gen E21/Assets/Terrain Assets/Boulders.asset create mode 100644 Proc Gen E21/Assets/Terrain Assets/Boulders.asset.meta create mode 100644 Proc Gen E21/Assets/Terrain Assets/Continentalness.asset create mode 100644 Proc Gen E21/Assets/Terrain Assets/Continentalness.asset.meta create mode 100644 Proc Gen E21/Assets/Terrain Assets/HMSettings.asset rename Proc Gen E21/Assets/Terrain Assets/{New Height Map Settings.asset.meta => HMSettings.asset.meta} (100%) create mode 100644 Proc Gen E21/Assets/Terrain Assets/Mesh Settings.asset rename Proc Gen E21/Assets/Terrain Assets/{New Mesh Settings.asset.meta => Mesh Settings.asset.meta} (100%) delete mode 100644 Proc Gen E21/Assets/Terrain Assets/New Height Map Settings.asset delete mode 100644 Proc Gen E21/Assets/Terrain Assets/New Mesh Settings.asset create mode 100644 Proc Gen E21/Assets/Terrain Assets/PeaksValleys.asset create mode 100644 Proc Gen E21/Assets/Terrain Assets/PeaksValleys.asset.meta diff --git a/Proc Gen E21/Assets/Editor.meta b/Proc Gen E21/Assets/Editor.meta index bebcf77f..30740491 100644 --- a/Proc Gen E21/Assets/Editor.meta +++ b/Proc Gen E21/Assets/Editor.meta @@ -1,9 +1,8 @@ fileFormatVersion: 2 -guid: bf078e660099b48bc84e3a0fc60a64c2 +guid: 5bbfc24fa2b99204286bf1daab24a821 folderAsset: yes -timeCreated: 1454754699 -licenseType: Pro DefaultImporter: + externalObjects: {} userData: assetBundleName: assetBundleVariant: diff --git a/Proc Gen E21/Assets/Materials.meta b/Proc Gen E21/Assets/Materials.meta index 33583fb9..c02e7769 100644 --- a/Proc Gen E21/Assets/Materials.meta +++ b/Proc Gen E21/Assets/Materials.meta @@ -1,9 +1,8 @@ fileFormatVersion: 2 -guid: f61c9fb70610d46e8bd80bc9290917e0 +guid: dfadc4e72f34e9a46b698ea9e9336c89 folderAsset: yes -timeCreated: 1454754651 -licenseType: Pro DefaultImporter: + externalObjects: {} userData: assetBundleName: assetBundleVariant: diff --git a/Proc Gen E21/Assets/Materials/Map Mat.mat b/Proc Gen E21/Assets/Materials/Map Mat.mat index abf065a6be3c363c6d07ed922e246a237e4fb7cc..9fd42c11c98fec16bbb5f3503e95b677463abd05 100644 GIT binary patch literal 2071 zcmcgtQBT`25Pt8kFc0jhMNJXfl(#~GRU^|am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}m)+I~D zmw#^G$IntztH^P%Q23X&0I=9(#Z+z&NwRlL^mGP(Z-+y;-Ff(fX4X3AN A4gdfE diff --git a/Proc Gen E21/Assets/Materials/Mesh Mat.mat.meta b/Proc Gen E21/Assets/Materials/Mesh Mat.mat.meta index f0d3c7ed..c9c5d113 100644 --- a/Proc Gen E21/Assets/Materials/Mesh Mat.mat.meta +++ b/Proc Gen E21/Assets/Materials/Mesh Mat.mat.meta @@ -1,8 +1,8 @@ fileFormatVersion: 2 -guid: b0872f84cf3c7441d893168677410c73 -timeCreated: 1455974709 -licenseType: Pro +guid: 6be612d4032a3fb4c9f67a0e30ca37e9 NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 0 userData: assetBundleName: assetBundleVariant: diff --git a/Proc Gen E21/Assets/Scenes.meta b/Proc Gen E21/Assets/Scenes.meta index 1946b9fe..9532f474 100644 --- a/Proc Gen E21/Assets/Scenes.meta +++ b/Proc Gen E21/Assets/Scenes.meta @@ -1,9 +1,8 @@ fileFormatVersion: 2 -guid: feba693715bef48e2be2f857837ee048 +guid: 7ff690a1ee8ab7446bb964028cc53e16 folderAsset: yes -timeCreated: 1454753180 -licenseType: Pro DefaultImporter: + externalObjects: {} userData: assetBundleName: assetBundleVariant: diff --git a/Proc Gen E21/Assets/Scripts.meta b/Proc Gen E21/Assets/Scripts.meta index bf7d5918..67a0bdec 100644 --- a/Proc Gen E21/Assets/Scripts.meta +++ b/Proc Gen E21/Assets/Scripts.meta @@ -1,9 +1,8 @@ fileFormatVersion: 2 -guid: 08021d2aed08a43afb65af2c61e3f366 +guid: 86f2575c97621124591f69d45d5f5345 folderAsset: yes -timeCreated: 1454753191 -licenseType: Pro DefaultImporter: + externalObjects: {} userData: assetBundleName: assetBundleVariant: diff --git a/Proc Gen E21/Assets/Scripts/Data.meta b/Proc Gen E21/Assets/Scripts/Data.meta index 06a2dc1a..454aaa59 100644 --- a/Proc Gen E21/Assets/Scripts/Data.meta +++ b/Proc Gen E21/Assets/Scripts/Data.meta @@ -1,9 +1,8 @@ fileFormatVersion: 2 -guid: bdcff4314b22342edb885bff58d7dd15 +guid: 1700a9cf9e4d9724ca97aa4f05e786f8 folderAsset: yes -timeCreated: 1474627643 -licenseType: Pro DefaultImporter: + externalObjects: {} userData: assetBundleName: assetBundleVariant: diff --git a/Proc Gen E21/Assets/Scripts/Data/HeightMapSettings.cs b/Proc Gen E21/Assets/Scripts/Data/HeightMapSettings.cs index f919b092..de78bc71 100644 --- a/Proc Gen E21/Assets/Scripts/Data/HeightMapSettings.cs +++ b/Proc Gen E21/Assets/Scripts/Data/HeightMapSettings.cs @@ -1,17 +1,17 @@ using UnityEngine; using System.Collections; +using UnityEngine.UIElements; [CreateAssetMenu()] public class HeightMapSettings : UpdatableData { - public NoiseSettings noiseSettings; - - public bool useFalloff; - + public NoiseLayers[] noiseLayers; public float heightMultiplier; + [Range(0f, 1f)] + public float fallOffIntensity; public AnimationCurve heightCurve; - public float minHeight { + public float minHeight { get { return heightMultiplier * heightCurve.Evaluate (0); } @@ -22,13 +22,13 @@ public float maxHeight { return heightMultiplier * heightCurve.Evaluate (1); } } +} - #if UNITY_EDITOR - - protected override void OnValidate() { - noiseSettings.ValidateValues (); - base.OnValidate (); - } - #endif -} +[System.Serializable] +public struct NoiseLayers +{ + public NoiseSettings noiseSettings; + [Range(0f, 1f)] + public float strength; +} \ No newline at end of file diff --git a/Proc Gen E21/Assets/Scripts/Data/HeightMapSettings.cs.meta b/Proc Gen E21/Assets/Scripts/Data/HeightMapSettings.cs.meta index 04007f5d..c9b7ab33 100644 --- a/Proc Gen E21/Assets/Scripts/Data/HeightMapSettings.cs.meta +++ b/Proc Gen E21/Assets/Scripts/Data/HeightMapSettings.cs.meta @@ -1,8 +1,7 @@ fileFormatVersion: 2 -guid: eb49c415c73a941729b11c3076268f15 -timeCreated: 1496316732 -licenseType: Pro +guid: 22f82a005245ce8429addea428a79d0c MonoImporter: + externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 diff --git a/Proc Gen E21/Assets/Scripts/Data/MeshSettings.cs.meta b/Proc Gen E21/Assets/Scripts/Data/MeshSettings.cs.meta index 30146c20..c45a29fa 100644 --- a/Proc Gen E21/Assets/Scripts/Data/MeshSettings.cs.meta +++ b/Proc Gen E21/Assets/Scripts/Data/MeshSettings.cs.meta @@ -1,8 +1,7 @@ fileFormatVersion: 2 -guid: f3cce3b9cb6274d299978f334a2cefde -timeCreated: 1496321326 -licenseType: Pro +guid: 2c087144dee755742a20ef57168ce9f0 MonoImporter: + externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 diff --git a/Proc Gen E21/Assets/Scripts/Data/NoiseSettings.cs b/Proc Gen E21/Assets/Scripts/Data/NoiseSettings.cs new file mode 100644 index 00000000..3152a748 --- /dev/null +++ b/Proc Gen E21/Assets/Scripts/Data/NoiseSettings.cs @@ -0,0 +1,41 @@ +using UnityEngine; +using System.Collections; + +[CreateAssetMenu()] +public class NoiseSettings : UpdatableData +{ + public Noise.NormalizeMode normalizeMode; + + public float scale = 50; + + [Range(1, 20)] + public int octaves = 6; + [Range(0, 1)] + public float persistance = .6f; + [Range(1, 20)] + public float lacunarity = 2; + + public int seed; + public Vector2 offset; + + public AnimationCurve noiseCurve; + +#if UNITY_EDITOR + + protected override void OnValidate() + { + ValidateValues(); + base.OnValidate(); + } + + public void ValidateValues() + { + scale = Mathf.Max(scale, 0.01f); + octaves = Mathf.Max(octaves, 1); + lacunarity = Mathf.Max(lacunarity, 1); + persistance = Mathf.Clamp01(persistance); + } +#endif + + +} \ No newline at end of file diff --git a/Proc Gen E21/Assets/Scripts/Data/NoiseSettings.cs.meta b/Proc Gen E21/Assets/Scripts/Data/NoiseSettings.cs.meta new file mode 100644 index 00000000..bc743450 --- /dev/null +++ b/Proc Gen E21/Assets/Scripts/Data/NoiseSettings.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d7b5971f7324f7d4aab07cfd82eba195 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Proc Gen E21/Assets/Scripts/Data/TextureData.cs.meta b/Proc Gen E21/Assets/Scripts/Data/TextureData.cs.meta index ac1e7998..dc0b5f11 100644 --- a/Proc Gen E21/Assets/Scripts/Data/TextureData.cs.meta +++ b/Proc Gen E21/Assets/Scripts/Data/TextureData.cs.meta @@ -1,8 +1,7 @@ fileFormatVersion: 2 -guid: 24bba47da550c4e86a3c8ae5cf2e264d -timeCreated: 1474633465 -licenseType: Pro +guid: f9e1c1f0f615d894ebebb376f45b96cc MonoImporter: + externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 diff --git a/Proc Gen E21/Assets/Scripts/Data/UpdatableData.cs.meta b/Proc Gen E21/Assets/Scripts/Data/UpdatableData.cs.meta index 46279a3a..cf8313e9 100644 --- a/Proc Gen E21/Assets/Scripts/Data/UpdatableData.cs.meta +++ b/Proc Gen E21/Assets/Scripts/Data/UpdatableData.cs.meta @@ -1,8 +1,7 @@ fileFormatVersion: 2 -guid: 616cf27add49146ab8c3c372774d402b -timeCreated: 1474629138 -licenseType: Pro +guid: d4f32288fe396a748bc5a02c0abbcf6b MonoImporter: + externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 diff --git a/Proc Gen E21/Assets/Scripts/FalloffGenerator.cs b/Proc Gen E21/Assets/Scripts/FalloffGenerator.cs index 99c3895d..a7b8924c 100644 --- a/Proc Gen E21/Assets/Scripts/FalloffGenerator.cs +++ b/Proc Gen E21/Assets/Scripts/FalloffGenerator.cs @@ -1,28 +1,107 @@ using UnityEngine; using System.Collections; + public static class FalloffGenerator { - public static float[,] GenerateFalloffMap(int size) { - float[,] map = new float[size,size]; + public enum FallOffType { None, Ocean, WestCoast, EastCoast, NorthCoast, SouthCoast, NWCoast, NECoast, SWCoast, SECoast } - for (int i = 0; i < size; i++) { - for (int j = 0; j < size; j++) { - float x = i / (float)size * 2 - 1; - float y = j / (float)size * 2 - 1; + public static float[,] GenerateFalloffMap(int size, FallOffType falloffType, float intensity) { + float[,] map = new float[size,size]; + if (falloffType == FallOffType.None) + { + for (int i = 0; i < size; i++) + { + for (int j = 0; j < size; j++) + { + map[i, j] = 1; + } + } + return map; + } - float value = Mathf.Max (Mathf.Abs (x), Mathf.Abs (y)); - map [i, j] = Evaluate(value); + if (falloffType == FallOffType.Ocean) + { + for (int i = 0; i < size; i++) + { + for (int j = 0; j < size; j++) + { + map[i, j] = 1 - intensity; + } } + return map; } - return map; - } - static float Evaluate(float value) { - float a = 3; - float b = 2.2f; + for (int i = 0; i < size; i++) { + for (int j = 0; j < size; j++) { + float x = i / ((float)size-1); + float y = j / ((float)size-1); + + if (falloffType == FallOffType.WestCoast) + { + x = 1-x; + y = 0; + } + else if (falloffType == FallOffType.EastCoast) + { + //x = x; + y = 0; + } + if (falloffType == FallOffType.NorthCoast) + { + y = 1-y; + x = 0; + } + else if (falloffType == FallOffType.SouthCoast) + { + //y = y; + x = 0; + } + else if (falloffType == FallOffType.NWCoast) + { + x = 1-x; + y = 1-y; + } + else if (falloffType == FallOffType.NECoast) + { + //x = x; + y = 1 - y; + } + else if (falloffType == FallOffType.SWCoast) + { + x = 1 - x; + //y = y; + } + else if (falloffType == FallOffType.SECoast) + { + //x = x; + //y = y; + } + + float valueX = SmoothStep(0, 1, x); + float valueY = SmoothStep(0, 1, y); + + map [i, j] = Mathf.Max(valueX, valueY) * intensity; + map[i, j] = 1 - map[i, j]; - return Mathf.Pow (value, a) / (Mathf.Pow (value, a) + Mathf.Pow (b - b * value, a)); + } + } + return map; } + //https://en.wikipedia.org/wiki/Smoothstep + static float SmoothStep(float edge0, float edge1, float x) + { + // Scale, and clamp x to 0..1 range + x = clamp((x-edge0) / (edge1-edge0)); + return x * x * (3.0f - 2.0f * x); + } + + static float clamp(float x, float lowerlimit = 0.0f, float upperlimit = 1.0f) + { + if (x < lowerlimit) return lowerlimit; + if (x > upperlimit) return upperlimit; + return x; + } + } diff --git a/Proc Gen E21/Assets/Scripts/FalloffGenerator.cs.meta b/Proc Gen E21/Assets/Scripts/FalloffGenerator.cs.meta index 3c439528..70f63b30 100644 --- a/Proc Gen E21/Assets/Scripts/FalloffGenerator.cs.meta +++ b/Proc Gen E21/Assets/Scripts/FalloffGenerator.cs.meta @@ -1,8 +1,7 @@ fileFormatVersion: 2 -guid: 94ecc0bec425d4c9a94a55c7bc8f1fea -timeCreated: 1462976878 -licenseType: Pro +guid: 8df95a71a3cfafe41a82fd0f790892a8 MonoImporter: + externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 diff --git a/Proc Gen E21/Assets/Scripts/HeightMapGenerator.cs b/Proc Gen E21/Assets/Scripts/HeightMapGenerator.cs index fc84aef2..4c9bc651 100644 --- a/Proc Gen E21/Assets/Scripts/HeightMapGenerator.cs +++ b/Proc Gen E21/Assets/Scripts/HeightMapGenerator.cs @@ -1,31 +1,56 @@ using System.Collections; using System.Collections.Generic; +using System.Linq; using UnityEngine; public static class HeightMapGenerator { - public static HeightMap GenerateHeightMap(int width, int height, HeightMapSettings settings, Vector2 sampleCentre) { - float[,] values = Noise.GenerateNoiseMap (width, height, settings.noiseSettings, sampleCentre); + public static HeightMap GenerateHeightMap(int width, int height, FalloffGenerator.FallOffType fallOffType, HeightMapSettings heightMapSettings, Vector2 sampleCentre) { + float[,,] noiseLayers = new float[heightMapSettings.noiseLayers.Length, width, height]; + float[,] falloffMap = FalloffGenerator.GenerateFalloffMap(width, fallOffType, heightMapSettings.fallOffIntensity); + for (int k = 0; k < heightMapSettings.noiseLayers.Length; k++) + { + AnimationCurve noiseCurve_threadsafe = new AnimationCurve(heightMapSettings.noiseLayers[k].noiseSettings.noiseCurve.keys); + float[,] values = Noise.GenerateNoiseMap(width, height, heightMapSettings.noiseLayers[k].noiseSettings, sampleCentre); - AnimationCurve heightCurve_threadsafe = new AnimationCurve (settings.heightCurve.keys); + for (int i = 0; i < width; i++) + { + for (int j = 0; j < height; j++) + { + noiseLayers[k, i, j] = noiseCurve_threadsafe.Evaluate(values[i, j]); + } + } + } - float minValue = float.MaxValue; + float minValue = float.MaxValue; float maxValue = float.MinValue; + AnimationCurve heightCurve_threadsafe = new AnimationCurve(heightMapSettings.heightCurve.keys); - for (int i = 0; i < width; i++) { - for (int j = 0; j < height; j++) { - values [i, j] *= heightCurve_threadsafe.Evaluate (values [i, j]) * settings.heightMultiplier; + float[,] heightFinalValues = new float[width, height]; + for (int i = 0; i < width; i++) + { + for (int j = 0; j < height; j++) + { + float noiseSum = 0; + float maxPossibleVal = 0; + for (int k = 0; k < heightMapSettings.noiseLayers.Length; k++) + { + noiseSum += noiseLayers[k, i, j] * heightMapSettings.noiseLayers[k].strength; + maxPossibleVal += heightMapSettings.noiseLayers[k].strength; + } + + heightFinalValues[i,j] = heightCurve_threadsafe.Evaluate((noiseSum / maxPossibleVal) * falloffMap[i, j]) * heightMapSettings.heightMultiplier; - if (values [i, j] > maxValue) { - maxValue = values [i, j]; + if (heightFinalValues[i, j] > maxValue) { + maxValue = heightFinalValues[i, j]; } - if (values [i, j] < minValue) { - minValue = values [i, j]; + if (heightFinalValues[i, j] < minValue) { + minValue = heightFinalValues[i, j]; } } - } + } - return new HeightMap (values, minValue, maxValue); + return new HeightMap (heightFinalValues, minValue, maxValue); } } diff --git a/Proc Gen E21/Assets/Scripts/HeightMapGenerator.cs.meta b/Proc Gen E21/Assets/Scripts/HeightMapGenerator.cs.meta index c3cff8c5..e609e3bc 100644 --- a/Proc Gen E21/Assets/Scripts/HeightMapGenerator.cs.meta +++ b/Proc Gen E21/Assets/Scripts/HeightMapGenerator.cs.meta @@ -1,8 +1,7 @@ fileFormatVersion: 2 -guid: 80a00a52d74ab4bd499aab44a48fb9c2 -timeCreated: 1496313471 -licenseType: Pro +guid: 0028f9ac38747994da811f11a9aa1e55 MonoImporter: + externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 diff --git a/Proc Gen E21/Assets/Scripts/HideOnPlay.cs.meta b/Proc Gen E21/Assets/Scripts/HideOnPlay.cs.meta index 6b8be0f7..c5af3675 100644 --- a/Proc Gen E21/Assets/Scripts/HideOnPlay.cs.meta +++ b/Proc Gen E21/Assets/Scripts/HideOnPlay.cs.meta @@ -1,8 +1,7 @@ fileFormatVersion: 2 -guid: 7712ca4b498404cc5931aea5ebc20f51 -timeCreated: 1472545823 -licenseType: Pro +guid: a396c7b309a68634ba9188f42c0d5210 MonoImporter: + externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 diff --git a/Proc Gen E21/Assets/Scripts/MapPreview.cs b/Proc Gen E21/Assets/Scripts/MapPreview.cs index 30077f75..74b2c34e 100644 --- a/Proc Gen E21/Assets/Scripts/MapPreview.cs +++ b/Proc Gen E21/Assets/Scripts/MapPreview.cs @@ -11,12 +11,18 @@ public class MapPreview : MonoBehaviour { public enum DrawMode {NoiseMap, Mesh, FalloffMap}; public DrawMode drawMode; + public FalloffGenerator.FallOffType fallOffType; + [Range(0.0f, 1.0f)] + public float fallOffIntensity; + public MeshSettings meshSettings; public HeightMapSettings heightMapSettings; public TextureData textureData; public Material terrainMaterial; + public NoiseSettings[] noiseSettingsListener; + [Range(0,MeshSettings.numSupportedLODs-1)] @@ -29,14 +35,14 @@ public enum DrawMode {NoiseMap, Mesh, FalloffMap}; public void DrawMapInEditor() { textureData.ApplyToMaterial (terrainMaterial); textureData.UpdateMeshHeights (terrainMaterial, heightMapSettings.minHeight, heightMapSettings.maxHeight); - HeightMap heightMap = HeightMapGenerator.GenerateHeightMap (meshSettings.numVertsPerLine, meshSettings.numVertsPerLine, heightMapSettings, Vector2.zero); + HeightMap heightMap = HeightMapGenerator.GenerateHeightMap (meshSettings.numVertsPerLine, meshSettings.numVertsPerLine, FalloffGenerator.FallOffType.None, heightMapSettings, Vector2.zero); if (drawMode == DrawMode.NoiseMap) { DrawTexture (TextureGenerator.TextureFromHeightMap (heightMap)); } else if (drawMode == DrawMode.Mesh) { DrawMesh (MeshGenerator.GenerateTerrainMesh (heightMap.values,meshSettings, editorPreviewLOD)); } else if (drawMode == DrawMode.FalloffMap) { - DrawTexture(TextureGenerator.TextureFromHeightMap(new HeightMap(FalloffGenerator.GenerateFalloffMap(meshSettings.numVertsPerLine),0,1))); + DrawTexture(TextureGenerator.TextureFromHeightMap(new HeightMap(FalloffGenerator.GenerateFalloffMap(meshSettings.numVertsPerLine, fallOffType, fallOffIntensity),0,1))); } } @@ -73,6 +79,15 @@ void OnTextureValuesUpdated() { void OnValidate() { + for (int i = 0; i maxLocalNoiseHeight) { - maxLocalNoiseHeight = noiseHeight; - } - if (noiseHeight < minLocalNoiseHeight) { - minLocalNoiseHeight = noiseHeight; - } noiseMap [x, y] = noiseHeight; if (settings.normalizeMode == NormalizeMode.Global) { - float normalizedHeight = (noiseMap [x, y] + 1) / (maxPossibleHeight / 0.9f); - noiseMap [x, y] = Mathf.Clamp (normalizedHeight, 0, int.MaxValue); + float normalizedHeight = (noiseMap [x, y] + (maxPossibleHeight/2)) / maxPossibleHeight; + noiseMap [x, y] = Mathf.Clamp (normalizedHeight, 0, 1f); } } } - if (settings.normalizeMode == NormalizeMode.Local) { - for (int y = 0; y < mapHeight; y++) { - for (int x = 0; x < mapWidth; x++) { - noiseMap [x, y] = Mathf.InverseLerp (minLocalNoiseHeight, maxLocalNoiseHeight, noiseMap [x, y]); - } - } - } - - return noiseMap; + return noiseMap; } } -[System.Serializable] -public class NoiseSettings { - public Noise.NormalizeMode normalizeMode; - - public float scale = 50; - - public int octaves = 6; - [Range(0,1)] - public float persistance =.6f; - public float lacunarity = 2; - - public int seed; - public Vector2 offset; - - public void ValidateValues() { - scale = Mathf.Max (scale, 0.01f); - octaves = Mathf.Max (octaves, 1); - lacunarity = Mathf.Max (lacunarity, 1); - persistance = Mathf.Clamp01 (persistance); - } -} \ No newline at end of file diff --git a/Proc Gen E21/Assets/Scripts/Noise.cs.meta b/Proc Gen E21/Assets/Scripts/Noise.cs.meta index d30f7c1b..941f115c 100644 --- a/Proc Gen E21/Assets/Scripts/Noise.cs.meta +++ b/Proc Gen E21/Assets/Scripts/Noise.cs.meta @@ -1,8 +1,7 @@ fileFormatVersion: 2 -guid: d4ed0d0ddb42c4af290db1cea4b1264f -timeCreated: 1454753270 -licenseType: Pro +guid: 0bad2b016d0f20246b6db530bf9af699 MonoImporter: + externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 diff --git a/Proc Gen E21/Assets/Scripts/Terrain.shader b/Proc Gen E21/Assets/Scripts/Terrain.shader index 64b7059b..d5dba903 100644 --- a/Proc Gen E21/Assets/Scripts/Terrain.shader +++ b/Proc Gen E21/Assets/Scripts/Terrain.shader @@ -1,7 +1,7 @@ Shader "Custom/Terrain" { Properties { - testTexture("Texture", 2D) = "white"{} - testScale("Scale", Float) = 1 + //testTexture("Texture", 2D) = "white"{} + //testScale("Scale", Float) = 1 } SubShader { @@ -28,8 +28,8 @@ float minHeight; float maxHeight; - sampler2D testTexture; - float testScale; + //sampler2D testTexture; + //float testScale; UNITY_DECLARE_TEX2DARRAY(baseTextures); diff --git a/Proc Gen E21/Assets/Scripts/Terrain.shader.meta b/Proc Gen E21/Assets/Scripts/Terrain.shader.meta index e3fa8811..b6b29e5b 100644 --- a/Proc Gen E21/Assets/Scripts/Terrain.shader.meta +++ b/Proc Gen E21/Assets/Scripts/Terrain.shader.meta @@ -1,9 +1,9 @@ fileFormatVersion: 2 -guid: e9c611933fe9745ebbd2c506d7711c71 -timeCreated: 1481137042 -licenseType: Pro +guid: 7e1766a4b61db3a4ea30b204abca2ff6 ShaderImporter: + externalObjects: {} defaultTextures: [] + nonModifiableTextures: [] userData: assetBundleName: assetBundleVariant: diff --git a/Proc Gen E21/Assets/Scripts/TerrainChunk.cs b/Proc Gen E21/Assets/Scripts/TerrainChunk.cs index b14462f7..5aeff1f1 100644 --- a/Proc Gen E21/Assets/Scripts/TerrainChunk.cs +++ b/Proc Gen E21/Assets/Scripts/TerrainChunk.cs @@ -2,7 +2,7 @@ public class TerrainChunk { - const float colliderGenerationDistanceThreshold = 5; + const float colliderGenerationDistanceThreshold = 25; public event System.Action onVisibilityChanged; public Vector2 coord; @@ -28,13 +28,16 @@ public class TerrainChunk { MeshSettings meshSettings; Transform viewer; - public TerrainChunk(Vector2 coord, HeightMapSettings heightMapSettings, MeshSettings meshSettings, LODInfo[] detailLevels, int colliderLODIndex, Transform parent, Transform viewer, Material material) { + FalloffGenerator.FallOffType fallOffType; + + public TerrainChunk(Vector2 coord, FalloffGenerator.FallOffType fallOffType, HeightMapSettings heightMapSettings, MeshSettings meshSettings, LODInfo[] detailLevels, int colliderLODIndex, Transform parent, Transform viewer, Material material) { this.coord = coord; this.detailLevels = detailLevels; this.colliderLODIndex = colliderLODIndex; this.heightMapSettings = heightMapSettings; this.meshSettings = meshSettings; this.viewer = viewer; + this.fallOffType = fallOffType; sampleCentre = coord * meshSettings.meshWorldSize / meshSettings.meshScale; Vector2 position = coord * meshSettings.meshWorldSize ; @@ -65,7 +68,7 @@ public TerrainChunk(Vector2 coord, HeightMapSettings heightMapSettings, MeshSett } public void Load() { - ThreadedDataRequester.RequestData(() => HeightMapGenerator.GenerateHeightMap (meshSettings.numVertsPerLine, meshSettings.numVertsPerLine, heightMapSettings, sampleCentre), OnHeightMapReceived); + ThreadedDataRequester.RequestData(() => HeightMapGenerator.GenerateHeightMap (meshSettings.numVertsPerLine, meshSettings.numVertsPerLine, fallOffType, heightMapSettings, sampleCentre), OnHeightMapReceived); } @@ -75,6 +78,7 @@ void OnHeightMapReceived(object heightMapObject) { heightMapReceived = true; UpdateTerrainChunk (); + UpdateCollisionMesh(); } Vector2 viewerPosition { diff --git a/Proc Gen E21/Assets/Scripts/TerrainChunk.cs.meta b/Proc Gen E21/Assets/Scripts/TerrainChunk.cs.meta index 84041a46..ca38f2ba 100644 --- a/Proc Gen E21/Assets/Scripts/TerrainChunk.cs.meta +++ b/Proc Gen E21/Assets/Scripts/TerrainChunk.cs.meta @@ -1,8 +1,7 @@ fileFormatVersion: 2 -guid: 63d2a970007f84193bf05f8f667daa73 -timeCreated: 1496353870 -licenseType: Pro +guid: a3f912307c0e3844bb926903322e42ac MonoImporter: + externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 diff --git a/Proc Gen E21/Assets/Scripts/TerrainGenerator.cs b/Proc Gen E21/Assets/Scripts/TerrainGenerator.cs index c00cb4a1..28bd7ce0 100644 --- a/Proc Gen E21/Assets/Scripts/TerrainGenerator.cs +++ b/Proc Gen E21/Assets/Scripts/TerrainGenerator.cs @@ -4,7 +4,7 @@ public class TerrainGenerator : MonoBehaviour { - const float viewerMoveThresholdForChunkUpdate = 25f; + const float viewerMoveThresholdForChunkUpdate = 10f; const float sqrViewerMoveThresholdForChunkUpdate = viewerMoveThresholdForChunkUpdate * viewerMoveThresholdForChunkUpdate; @@ -13,11 +13,14 @@ public class TerrainGenerator : MonoBehaviour { public MeshSettings meshSettings; public HeightMapSettings heightMapSettings; - public TextureData textureSettings; + public TextureData textureSettings; public Transform viewer; public Material mapMaterial; + public Vector2 mapSize; + Vector2 mapSizeInChunks; + Vector2 viewerPosition; Vector2 viewerPositionOld; @@ -36,6 +39,8 @@ void Start() { meshWorldSize = meshSettings.meshWorldSize; chunksVisibleInViewDst = Mathf.RoundToInt(maxViewDst / meshWorldSize); + mapSizeInChunks = new Vector2(Mathf.RoundToInt(mapSize.x / meshWorldSize), Mathf.RoundToInt(mapSize.y / meshWorldSize)); + UpdateVisibleChunks (); } @@ -71,10 +76,7 @@ void UpdateVisibleChunks() { if (terrainChunkDictionary.ContainsKey (viewedChunkCoord)) { terrainChunkDictionary [viewedChunkCoord].UpdateTerrainChunk (); } else { - TerrainChunk newChunk = new TerrainChunk (viewedChunkCoord,heightMapSettings,meshSettings, detailLevels, colliderLODIndex, transform, viewer, mapMaterial); - terrainChunkDictionary.Add (viewedChunkCoord, newChunk); - newChunk.onVisibilityChanged += OnTerrainChunkVisibilityChanged; - newChunk.Load (); + AddNewChunk (viewedChunkCoord); } } @@ -82,6 +84,51 @@ void UpdateVisibleChunks() { } } + void AddNewChunk(Vector2 viewedChunkCoord) + { + FalloffGenerator.FallOffType fallOffType = FalloffGenerator.FallOffType.None; + if (Mathf.Abs(viewedChunkCoord.x) > mapSizeInChunks.x + 1 || Mathf.Abs(viewedChunkCoord.y) > mapSizeInChunks.y + 1) { + fallOffType = FalloffGenerator.FallOffType.Ocean; + } + else if (viewedChunkCoord.x == mapSizeInChunks.x + 1) + { + if (viewedChunkCoord.y == mapSizeInChunks.y + 1) + { + fallOffType = FalloffGenerator.FallOffType.NECoast; + } + else if (viewedChunkCoord.y == -mapSizeInChunks.y - 1) + { + fallOffType = FalloffGenerator.FallOffType.SECoast; + } + else fallOffType = FalloffGenerator.FallOffType.EastCoast; + } + else if (viewedChunkCoord.x == -mapSizeInChunks.x - 1) + { + if (viewedChunkCoord.y == -mapSizeInChunks.y - 1) + { + fallOffType = FalloffGenerator.FallOffType.SWCoast; + } + else if (viewedChunkCoord.y == mapSizeInChunks.y + 1) + { + fallOffType = FalloffGenerator.FallOffType.NWCoast; + } + else fallOffType = FalloffGenerator.FallOffType.WestCoast; + } + else if (viewedChunkCoord.y == mapSizeInChunks.y + 1) + { + fallOffType = FalloffGenerator.FallOffType.NorthCoast; + } + else if (viewedChunkCoord.y == -mapSizeInChunks.y - 1) + { + fallOffType = FalloffGenerator.FallOffType.SouthCoast; + } + + TerrainChunk newChunk = new TerrainChunk(viewedChunkCoord, fallOffType, heightMapSettings, meshSettings, detailLevels, colliderLODIndex, transform, viewer, mapMaterial); + terrainChunkDictionary.Add(viewedChunkCoord, newChunk); + newChunk.onVisibilityChanged += OnTerrainChunkVisibilityChanged; + newChunk.Load(); + } + void OnTerrainChunkVisibilityChanged(TerrainChunk chunk, bool isVisible) { if (isVisible) { visibleTerrainChunks.Add (chunk); diff --git a/Proc Gen E21/Assets/Scripts/TerrainGenerator.cs.meta b/Proc Gen E21/Assets/Scripts/TerrainGenerator.cs.meta index 3d3a0368..a2e629ba 100644 --- a/Proc Gen E21/Assets/Scripts/TerrainGenerator.cs.meta +++ b/Proc Gen E21/Assets/Scripts/TerrainGenerator.cs.meta @@ -1,8 +1,7 @@ fileFormatVersion: 2 -guid: d5ed9d55d767f47ef80b94009415a728 -timeCreated: 1496400584 -licenseType: Pro +guid: 57442ab225c17dd4a88aa819c7eabfcd MonoImporter: + externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 diff --git a/Proc Gen E21/Assets/Scripts/TextureGenerator.cs.meta b/Proc Gen E21/Assets/Scripts/TextureGenerator.cs.meta index 640b5732..2fbb3d3f 100644 --- a/Proc Gen E21/Assets/Scripts/TextureGenerator.cs.meta +++ b/Proc Gen E21/Assets/Scripts/TextureGenerator.cs.meta @@ -1,8 +1,7 @@ fileFormatVersion: 2 -guid: df7acc444474841759c3b95c7ef6d1c3 -timeCreated: 1455354562 -licenseType: Pro +guid: a7913482082b14d4f8e9a8c90d45383e MonoImporter: + externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 diff --git a/Proc Gen E21/Assets/Scripts/ThreadedDataRequester.cs.meta b/Proc Gen E21/Assets/Scripts/ThreadedDataRequester.cs.meta index d9731d90..31a20c4c 100644 --- a/Proc Gen E21/Assets/Scripts/ThreadedDataRequester.cs.meta +++ b/Proc Gen E21/Assets/Scripts/ThreadedDataRequester.cs.meta @@ -1,8 +1,7 @@ fileFormatVersion: 2 -guid: 60765b39c6679414382a47b20bd4a882 -timeCreated: 1496347821 -licenseType: Pro +guid: 200339e620072e84999fd89476b90d1d MonoImporter: + externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 diff --git a/Proc Gen E21/Assets/Standard Assets.meta b/Proc Gen E21/Assets/Standard Assets.meta index 51c8abf6..64eb7961 100644 --- a/Proc Gen E21/Assets/Standard Assets.meta +++ b/Proc Gen E21/Assets/Standard Assets.meta @@ -1,9 +1,8 @@ fileFormatVersion: 2 -guid: 8986dafbf31c843e3aafd358e0b15ea6 +guid: e0c0246dbb7f3214b915fb01af9fd4cc folderAsset: yes -timeCreated: 1472545971 -licenseType: Pro DefaultImporter: + externalObjects: {} userData: assetBundleName: assetBundleVariant: diff --git a/Proc Gen E21/Assets/Terrain Assets.meta b/Proc Gen E21/Assets/Terrain Assets.meta index 3231846a..57f2956a 100644 --- a/Proc Gen E21/Assets/Terrain Assets.meta +++ b/Proc Gen E21/Assets/Terrain Assets.meta @@ -1,9 +1,8 @@ fileFormatVersion: 2 -guid: daeb5cd6cdf2548318158d5d689f6fe4 +guid: 4efdbb173820b0144aa1c8fc64bfe1b5 folderAsset: yes -timeCreated: 1474629056 -licenseType: Pro DefaultImporter: + externalObjects: {} userData: assetBundleName: assetBundleVariant: diff --git a/Proc Gen E21/Assets/Terrain Assets/Boulders.asset b/Proc Gen E21/Assets/Terrain Assets/Boulders.asset new file mode 100644 index 00000000..43f3a6ad --- /dev/null +++ b/Proc Gen E21/Assets/Terrain Assets/Boulders.asset @@ -0,0 +1,46 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d7b5971f7324f7d4aab07cfd82eba195, type: 3} + m_Name: Boulders + m_EditorClassIdentifier: + autoUpdate: 1 + normalizeMode: 0 + scale: 200 + octaves: 4 + persistance: 0.274 + lacunarity: 3.3 + seed: 4 + offset: {x: 0, y: 0} + noiseCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 1 + outSlope: 1 + tangentMode: 34 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + - serializedVersion: 3 + time: 1 + value: 1 + inSlope: 1 + outSlope: 1 + tangentMode: 34 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 diff --git a/Proc Gen E21/Assets/Terrain Assets/Boulders.asset.meta b/Proc Gen E21/Assets/Terrain Assets/Boulders.asset.meta new file mode 100644 index 00000000..5e008ff2 --- /dev/null +++ b/Proc Gen E21/Assets/Terrain Assets/Boulders.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5781622e03fbcd743a22b972001ca59b +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Proc Gen E21/Assets/Terrain Assets/Continentalness.asset b/Proc Gen E21/Assets/Terrain Assets/Continentalness.asset new file mode 100644 index 00000000..e42bce20 --- /dev/null +++ b/Proc Gen E21/Assets/Terrain Assets/Continentalness.asset @@ -0,0 +1,82 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d7b5971f7324f7d4aab07cfd82eba195, type: 3} + m_Name: Continentalness + m_EditorClassIdentifier: + autoUpdate: 1 + normalizeMode: 0 + scale: 1000 + octaves: 8 + persistance: 0.643 + lacunarity: 1.67 + seed: 35 + offset: {x: 0, y: 0} + noiseCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0.0000009885989 + value: -0.0000056428835 + inSlope: 0.46389836 + outSlope: 0.46389836 + tangentMode: 34 + weightedMode: 0 + inWeight: 0 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 0.32466966 + value: 0.15060762 + inSlope: 0.7468403 + outSlope: 0.7468403 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.23043479 + outWeight: 0.43550107 + - serializedVersion: 3 + time: 0.46252146 + value: 0.2944386 + inSlope: 0.9049326 + outSlope: 0.9049326 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 0.5610932 + value: 0.3952402 + inSlope: 0.80236745 + outSlope: 0.80236745 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 0.70817214 + value: 0.57024765 + inSlope: 1.1693232 + outSlope: 1.1693232 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.061494906 + outWeight: 0.1511484 + - serializedVersion: 3 + time: 1 + value: 0.7452847 + inSlope: 0.59979546 + outSlope: 0.59979546 + tangentMode: 34 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 diff --git a/Proc Gen E21/Assets/Terrain Assets/Continentalness.asset.meta b/Proc Gen E21/Assets/Terrain Assets/Continentalness.asset.meta new file mode 100644 index 00000000..2be63466 --- /dev/null +++ b/Proc Gen E21/Assets/Terrain Assets/Continentalness.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 22cd561dd60059644930c4219aa774e1 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Proc Gen E21/Assets/Terrain Assets/Default Texture.asset b/Proc Gen E21/Assets/Terrain Assets/Default Texture.asset index b291a00a5c7ea1f50aa3c1c4163a51af57fc6fd4..f3ce2036b61e95d51b88a5c101180e9eaf4211e9 100644 GIT binary patch literal 1789 zcmb7^OK;RL5P_gie zq9h(W^ZA?c+1HEv4+ILBoIPCJkTF209PQ&6S(0B> zy@+>LIr8^9^m7+0>+YI9*~Z61;}?A&)9&DneLA@Cbz|KkhLXVgKi8p7ZMT!@%y;#2 zdu0Hzrk#@cs?M`36Tw48D+wZKgV9CjxRMnLXQcO2lAf12Z$9FD%o&yBDl@GXi9E!g zY1PH81TGi0@9#ovQeD-tD@h)+tJHp32AlHCA=!m}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PcOEdMRO_P#)V;{J zQruJ!L240PyAToFxGlI65nQOaa^tG;|L5L>$=>B0n9R&KXZ|_)hr1Y&^lOoxiiq^0 zM<+6n9mt-Y%E@N4*;ERkZm{(9{#bteYJDTMJiRhJKl3p2dE(pL$EA_A@4w!y^j~;+ z0%;){w{$6q&Wl8lXqw#-xsn%YiQZssOOnT2a>fSuZuBX%n5X0mG!9|T{Itch&^d|u z_GGQ4^C%_JheT(qm2c~8v$(C()#gghLFYlD!!w4>T4y~wEN<)UY;z^6sPis#Sl=#c zK&a)zHE{kf{^wTxKFhnIa)o@$?aGS@z zoi=lkBj|Yn^z9jH$zjSmkCG$ES5f;VGZr~UnB>#9>zFdXj~u~#@;exlA16c<3Ss@? zXsI05>Z1#xt_I~=bx>ySjg>2U{4xdwFZ40+8e#4BT*(Wy%<8}|PI?tBjX;l8ys+qd zrE>MYO!|%LOtHMA$Ezj1AX8Whu%t^PoeT6e|7YEt&mVq>405)wi}*Z~u?&40eERm( zl`~Hk|K^^*-~7!F!i96dIp7>{4mby#1I_{GfOEh(;2ikR4)86)u-_znKi<^ynHzWn WWr{is@$d;uR-A_?))1$yXUae8grZCU diff --git a/Proc Gen E21/Assets/Terrain Assets/PeaksValleys.asset b/Proc Gen E21/Assets/Terrain Assets/PeaksValleys.asset new file mode 100644 index 00000000..88f3070d --- /dev/null +++ b/Proc Gen E21/Assets/Terrain Assets/PeaksValleys.asset @@ -0,0 +1,64 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d7b5971f7324f7d4aab07cfd82eba195, type: 3} + m_Name: PeaksValleys + m_EditorClassIdentifier: + autoUpdate: 1 + normalizeMode: 0 + scale: 400 + octaves: 3 + persistance: 0.421 + lacunarity: 2 + seed: 36 + offset: {x: 0, y: 0} + noiseCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0.659474 + outSlope: 0.659474 + tangentMode: 34 + weightedMode: 0 + inWeight: 0 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 0.30336022 + value: 0.20005819 + inSlope: 0.19474226 + outSlope: 0.19474226 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.107889645 + outWeight: 0.14676993 + - serializedVersion: 3 + time: 0.7442426 + value: 0.6923793 + inSlope: 2.8794458 + outSlope: 2.8794458 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.087401435 + outWeight: 0.10145652 + - serializedVersion: 3 + time: 1 + value: 1 + inSlope: 1.2027832 + outSlope: 1.2027832 + tangentMode: 34 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 diff --git a/Proc Gen E21/Assets/Terrain Assets/PeaksValleys.asset.meta b/Proc Gen E21/Assets/Terrain Assets/PeaksValleys.asset.meta new file mode 100644 index 00000000..eb240dc5 --- /dev/null +++ b/Proc Gen E21/Assets/Terrain Assets/PeaksValleys.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 46cf976dc211b08469f46ad77321fd51 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Proc Gen E21/Assets/Textures.meta b/Proc Gen E21/Assets/Textures.meta index 63796c35..95b348f5 100644 --- a/Proc Gen E21/Assets/Textures.meta +++ b/Proc Gen E21/Assets/Textures.meta @@ -1,9 +1,8 @@ fileFormatVersion: 2 -guid: 5b57d2ec6090348c0b8ff616d3100cea +guid: cb7cd0301387989429a78abc865783b1 folderAsset: yes -timeCreated: 1481997553 -licenseType: Pro DefaultImporter: + externalObjects: {} userData: assetBundleName: assetBundleVariant: From 30b4cd785215dbd436874e0bc8d95739569f6a5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomislav=20Reki=C4=87?= <44620759+tomislavrekic@users.noreply.github.com> Date: Fri, 12 Jan 2024 09:20:34 +0100 Subject: [PATCH 2/2] Some formatting --- .../Assets/Scripts/Data/HeightMapSettings.cs | 3 +- .../Assets/Scripts/Data/NoiseSettings.cs | 48 ++++---- .../Assets/Scripts/FalloffGenerator.cs | 109 +++++++++--------- .../Assets/Scripts/HeightMapGenerator.cs | 29 +++-- Proc Gen E21/Assets/Scripts/MapPreview.cs | 8 +- Proc Gen E21/Assets/Scripts/Noise.cs | 2 +- Proc Gen E21/Assets/Scripts/TerrainChunk.cs | 2 +- .../Assets/Scripts/TerrainGenerator.cs | 74 ++++++------ 8 files changed, 133 insertions(+), 142 deletions(-) diff --git a/Proc Gen E21/Assets/Scripts/Data/HeightMapSettings.cs b/Proc Gen E21/Assets/Scripts/Data/HeightMapSettings.cs index de78bc71..0adb76c4 100644 --- a/Proc Gen E21/Assets/Scripts/Data/HeightMapSettings.cs +++ b/Proc Gen E21/Assets/Scripts/Data/HeightMapSettings.cs @@ -1,6 +1,5 @@ using UnityEngine; using System.Collections; -using UnityEngine.UIElements; [CreateAssetMenu()] public class HeightMapSettings : UpdatableData { @@ -11,7 +10,7 @@ public class HeightMapSettings : UpdatableData { public float fallOffIntensity; public AnimationCurve heightCurve; - public float minHeight { + public float minHeight { get { return heightMultiplier * heightCurve.Evaluate (0); } diff --git a/Proc Gen E21/Assets/Scripts/Data/NoiseSettings.cs b/Proc Gen E21/Assets/Scripts/Data/NoiseSettings.cs index 3152a748..80411dcd 100644 --- a/Proc Gen E21/Assets/Scripts/Data/NoiseSettings.cs +++ b/Proc Gen E21/Assets/Scripts/Data/NoiseSettings.cs @@ -4,37 +4,37 @@ [CreateAssetMenu()] public class NoiseSettings : UpdatableData { - public Noise.NormalizeMode normalizeMode; + public Noise.NormalizeMode normalizeMode; - public float scale = 50; + public float scale = 50; - [Range(1, 20)] - public int octaves = 6; - [Range(0, 1)] - public float persistance = .6f; - [Range(1, 20)] - public float lacunarity = 2; + [Range(1, 20)] + public int octaves = 6; + [Range(0, 1)] + public float persistance = .6f; + [Range(1, 20)] + public float lacunarity = 2; - public int seed; - public Vector2 offset; + public int seed; + public Vector2 offset; - public AnimationCurve noiseCurve; + public AnimationCurve noiseCurve; #if UNITY_EDITOR - protected override void OnValidate() - { - ValidateValues(); - base.OnValidate(); - } - - public void ValidateValues() - { - scale = Mathf.Max(scale, 0.01f); - octaves = Mathf.Max(octaves, 1); - lacunarity = Mathf.Max(lacunarity, 1); - persistance = Mathf.Clamp01(persistance); - } + protected override void OnValidate() + { + ValidateValues(); + base.OnValidate(); + } + + public void ValidateValues() + { + scale = Mathf.Max(scale, 0.01f); + octaves = Mathf.Max(octaves, 1); + lacunarity = Mathf.Max(lacunarity, 1); + persistance = Mathf.Clamp01(persistance); + } #endif diff --git a/Proc Gen E21/Assets/Scripts/FalloffGenerator.cs b/Proc Gen E21/Assets/Scripts/FalloffGenerator.cs index a7b8924c..b20d4e01 100644 --- a/Proc Gen E21/Assets/Scripts/FalloffGenerator.cs +++ b/Proc Gen E21/Assets/Scripts/FalloffGenerator.cs @@ -1,24 +1,23 @@ using UnityEngine; using System.Collections; - public static class FalloffGenerator { - public enum FallOffType { None, Ocean, WestCoast, EastCoast, NorthCoast, SouthCoast, NWCoast, NECoast, SWCoast, SECoast } + public enum FallOffType { None, Ocean, WestCoast, EastCoast, NorthCoast, SouthCoast, NWCoast, NECoast, SWCoast, SECoast } public static float[,] GenerateFalloffMap(int size, FallOffType falloffType, float intensity) { float[,] map = new float[size,size]; if (falloffType == FallOffType.None) { - for (int i = 0; i < size; i++) - { - for (int j = 0; j < size; j++) - { + for (int i = 0; i < size; i++) + { + for (int j = 0; j < size; j++) + { map[i, j] = 1; - } - } - return map; - } + } + } + return map; + } if (falloffType == FallOffType.Ocean) { @@ -27,13 +26,13 @@ public enum FallOffType { None, Ocean, WestCoast, EastCoast, NorthCoast, SouthCo for (int j = 0; j < size; j++) { map[i, j] = 1 - intensity; - } + } } return map; } - for (int i = 0; i < size; i++) { + for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { float x = i / ((float)size-1); float y = j / ((float)size-1); @@ -46,62 +45,62 @@ public enum FallOffType { None, Ocean, WestCoast, EastCoast, NorthCoast, SouthCo else if (falloffType == FallOffType.EastCoast) { //x = x; - y = 0; - } - if (falloffType == FallOffType.NorthCoast) - { - y = 1-y; + y = 0; + } + if (falloffType == FallOffType.NorthCoast) + { + y = 1-y; x = 0; - } - else if (falloffType == FallOffType.SouthCoast) - { - //y = y; + } + else if (falloffType == FallOffType.SouthCoast) + { + //y = y; x = 0; - } + } else if (falloffType == FallOffType.NWCoast) { x = 1-x; y = 1-y; } - else if (falloffType == FallOffType.NECoast) - { - //x = x; - y = 1 - y; - } - else if (falloffType == FallOffType.SWCoast) - { - x = 1 - x; - //y = y; - } - else if (falloffType == FallOffType.SECoast) - { - //x = x; - //y = y; - } + else if (falloffType == FallOffType.NECoast) + { + //x = x; + y = 1 - y; + } + else if (falloffType == FallOffType.SWCoast) + { + x = 1 - x; + //y = y; + } + else if (falloffType == FallOffType.SECoast) + { + //x = x; + //y = y; + } - float valueX = SmoothStep(0, 1, x); + float valueX = SmoothStep(0, 1, x); float valueY = SmoothStep(0, 1, y); - map [i, j] = Mathf.Max(valueX, valueY) * intensity; - map[i, j] = 1 - map[i, j]; + map [i, j] = Mathf.Max(valueX, valueY) * intensity; + map[i, j] = 1 - map[i, j]; - } + } } - return map; + return map; + } + //https://en.wikipedia.org/wiki/Smoothstep + static float SmoothStep(float edge0, float edge1, float x) + { + // Scale, and clamp x to 0..1 range + x = clamp((x-edge0) / (edge1-edge0)); + return x * x * (3.0f - 2.0f * x); } - //https://en.wikipedia.org/wiki/Smoothstep - static float SmoothStep(float edge0, float edge1, float x) - { - // Scale, and clamp x to 0..1 range - x = clamp((x-edge0) / (edge1-edge0)); - return x * x * (3.0f - 2.0f * x); - } - static float clamp(float x, float lowerlimit = 0.0f, float upperlimit = 1.0f) - { - if (x < lowerlimit) return lowerlimit; - if (x > upperlimit) return upperlimit; - return x; - } + static float clamp(float x, float lowerlimit = 0.0f, float upperlimit = 1.0f) + { + if (x < lowerlimit) return lowerlimit; + if (x > upperlimit) return upperlimit; + return x; + } } diff --git a/Proc Gen E21/Assets/Scripts/HeightMapGenerator.cs b/Proc Gen E21/Assets/Scripts/HeightMapGenerator.cs index 4c9bc651..a02b13f4 100644 --- a/Proc Gen E21/Assets/Scripts/HeightMapGenerator.cs +++ b/Proc Gen E21/Assets/Scripts/HeightMapGenerator.cs @@ -1,19 +1,18 @@ using System.Collections; using System.Collections.Generic; -using System.Linq; using UnityEngine; public static class HeightMapGenerator { public static HeightMap GenerateHeightMap(int width, int height, FalloffGenerator.FallOffType fallOffType, HeightMapSettings heightMapSettings, Vector2 sampleCentre) { float[,,] noiseLayers = new float[heightMapSettings.noiseLayers.Length, width, height]; - float[,] falloffMap = FalloffGenerator.GenerateFalloffMap(width, fallOffType, heightMapSettings.fallOffIntensity); - for (int k = 0; k < heightMapSettings.noiseLayers.Length; k++) + float[,] falloffMap = FalloffGenerator.GenerateFalloffMap(width, fallOffType, heightMapSettings.fallOffIntensity); + for (int k = 0; k < heightMapSettings.noiseLayers.Length; k++) { - AnimationCurve noiseCurve_threadsafe = new AnimationCurve(heightMapSettings.noiseLayers[k].noiseSettings.noiseCurve.keys); + AnimationCurve noiseCurve_threadsafe = new AnimationCurve(heightMapSettings.noiseLayers[k].noiseSettings.noiseCurve.keys); float[,] values = Noise.GenerateNoiseMap(width, height, heightMapSettings.noiseLayers[k].noiseSettings, sampleCentre); - for (int i = 0; i < width; i++) + for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { @@ -22,13 +21,13 @@ public static HeightMap GenerateHeightMap(int width, int height, FalloffGenerato } } - float minValue = float.MaxValue; + float minValue = float.MaxValue; float maxValue = float.MinValue; - AnimationCurve heightCurve_threadsafe = new AnimationCurve(heightMapSettings.heightCurve.keys); + AnimationCurve heightCurve_threadsafe = new AnimationCurve(heightMapSettings.heightCurve.keys); - float[,] heightFinalValues = new float[width, height]; - for (int i = 0; i < width; i++) - { + float[,] heightFinalValues = new float[width, height]; + for (int i = 0; i < width; i++) + { for (int j = 0; j < height; j++) { float noiseSum = 0; @@ -37,20 +36,20 @@ public static HeightMap GenerateHeightMap(int width, int height, FalloffGenerato { noiseSum += noiseLayers[k, i, j] * heightMapSettings.noiseLayers[k].strength; maxPossibleVal += heightMapSettings.noiseLayers[k].strength; - } + } - heightFinalValues[i,j] = heightCurve_threadsafe.Evaluate((noiseSum / maxPossibleVal) * falloffMap[i, j]) * heightMapSettings.heightMultiplier; + heightFinalValues[i,j] = heightCurve_threadsafe.Evaluate((noiseSum / maxPossibleVal) * falloffMap[i, j]) * heightMapSettings.heightMultiplier; - if (heightFinalValues[i, j] > maxValue) { + if (heightFinalValues[i, j] > maxValue) { maxValue = heightFinalValues[i, j]; } if (heightFinalValues[i, j] < minValue) { minValue = heightFinalValues[i, j]; } } - } + } - return new HeightMap (heightFinalValues, minValue, maxValue); + return new HeightMap (heightFinalValues, minValue, maxValue); } } diff --git a/Proc Gen E21/Assets/Scripts/MapPreview.cs b/Proc Gen E21/Assets/Scripts/MapPreview.cs index 74b2c34e..3a09c45f 100644 --- a/Proc Gen E21/Assets/Scripts/MapPreview.cs +++ b/Proc Gen E21/Assets/Scripts/MapPreview.cs @@ -7,7 +7,6 @@ public class MapPreview : MonoBehaviour { public MeshFilter meshFilter; public MeshRenderer meshRenderer; - public enum DrawMode {NoiseMap, Mesh, FalloffMap}; public DrawMode drawMode; @@ -23,15 +22,10 @@ public enum DrawMode {NoiseMap, Mesh, FalloffMap}; public NoiseSettings[] noiseSettingsListener; - - [Range(0,MeshSettings.numSupportedLODs-1)] public int editorPreviewLOD; public bool autoUpdate; - - - public void DrawMapInEditor() { textureData.ApplyToMaterial (terrainMaterial); textureData.UpdateMeshHeights (terrainMaterial, heightMapSettings.minHeight, heightMapSettings.maxHeight); @@ -85,7 +79,7 @@ void OnValidate() { { noiseSettingsListener[i].OnValuesUpdated -= OnValuesUpdated; noiseSettingsListener[i].OnValuesUpdated += OnValuesUpdated; - } + } } if (meshSettings != null) { diff --git a/Proc Gen E21/Assets/Scripts/Noise.cs b/Proc Gen E21/Assets/Scripts/Noise.cs index d8830579..999ed68a 100644 --- a/Proc Gen E21/Assets/Scripts/Noise.cs +++ b/Proc Gen E21/Assets/Scripts/Noise.cs @@ -54,7 +54,7 @@ public enum NormalizeMode {Global}; } } - return noiseMap; + return noiseMap; } } diff --git a/Proc Gen E21/Assets/Scripts/TerrainChunk.cs b/Proc Gen E21/Assets/Scripts/TerrainChunk.cs index 5aeff1f1..2e17a28d 100644 --- a/Proc Gen E21/Assets/Scripts/TerrainChunk.cs +++ b/Proc Gen E21/Assets/Scripts/TerrainChunk.cs @@ -30,7 +30,7 @@ public class TerrainChunk { FalloffGenerator.FallOffType fallOffType; - public TerrainChunk(Vector2 coord, FalloffGenerator.FallOffType fallOffType, HeightMapSettings heightMapSettings, MeshSettings meshSettings, LODInfo[] detailLevels, int colliderLODIndex, Transform parent, Transform viewer, Material material) { + public TerrainChunk(Vector2 coord, FalloffGenerator.FallOffType fallOffType, HeightMapSettings heightMapSettings, MeshSettings meshSettings, LODInfo[] detailLevels, int colliderLODIndex, Transform parent, Transform viewer, Material material) { this.coord = coord; this.detailLevels = detailLevels; this.colliderLODIndex = colliderLODIndex; diff --git a/Proc Gen E21/Assets/Scripts/TerrainGenerator.cs b/Proc Gen E21/Assets/Scripts/TerrainGenerator.cs index 28bd7ce0..a261af26 100644 --- a/Proc Gen E21/Assets/Scripts/TerrainGenerator.cs +++ b/Proc Gen E21/Assets/Scripts/TerrainGenerator.cs @@ -13,7 +13,7 @@ public class TerrainGenerator : MonoBehaviour { public MeshSettings meshSettings; public HeightMapSettings heightMapSettings; - public TextureData textureSettings; + public TextureData textureSettings; public Transform viewer; public Material mapMaterial; @@ -88,46 +88,46 @@ void AddNewChunk(Vector2 viewedChunkCoord) { FalloffGenerator.FallOffType fallOffType = FalloffGenerator.FallOffType.None; if (Mathf.Abs(viewedChunkCoord.x) > mapSizeInChunks.x + 1 || Mathf.Abs(viewedChunkCoord.y) > mapSizeInChunks.y + 1) { - fallOffType = FalloffGenerator.FallOffType.Ocean; - } - else if (viewedChunkCoord.x == mapSizeInChunks.x + 1) + fallOffType = FalloffGenerator.FallOffType.Ocean; + } + else if (viewedChunkCoord.x == mapSizeInChunks.x + 1) { if (viewedChunkCoord.y == mapSizeInChunks.y + 1) { - fallOffType = FalloffGenerator.FallOffType.NECoast; - } - else if (viewedChunkCoord.y == -mapSizeInChunks.y - 1) - { - fallOffType = FalloffGenerator.FallOffType.SECoast; - } - else fallOffType = FalloffGenerator.FallOffType.EastCoast; + fallOffType = FalloffGenerator.FallOffType.NECoast; + } + else if (viewedChunkCoord.y == -mapSizeInChunks.y - 1) + { + fallOffType = FalloffGenerator.FallOffType.SECoast; + } + else fallOffType = FalloffGenerator.FallOffType.EastCoast; + } + else if (viewedChunkCoord.x == -mapSizeInChunks.x - 1) + { + if (viewedChunkCoord.y == -mapSizeInChunks.y - 1) + { + fallOffType = FalloffGenerator.FallOffType.SWCoast; + } + else if (viewedChunkCoord.y == mapSizeInChunks.y + 1) + { + fallOffType = FalloffGenerator.FallOffType.NWCoast; + } + else fallOffType = FalloffGenerator.FallOffType.WestCoast; + } + else if (viewedChunkCoord.y == mapSizeInChunks.y + 1) + { + fallOffType = FalloffGenerator.FallOffType.NorthCoast; } - else if (viewedChunkCoord.x == -mapSizeInChunks.x - 1) - { - if (viewedChunkCoord.y == -mapSizeInChunks.y - 1) - { - fallOffType = FalloffGenerator.FallOffType.SWCoast; - } - else if (viewedChunkCoord.y == mapSizeInChunks.y + 1) - { - fallOffType = FalloffGenerator.FallOffType.NWCoast; - } - else fallOffType = FalloffGenerator.FallOffType.WestCoast; - } - else if (viewedChunkCoord.y == mapSizeInChunks.y + 1) - { - fallOffType = FalloffGenerator.FallOffType.NorthCoast; - } - else if (viewedChunkCoord.y == -mapSizeInChunks.y - 1) - { - fallOffType = FalloffGenerator.FallOffType.SouthCoast; - } - - TerrainChunk newChunk = new TerrainChunk(viewedChunkCoord, fallOffType, heightMapSettings, meshSettings, detailLevels, colliderLODIndex, transform, viewer, mapMaterial); - terrainChunkDictionary.Add(viewedChunkCoord, newChunk); - newChunk.onVisibilityChanged += OnTerrainChunkVisibilityChanged; - newChunk.Load(); - } + else if (viewedChunkCoord.y == -mapSizeInChunks.y - 1) + { + fallOffType = FalloffGenerator.FallOffType.SouthCoast; + } + + TerrainChunk newChunk = new TerrainChunk(viewedChunkCoord, fallOffType, heightMapSettings, meshSettings, detailLevels, colliderLODIndex, transform, viewer, mapMaterial); + terrainChunkDictionary.Add(viewedChunkCoord, newChunk); + newChunk.onVisibilityChanged += OnTerrainChunkVisibilityChanged; + newChunk.Load(); + } void OnTerrainChunkVisibilityChanged(TerrainChunk chunk, bool isVisible) { if (isVisible) {