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_VertexColorNoiseRGB.cs
95 lines (85 loc) · 2.77 KB
/
PQSMod_VertexColorNoiseRGB.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
87
88
89
90
91
92
93
94
95
/**
* libpqsmods - A standalone implementation of KSP's PQSMods
* Copyright (c) Thomas P. 2016
* Licensed under the terms of the MIT license
*/
using LibNoise;
using LibNoise.Generator;
using System;
using ProceduralQuadSphere.Unity;
namespace ProceduralQuadSphere
{
/// <summary>
/// PQSMod that applies color based on a noise generator with a blend value added to each channel
/// </summary>
/// <seealso cref="PQSMod" />
public class PQSMod_VertexColorNoiseRGB : PQSMod
{
public enum NoiseType
{
Perlin,
RiggedMultifractal,
Billow
}
/// <summary>
/// The type of the noise that gets used.
/// </summary>
public NoiseType noiseType;
/// <summary>
/// The red blend value
/// </summary>
public Single rBlend;
/// <summary>
/// The green blend value
/// </summary>
public Single gBlend;
/// <summary>
/// The blue blend value
/// </summary>
public Single bBlend;
#region Noise Values
public Single blend;
public Int32 seed;
public Single frequency;
public Single lacunarity;
public Single persistance;
public Int32 octaves;
public QualityMode mode;
private ModuleBase noiseMap;
#endregion
/// <summary>
/// The color that gets created from the noise
/// </summary>
private Color c;
/// <summary>
/// Initializes the base mod
/// </summary>
public override void OnSetup()
{
switch (noiseType)
{
case NoiseType.Perlin:
noiseMap = new Perlin(frequency, lacunarity, persistance, octaves, seed, mode);
break;
case NoiseType.Billow:
noiseMap = new Billow(frequency, lacunarity, persistance, octaves, seed, mode);
break;
case NoiseType.RiggedMultifractal:
noiseMap = new RidgedMultifractal(frequency, lacunarity, octaves, seed, mode);
break;
default:
throw new ArgumentException("Noise Type seems to be something undefineable. You are a scrub.", nameof(noiseType));
}
c = Color.white;
}
/// <summary>
/// Called when the parent sphere builds it's color
/// </summary>
public override void OnVertexBuild(VertexBuildData data)
{
Single h = (Single)((noiseMap.GetValue(data.directionFromCenter) + 1.0) * 0.5);
c.r = h * rBlend; c.g = h * gBlend; c.b = h * bBlend;
data.vertColor = Color.Lerp(data.vertColor, c, blend);
}
}
}