This repository has been archived by the owner on Aug 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPQSMod_VertexNoise.cs
86 lines (80 loc) · 2.52 KB
/
PQSMod_VertexNoise.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
* libpqsmods - A standalone implementation of KSP's PQSMods
* Copyright (c) Thomas P. 2016
* Licensed under the terms of the MIT license
*/
using System;
using LibNoise.Generator;
using LibNoise.Operator;
namespace ProceduralQuadSphere
{
/// <summary>
/// A mod that combines all existing noises
/// </summary>
/// <seealso cref="PQSMod" />
public class PQSMod_VertexNoise : PQSMod
{
#region Noise Values
public Int32 seed;
public Single noiseDeformity;
public Int32 noisePasses;
public Single smoothness;
public Single falloff;
public Single mesaVsPlainsBias;
public Single plainsVsMountainSmoothness;
public Single plainsVsMountainThreshold;
public Single plainSmoothness;
private Select terrainHeightMap;
#endregion
/// <summary>
/// Initializes the base mod
/// </summary>
public override void OnSetup()
{
Billow billow = new Billow()
{
Seed = seed,
Frequency = 2 * (1f / smoothness)
};
ScaleBias scaleBia = new ScaleBias((1f / plainSmoothness), mesaVsPlainsBias, billow);
RidgedMultifractal riggedMultifractal = new RidgedMultifractal
{
Seed = seed,
OctaveCount = noisePasses,
Frequency = 1 / smoothness
};
Perlin perlin = new Perlin
{
Seed = seed,
OctaveCount = noisePasses,
Frequency = 1 / plainsVsMountainSmoothness,
Persistence = 1 / falloff
};
terrainHeightMap = new Select(0, 1, plainsVsMountainThreshold, scaleBia, riggedMultifractal)
{
Controller = perlin
};
}
/// <summary>
/// Called when the parent sphere builds it's height
/// </summary>
public override void OnVertexBuildHeight(VertexBuildData data)
{
data.vertHeight += terrainHeightMap.GetValue(data.directionFromCenter * sphere.radius) * noiseDeformity;
}
/// <summary>
/// Gets the maximum height of the mod.
/// </summary>
public override Double GetVertexMaxHeight()
{
return noiseDeformity;
}
/// <summary>
/// Gets the minimum height of the mod.
/// </summary>
public override Double GetVertexMinHeight()
{
return 0;
}
}
}