-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNormalMap.h
More file actions
executable file
·174 lines (124 loc) · 3.29 KB
/
Copy pathNormalMap.h
File metadata and controls
executable file
·174 lines (124 loc) · 3.29 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include "util.h"
#include <cmath>
#include <vector>
#ifndef PI
#define PI 3.14159265358979323846
#endif
#ifndef NORMALMAP_H
#define NORMALMAP_H
class NormalMap {
public:
// Returns a delta x, delta y for the bump map. Point is given in object space.
virtual Vector3D bump(const Point3D& p) = 0;
};
class CorrugatedNormal: public NormalMap {
/*
* Creates single-direction cosine waves.
*/
public:
Vector3D bump(const Point3D& p);
double period = 24.0;
double phaseOffset = 0.0;
double magnitude = 0.25;
};
class RadialCorrugatedNormal: public NormalMap {
/*
* Creates radial cosine waves.
*/
public:
RadialCorrugatedNormal(double x, double y) {
this -> centre = Point3D(x, y, 0);
}
Vector3D bump (const Point3D& p);
double period = 12.0;
double phaseOffset = 0.0;
double magnitude = 0.25;
private:
Point3D centre;
};
class NoiseyNormal: public NormalMap {
/*
* Creates completely noisey surface normal
*/
public:
NoiseyNormal(double magnitude) {
this -> magnitude = magnitude;
}
Vector3D bump(const Point3D& point);
double magnitude = 0.2;
};
class BricksNormal: public NormalMap {
/*
* Creates kind of a brick effect.
*/
public:
Vector3D bump(const Point3D& point);
double xPeriod = 6.0;
double yPeriod = 6.0;
double magnitude = 0.2;
double depthThreshold = -0.9;
};
class LumpyNormal : public NormalMap {
/*
* Small round bumps across the surface.
*/
public:
Vector3D bump (const Point3D& point);
double period = 6.0;
double depthThreshold = 0.8;
double magnitude = 10;
};
class RibbedNormal : public NormalMap {
/*
* For her pleasure
*/
public:
Vector3D bump (const Point3D& point);
double period = 6.0;
double heightCutoff = 0.58;
double magnitude = 0.3;
};
class PolynomialNoiseNormal : public NormalMap {
/*
* Generates a random harmonic noise map.
* Benefits are: computation time, continuousness.
*/
public:
PolynomialNoiseNormal(int order) {
int noiseLevel = order * 2;
for (int i = 0; i < order; i++) {
this -> xroots.push_back(double(rand() % noiseLevel) - double(noiseLevel) / 2);
this -> yroots.push_back(double(rand() % noiseLevel) - double(noiseLevel) / 2);
this -> xoffsets.push_back(double(rand() % noiseLevel) - double(noiseLevel) / 2);
this -> yoffsets.push_back(double(rand() % noiseLevel) - double(noiseLevel) / 2);
}
this -> order = order;
}
Vector3D bump (const Point3D& point);
private:
// Roots in [0,1]
int order;
std::vector<double> xroots;
std::vector<double> yroots;
std::vector<double> xoffsets;
std::vector<double> yoffsets;
};
class MetallicGrainNormal : public NormalMap {
/*
* Simulates metal surface grains, essentially k-nn voronoi.
*/
public:
MetallicGrainNormal(int nDents) {
for (int i = 0; i < nDents; i++) {
dentLocations.push_back(Vector3D(
(rand() % 50) / 50.0,
(rand() % 50) / 50.0,
0.0
));
}
}
Vector3D bump (const Point3D& point);
private:
std::vector<Vector3D> dentLocations;
};
#endif