diff --git a/Assets/Scenes/Biomes.unity b/Assets/Scenes/Biomes.unity index e0884ec9b75454f5b31ea0425a611431500a87da..7bf2f91498d0927ccb62d0216bf702bb2605b55c 100644 --- a/Assets/Scenes/Biomes.unity +++ b/Assets/Scenes/Biomes.unity @@ -38,7 +38,7 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 0} - m_IndirectSpecularColor: {r: 0.18028378, g: 0.22571412, b: 0.30692285, a: 1} + m_IndirectSpecularColor: {r: 0.18029127, g: 0.22572401, b: 0.3069303, a: 1} m_UseRadianceAmbientProbe: 0 --- !u!157 &3 LightmapSettings: @@ -350,20 +350,28 @@ MonoBehaviour: map: - amplitude: 10 frequency: 0.02 - type: 0 + type: 1 + offset: {x: 135.04135, y: -207.50754} + shapeMap: [] + terrainMap: [] debugColor: {r: 1, g: 0, b: 0, a: 0} - name: Rainfall map: - amplitude: 10 frequency: 0.1 - type: 0 + type: 1 + offset: {x: -97.412056, y: -248.15933} + shapeMap: [] + terrainMap: [] debugColor: {r: 0, g: 0.8982549, b: 1, a: 0} - name: Magic map: - - amplitude: 1 + - amplitude: 10 frequency: 0.01 type: 1 + offset: {x: 71.88173, y: -15.729124} + shapeMap: [] + terrainMap: [] debugColor: {r: 0.6406398, g: 0, b: 1, a: 1} - updateDebug: 0 - debugSize: 100 - debugFrequency: 9.7 + debugSize: 10 + debugFrequency: 5 diff --git a/Assets/Scripts/Helpers/RNG.cs b/Assets/Scripts/Helpers/RNG.cs index a4ec9a84ca0d7768edd4e749d3dfc4e91f0405e7..07a96cd4bd244079e3da8add5266e310b73132aa 100644 --- a/Assets/Scripts/Helpers/RNG.cs +++ b/Assets/Scripts/Helpers/RNG.cs @@ -99,8 +99,7 @@ public static class RNG } /// <summary> - /// Returns a Vector2 with both components ranging from - /// -val to val + /// Returns a Vector2 with both components ranging from -val to val /// </summary> /// <param name="val"></param> /// <returns></returns> @@ -110,8 +109,7 @@ public static class RNG } /// <summary> - /// Returns a Vector2 with both components ranging from - /// minVal to maxVal + /// Returns a Vector2 with both components ranging from minVal to maxVal /// </summary> /// <param name="val"></param> /// <returns></returns> diff --git a/Assets/Scripts/NewGeneration/Biome/BiomeMaster.cs b/Assets/Scripts/NewGeneration/Biome/BiomeMaster.cs index 30b52e383fa3353edbc1dd53645e5fba0362051d..319da8106825785e156297abc6ac790dfaa1166d 100644 --- a/Assets/Scripts/NewGeneration/Biome/BiomeMaster.cs +++ b/Assets/Scripts/NewGeneration/Biome/BiomeMaster.cs @@ -2,55 +2,47 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +using NaughtyAttributes; public class BiomeMaster : MonoBehaviour { + #region Variables public List<BiomeParameter> parameters; + #region Debug [Header("Debug")] - public bool updateDebug; - public int debugSize = 500; public float debugFrequency = 0.1f; + #endregion + #endregion - #region On Validate - private void OnValidate() + #region Buttons + [Button("Update Debug")] + private void UpdateDebug() { - if (updateDebug) + for (int i = -debugSize; i < debugSize; i++) { - updateDebug = false; - - for (int i = -debugSize; i < debugSize; i++) + for (int j = -debugSize; j < debugSize; j++) { - for (int j = -debugSize; j < debugSize; j++) - { - float x = i * debugFrequency; - float y = j * debugFrequency; - float h = 0; - Color colorBlend = new(); - - foreach (var parameter in parameters) - { - foreach (var octave in parameter.map) - { - float strength = octave.Calculate(new(x, y)); - h += strength; - - if (octave.amplitude > 0) - colorBlend += parameter.debugColor * (strength / octave.amplitude) - / parameters.Count; - } - } - - colorBlend.a = 1; + float x = i * debugFrequency; + float y = j * debugFrequency; - Vector3 start = new(x, 0, y); - Vector3 end = new(x, h, y); - Debug.DrawLine(start, end, colorBlend, 10); + foreach (var param in parameters) + { + param.DrawDebug(x, y); } } } } + + [Button("Reseed Octaves")] + private void ReseedParameters() + { + foreach (var param in parameters) + { + param.ReseedOctaves(); + } + } #endregion } \ No newline at end of file diff --git a/Assets/Scripts/NewGeneration/Biome/BiomeParameter.cs b/Assets/Scripts/NewGeneration/Biome/BiomeParameter.cs index 9f037e56b76d56ed721a0ee2b1d78d970caa84f3..550373d9dbf241feaf444696f1fae9cef3e64be5 100644 --- a/Assets/Scripts/NewGeneration/Biome/BiomeParameter.cs +++ b/Assets/Scripts/NewGeneration/Biome/BiomeParameter.cs @@ -1,19 +1,54 @@ using System.Collections; using System; +using System.Linq; using UnityEngine; using System.Collections.Generic; [Serializable] -public struct BiomeParameter +public class BiomeParameter { + public const int MAX_OCTAVE_OFFSET = 256; + public string name; [Tooltip("What is used to generate the biome.")] public List<Octave> map; [Tooltip("What is used to generate the terrain.")] public List<Octave> shapeMap; [Tooltip("What is used to map terrain materials to heights.")] - public List<TerrainHeightMap> heightMap; + public List<TerrainHeightMap> terrainMap; public Color debugColor; + + public void DrawDebug(float x, float y) + { + Vector3 start = new(x, 0, y); + Vector3 end = start + map.Sum(o => o.Calculate(new(x, y))) * Vector3.up; + Debug.DrawLine(start, end, debugColor, 10); + } + + /// <summary> + /// Reseeds the map and shapeMap octaves by randomizing their + /// offsets. + /// </summary> + public void ReseedOctaves() + { + map = ReseedOctave(map); + shapeMap = ReseedOctave(shapeMap); + } + + private List<Octave> ReseedOctave(List<Octave> octaves) + { + List<Octave> output = new(octaves.Count); + + foreach (var o in octaves) + { + Octave newOctave = new(o, RandomOffset()); + output.Add(newOctave); + } + + return output; + } + + private Vector2 RandomOffset() => RNG.GetRandomVector2(MAX_OCTAVE_OFFSET); } [Serializable] diff --git a/Assets/Scripts/TerrainGeneration/Chunker/TerrainChunker.cs b/Assets/Scripts/TerrainGeneration/Chunker/TerrainChunker.cs index 7f53024df02549f99c2a6ef845e12f306fc7cef6..13cbaaa48bff301d8c2488acec71ac5bbd4c6383 100644 --- a/Assets/Scripts/TerrainGeneration/Chunker/TerrainChunker.cs +++ b/Assets/Scripts/TerrainGeneration/Chunker/TerrainChunker.cs @@ -37,7 +37,7 @@ public abstract class TerrainChunker : MonoBehaviour protected float heightScale; - private bool initalGen = true; + private bool initialGen = true; private bool lookForCompletion = false; @@ -107,9 +107,9 @@ public abstract class TerrainChunker : MonoBehaviour ApplyTerrain(GetHeights()); lookForCompletion = false; - if (initalGen) + if (initialGen) { - initalGen = false; + initialGen = false; master.ChunkInitGenerate(); } } diff --git a/Assets/Scripts/TerrainGeneration/Octave.cs b/Assets/Scripts/TerrainGeneration/Octave.cs index 0f374fca6788f6d78d991eebb38c52fa44d78ce7..c89c0ab32cfd30e001b7ae8e1aeca23ce5278ffc 100644 --- a/Assets/Scripts/TerrainGeneration/Octave.cs +++ b/Assets/Scripts/TerrainGeneration/Octave.cs @@ -45,4 +45,29 @@ public struct Octave return addition * amplitude; } + + /// <summary> + /// Copies an octave. + /// </summary> + /// <param name="copy"></param> + public Octave(Octave copy) + { + amplitude = copy.amplitude; + frequency = copy.frequency; + type = copy.type; + offset = copy.offset; + } + + /// <summary> + /// Copies an octave, but changes the offset. + /// </summary> + /// <param name="copy"></param> + /// <param name="offset"></param> + public Octave(Octave copy, Vector2 offset) + { + amplitude = copy.amplitude; + frequency = copy.frequency; + type = copy.type; + this.offset = offset; + } } \ No newline at end of file