-
Notifications
You must be signed in to change notification settings - Fork 0
/
SolidNoise.h
49 lines (42 loc) · 1.03 KB
/
SolidNoise.h
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
#pragma once
#include <cmath>
#include "Vector3.h"
class SolidNoise
{
public:
SolidNoise();
float Noise(const Vector3 &) const;
float Turbulence(const Vector3 &p, int depth) const;
float DTurbulence(const Vector3 &p, int depth, float d) const;
float Omega(float t) const;
Vector3 Gamma(int i, int j, int k) const;
int IntGamma(int i, int j) const;
float Knot(int i, int j, int k, Vector3 &v) const;
public:
Vector3 grad[16];
int phi[16];
};
inline float SolidNoise::Omega(float t) const
{
t = (t > 0.0f) ? t : -t;
return (-6.0f*t*t*t*t*t + 15.0f*t*t*t*t - 10.0f*t*t*t + 1.0f);
}
inline Vector3 SolidNoise::Gamma(int i, int j, int k) const
{
int idx;
idx = phi[abs(k) % 16];
idx = phi[abs(j + idx) % 16];
idx = phi[abs(i + idx) % 16];
return grad[idx];
}
inline float SolidNoise::Knot(int i, int j, int k, Vector3 &v) const
{
return (Omega(v.x)*Omega(v.y) * Omega(v.z) * (Dot(Gamma(i, j, k), v)));
}
inline int SolidNoise::IntGamma(int i, int j) const
{
int idx;
idx = phi[abs(j) % 16];
idx = phi[abs(i + idx) % 16];
return idx;
}