-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#3 Setting up multiple Noise Filters (need to insert Conditional scri…
…pts for editor)
- Loading branch information
1 parent
ca68efd
commit 5417ce4
Showing
11 changed files
with
141 additions
and
15 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
Assets/PCG/Planet Procedural Generation/Scripts/NoiseFilterFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public static class NoiseFilterFactory { | ||
public static INoiseFilter CreateNoiseFilter(NoiseSettings settings) { | ||
// Type of noise that will be created depends on the filter type specifed in the settings (NoiseSettings.cs main class) | ||
switch(settings.filterType) { | ||
case NoiseSettings.FilterType.Simple: | ||
return new SimpleNoiseFilter(settings.simpleNoiseSettings); | ||
case NoiseSettings.FilterType.Rigid: | ||
return new RigidNoiseFilter(settings.rigidNoiseSettings); | ||
} | ||
return null; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/PCG/Planet Procedural Generation/Scripts/NoiseFilterFactory.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
Assets/PCG/Planet Procedural Generation/Scripts/NoiseSettings.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
Assets/PCG/Planet Procedural Generation/Scripts/RigidNoiseFilter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class RigidNoiseFilter : INoiseFilter { | ||
NoiseSettings.RigidNoiseSettings settings; | ||
Noise noise = new Noise(); | ||
|
||
public RigidNoiseFilter(NoiseSettings.RigidNoiseSettings settings) { | ||
this.settings = settings; | ||
} | ||
|
||
public float Evaluate(Vector3 point) { | ||
float noiseValue = 0; | ||
float frequency = settings.baseRoughness; | ||
float amplitude = 1; | ||
float weight = 1; | ||
|
||
for(int i = 0; i < settings.numLayers; i++) { | ||
float v = 1-Mathf.Abs(noise.Evaluate(point*frequency+settings.centre)); | ||
v *= v;// Make ridges more pronounced by squaring the value | ||
v *= weight; | ||
weight = Mathf.Clamp01(v * settings.weightMultiplier); | ||
noiseValue += v * amplitude; | ||
frequency *= settings.roughness; | ||
amplitude *= settings.persistence; | ||
} | ||
|
||
noiseValue = Mathf.Max(0, noiseValue - settings.minValue); | ||
return noiseValue * settings.strength; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/PCG/Planet Procedural Generation/Scripts/RigidNoiseFilter.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
Assets/PCG/Planet Procedural Generation/Scripts/SimpleNoiseFilter.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
Assets/PCG/Planet Procedural Generation/Scripts/iNoiseFilter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public interface INoiseFilter { | ||
// Define the method that each class has to have to qualify as a noise filter | ||
float Evaluate(Vector3 point); | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/PCG/Planet Procedural Generation/Scripts/iNoiseFilter.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.