Skip to content

Commit

Permalink
noise changes
Browse files Browse the repository at this point in the history
  • Loading branch information
7ubi committed Jun 4, 2021
1 parent 8fc9e8a commit 22b61cd
Show file tree
Hide file tree
Showing 25 changed files with 2,654 additions and 1,512 deletions.
8 changes: 8 additions & 0 deletions Assets/Biomes.meta

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

29 changes: 29 additions & 0 deletions Assets/Biomes/Desert.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
%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: 56e72c31f97d0dc439a7bfd446a902f6, type: 3}
m_Name: Desert
m_EditorClassIdentifier:
name: Desert
scale: 90
octaves: 4
persistance: 0.6
lacunarity: 2
maxGeneratingHeight: 50
amplitude: 20
offset: {x: 149837, y: -27634}
topBlock: 7
secondaryBlock: 7
vegetationThreshold: 0.01
minVegetationHeight: 3
maxVegetationHeight: 8
hasTree: 0
hasCactus: 1
8 changes: 8 additions & 0 deletions Assets/Biomes/Desert.asset.meta

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

29 changes: 29 additions & 0 deletions Assets/Biomes/Forest.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
%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: 56e72c31f97d0dc439a7bfd446a902f6, type: 3}
m_Name: Forest
m_EditorClassIdentifier:
name: Forest
scale: 90
octaves: 4
persistance: 0.7
lacunarity: 2
maxGeneratingHeight: 70
amplitude: 30
offset: {x: 41124, y: 14231}
topBlock: 2
secondaryBlock: 1
vegetationThreshold: 0.064
minVegetationHeight: 3
maxVegetationHeight: 6
hasTree: 1
hasCactus: 0
8 changes: 8 additions & 0 deletions Assets/Biomes/Forest.asset.meta

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

29 changes: 29 additions & 0 deletions Assets/Biomes/Grassland.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
%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: 56e72c31f97d0dc439a7bfd446a902f6, type: 3}
m_Name: Grassland
m_EditorClassIdentifier:
name: Grassland
scale: 80
octaves: 4
persistance: 0.7
lacunarity: 2
maxGeneratingHeight: 70
amplitude: 30
offset: {x: 83274, y: 0.2}
topBlock: 2
secondaryBlock: 1
vegetationThreshold: 0.01
minVegetationHeight: 3
maxVegetationHeight: 6
hasTree: 1
hasCactus: 0
8 changes: 8 additions & 0 deletions Assets/Biomes/Grassland.asset.meta

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

29 changes: 29 additions & 0 deletions Assets/Biomes/Snowland.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
%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: 56e72c31f97d0dc439a7bfd446a902f6, type: 3}
m_Name: Snowland
m_EditorClassIdentifier:
name: Snowland
scale: 50
octaves: 5
persistance: 0.8
lacunarity: 3
maxGeneratingHeight: 165
amplitude: 40
offset: {x: 214, y: 43}
topBlock: 6
secondaryBlock: 1
vegetationThreshold: 0.01
minVegetationHeight: 3
maxVegetationHeight: 7
hasTree: 1
hasCactus: 0
8 changes: 8 additions & 0 deletions Assets/Biomes/Snowland.asset.meta

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

60 changes: 4 additions & 56 deletions Assets/Scenes/Game.unity
Original file line number Diff line number Diff line change
Expand Up @@ -4451,7 +4451,6 @@ GameObject:
- component: {fileID: 1731320882}
- component: {fileID: 1731320885}
- component: {fileID: 1731320886}
- component: {fileID: 1731320887}
- component: {fileID: 1731320888}
- component: {fileID: 1731320884}
m_Layer: 0
Expand Down Expand Up @@ -4630,42 +4629,10 @@ MonoBehaviour:
destroyTime: 1
stackSize: 64
biomes:
- name: Grassland
noiseMult1: 0.01
noiseMult2: 0.00001
maxGeneratingHeight: 90
offset: {x: 281947, y: 0.2}
topBlock: 2
secondaryBlock: 1
vegetationThreshold: 0.01
minVegetationHeight: 3
maxVegetationHeight: 7
hasTree: 1
hasCactus: 0
- name: Snowland
noiseMult1: 0.05
noiseMult2: 0.0001
maxGeneratingHeight: 125
offset: {x: 5748, y: 43534}
topBlock: 6
secondaryBlock: 1
vegetationThreshold: 0.01
minVegetationHeight: 3
maxVegetationHeight: 8
hasTree: 1
hasCactus: 0
- name: Desert
noiseMult1: 0.01
noiseMult2: 0.00001
maxGeneratingHeight: 75
offset: {x: 234, y: 545}
topBlock: 7
secondaryBlock: 7
vegetationThreshold: 0.023
minVegetationHeight: 2
maxVegetationHeight: 8
hasTree: 0
hasCactus: 1
- {fileID: 11400000, guid: 0b42d1ee036fcb146ab5a0bab05c576c, type: 2}
- {fileID: 11400000, guid: 109345ddce309d24bb651d0ac0ad414b, type: 2}
- {fileID: 11400000, guid: 395e06bc58f962941b98aae9e0d537fd, type: 2}
- {fileID: 11400000, guid: 24dac4f41998bca40be4aef18ef05680, type: 2}
--- !u!4 &1731320883
Transform:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -4719,25 +4686,6 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
player: {fileID: 1743702924}
--- !u!114 &1731320887
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1731320881}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 557a86b045e63a34c8cc5fac7bb9112e, type: 3}
m_Name:
m_EditorClassIdentifier:
waterChunck: {fileID: 8451236987504973569, guid: c34262576ff9a3e4888b17c5dce21dad,
type: 3}
worldCreation: {fileID: 1731320882}
waterAnimTime: 1
topWater: {fileID: 0}
normalWater: {fileID: 0}
height: 60
--- !u!114 &1731320888
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down
36 changes: 22 additions & 14 deletions Assets/Scripts/World/Biome.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,28 @@
using UnityEngine;


[Serializable]
public class Biome
[CreateAssetMenu(fileName = "Biome", menuName = "Ourcraft/Biome")]
public class Biome : ScriptableObject
{
[SerializeField] public string name;
public string name;

[SerializeField] public float noiseMult1;
[SerializeField] public float noiseMult2;
[SerializeField] public int maxGeneratingHeight;
[SerializeField] public Vector2 offset;
[SerializeField] public int topBlock;
[SerializeField] public int secondaryBlock;
[SerializeField] public float vegetationThreshold;
[SerializeField] public int minVegetationHeight;
[SerializeField] public int maxVegetationHeight;
[SerializeField] public bool hasTree = true;
[SerializeField] public bool hasCactus = false;
public float scale;
public int octaves;
public float persistance;
public float lacunarity;
public int maxGeneratingHeight;
public int amplitude;
public Vector2 offset;
public int topBlock;
public int secondaryBlock;
public float vegetationThreshold;
public int minVegetationHeight;
public int maxVegetationHeight;
public bool hasTree = true;
public bool hasCactus = false;

public float GetHeight(float x, float z, int seed)
{
return Noise.GetNoise(x, z, seed, amplitude, scale, 1, octaves, persistance, lacunarity) * maxGeneratingHeight;
}
}
12 changes: 9 additions & 3 deletions Assets/Scripts/World/MeshCreation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ private void GenerateBlocks()
}
else
{
if (worldCreation.Perlin3D((x + _offset.x) * 0.05f + worldCreation.Seed, height * 0.05f + worldCreation.Seed,
if (Noise.Perlin3D((x + _offset.x) * 0.05f + worldCreation.Seed, height * 0.05f + worldCreation.Seed,
(z + _offset.y) * 0.05f + worldCreation.Seed) >= worldCreation.noiseThreshold)
{
_blockIDs[x, height + worldCreation.minHeight, z] = biome.topBlock;
Expand Down Expand Up @@ -295,9 +295,14 @@ private void GenerateBlocks()

for(var y = height + worldCreation.minHeight - 1; y >= 1; y--)
{
if (worldCreation.Perlin3D((x + _offset.x) * 0.05f + worldCreation.Seed, (float) y * 0.05f + worldCreation.Seed,
if (Noise.Perlin3D((x + _offset.x) * 0.05f + worldCreation.Seed, (float) y * 0.05f + worldCreation.Seed,
(z + _offset.y) * 0.05f + worldCreation.Seed) < worldCreation.noiseThreshold)
{
// if (!grassTop)
// {
// water.AddWater(x, y, z);
// }

continue;
}

Expand All @@ -308,9 +313,10 @@ private void GenerateBlocks()
}
else
{
grassTop = true;
if (y <= height + worldCreation.minHeight - 4)
{
if (worldCreation.Perlin3D((x + worldCreation.ironNoiseOffset.x) * 0.5f + worldCreation.Seed,
if (Noise.Perlin3D((x + worldCreation.ironNoiseOffset.x) * 0.5f + worldCreation.Seed,
(y + worldCreation.ironNoiseOffset.y) * 0.5f + worldCreation.Seed, (z + worldCreation.ironNoiseOffset.z) * 0.5f + worldCreation.Seed) <
worldCreation.ironNoiseThreshold)
{
Expand Down
40 changes: 40 additions & 0 deletions Assets/Scripts/World/Noise.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public static class Noise
{
public static float GetNoise(float x, float z, int seed, float amplitude, float scale, float frequency, int octaves, float persistance, float lacunarity)
{
var height = 0f;

for (var i = 0; i < octaves; i++)
{
var sampleX = (x + seed) / scale * frequency;
var sampleZ = (z + seed) / scale * frequency;

var perlinVal = Mathf.PerlinNoise(sampleX, sampleZ);
height += perlinVal * amplitude;

frequency *= lacunarity;
amplitude *= persistance;
}

return Mathf.InverseLerp(0, amplitude, height);
}

public static float Perlin3D(float x, float y, float z)
{
var ab = Mathf.PerlinNoise(x, y);
var bc = Mathf.PerlinNoise(y, z);
var ac = Mathf.PerlinNoise(x, z);

var ba = Mathf.PerlinNoise(y, x);
var cb = Mathf.PerlinNoise(z, y);
var ca = Mathf.PerlinNoise(z, x);

var abc = ab + bc + ac + ba + cb + ca;

return abc / 6f;
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/World/Noise.cs.meta

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

Loading

0 comments on commit 22b61cd

Please sign in to comment.