This repository was 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
Expand file tree
/
Copy pathPQSMod_VertexSimplexMultiChromatic.cs
More file actions
80 lines (71 loc) · 2.55 KB
/
PQSMod_VertexSimplexMultiChromatic.cs
File metadata and controls
80 lines (71 loc) · 2.55 KB
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
/**
* libpqsmods - A standalone implementation of KSP's PQSMods
* Copyright (c) Thomas P. 2016
* Licensed under the terms of the MIT license
*/
using System;
using ProceduralQuadSphere.KSP;
using ProceduralQuadSphere.Unity;
namespace ProceduralQuadSphere
{
/// <summary>
/// A mod that uses three simplexes to color the terrain
/// </summary>
/// <seealso cref="PQSMod" />
public class PQSMod_VertexSimplexMultiChromatic : PQSMod
{
/// <summary>
/// How much of the resulting color ends up in the terrain
/// </summary>
public Single blend;
// R
public Int32 redSeed;
public Double redOctaves;
public Double redPersistence;
public Double redFrequency;
// B
public Int32 blueSeed;
public Double blueOctaves;
public Double bluePersistence;
public Double blueFrequency;
// G
public Int32 greenSeed;
public Double greenOctaves;
public Double greenPersistence;
public Double greenFrequency;
// A
public Int32 alphaSeed;
public Double alphaOctaves;
public Double alphaPersistence;
public Double alphaFrequency;
// The final channel simplexes
private Simplex redSimplex;
private Simplex blueSimplex;
private Simplex greenSimplex;
private Simplex alphaSimplex;
/// <summary>
/// Initializes the base mod
/// </summary>
public override void OnSetup()
{
redSimplex = new Simplex(redSeed, redOctaves, redPersistence, redFrequency);
blueSimplex = new Simplex(blueSeed, blueOctaves, bluePersistence, blueFrequency);
greenSimplex = new Simplex(greenSeed, greenOctaves, greenPersistence, greenFrequency);
alphaSimplex = new Simplex(alphaSeed, alphaOctaves, alphaPersistence, alphaFrequency);
}
/// <summary>
/// Called when the parent sphere builds it's color
/// </summary>
public override void OnVertexBuild(VertexBuildData data)
{
Color c = new Color
{
r = (Single) redSimplex.noiseNormalized(data.directionFromCenter),
g = (Single) blueSimplex.noiseNormalized(data.directionFromCenter),
b = (Single) greenSimplex.noiseNormalized(data.directionFromCenter),
a = (Single) alphaSimplex.noiseNormalized(data.directionFromCenter)
};
data.vertColor = Color.Lerp(data.vertColor, c, blend);
}
}
}