Skip to content
Snippets Groups Projects
Commit cd4fa925 authored by Ryan Chang's avatar Ryan Chang
Browse files

Biomes reseeding

parent 507594ab
No related branches found
No related tags found
No related merge requests found
......@@ -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
......@@ -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>
......
......@@ -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
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]
......
......@@ -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();
}
}
......
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment