Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Proc Gen E21/Assets/Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Proc Gen E21/Assets/Materials.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Proc Gen E21/Assets/Materials/Map Mat.mat
Binary file not shown.
6 changes: 3 additions & 3 deletions Proc Gen E21/Assets/Materials/Map Mat.mat.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Proc Gen E21/Assets/Materials/Mesh Mat.mat
Binary file not shown.
6 changes: 3 additions & 3 deletions Proc Gen E21/Assets/Materials/Mesh Mat.mat.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Proc Gen E21/Assets/Scenes.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Proc Gen E21/Assets/Scripts.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Proc Gen E21/Assets/Scripts/Data.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 11 additions & 12 deletions Proc Gen E21/Assets/Scripts/Data/HeightMapSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
[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 {
Expand All @@ -22,13 +21,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;
}
5 changes: 2 additions & 3 deletions Proc Gen E21/Assets/Scripts/Data/HeightMapSettings.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Proc Gen E21/Assets/Scripts/Data/MeshSettings.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions Proc Gen E21/Assets/Scripts/Data/NoiseSettings.cs
Original file line number Diff line number Diff line change
@@ -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


}
11 changes: 11 additions & 0 deletions Proc Gen E21/Assets/Scripts/Data/NoiseSettings.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Proc Gen E21/Assets/Scripts/Data/TextureData.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Proc Gen E21/Assets/Scripts/Data/UpdatableData.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

100 changes: 89 additions & 11 deletions Proc Gen E21/Assets/Scripts/FalloffGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,104 @@

public static class FalloffGenerator {

public static float[,] GenerateFalloffMap(int size) {
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++)
{
map[i, j] = 1;
}
}
return map;
}

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;
}


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;
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];

float value = Mathf.Max (Mathf.Abs (x), Mathf.Abs (y));
map [i, j] = Evaluate(value);
}
}

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 Evaluate(float value) {
float a = 3;
float b = 2.2f;

return Mathf.Pow (value, a) / (Mathf.Pow (value, a) + Mathf.Pow (b - b * value, a));
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;
}

}
5 changes: 2 additions & 3 deletions Proc Gen E21/Assets/Scripts/FalloffGenerator.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading