forked from keijiro/NoiseShader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NoiseTest.cs
56 lines (45 loc) · 1.33 KB
/
NoiseTest.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
using UnityEngine;
[ExecuteInEditMode]
public class NoiseTest : MonoBehaviour
{
public enum NoiseType {
ClassicPerlin,
PeriodicPerlin,
Simplex,
SimplexNumericalGrad,
SimplexAnalyticalGrad
}
[SerializeField]
NoiseType _noiseType;
[SerializeField]
bool _is3D;
[SerializeField]
bool _isFractal;
[SerializeField]
Shader shader;
Material _material;
void Update()
{
if (_material == null)
{
_material = new Material(shader);
_material.hideFlags = HideFlags.DontSave;
GetComponent<Renderer>().material = _material;
}
_material.shaderKeywords = null;
if (_noiseType == NoiseType.ClassicPerlin)
_material.EnableKeyword("CNOISE");
else if (_noiseType == NoiseType.PeriodicPerlin)
_material.EnableKeyword("PNOISE");
else if (_noiseType == NoiseType.Simplex)
_material.EnableKeyword("SNOISE");
else if (_noiseType == NoiseType.SimplexNumericalGrad)
_material.EnableKeyword("SNOISE_NGRAD");
else // SimplexAnalyticalGrad
_material.EnableKeyword("SNOISE_AGRAD");
if (_is3D)
_material.EnableKeyword("THREED");
if (_isFractal)
_material.EnableKeyword("FRACTAL");
}
}