74 |
} |
} |
75 |
} |
} |
76 |
|
|
77 |
|
double identity(double x) { return x; } |
78 |
|
|
79 |
void GENERATE(TextureParam *params, int width, int height, int depth, int components, float *data) { |
void GENERATE(TextureParam *params, int width, int height, int depth, int components, float *data) { |
80 |
FPARAM(bias, 0); |
FPARAM(bias, 0); |
81 |
FPARAM(scale, 1); |
FPARAM(scale, 1); |
84 |
FPARAM(df, 2); |
FPARAM(df, 2); |
85 |
FPARAM(seed, 0); |
FPARAM(seed, 0); |
86 |
FPARAM(turb, 0); |
FPARAM(turb, 0); |
87 |
|
FPARAM(fbm, 0); |
88 |
FPARAM(freq2, 20); |
FPARAM(freq2, 20); |
89 |
|
|
90 |
|
double (*func)(double) = identity; |
91 |
|
if (turb) func = fabs, fbm = 1; |
92 |
|
|
93 |
if (seed) srandom((long)seed); |
if (seed) srandom((long)seed); |
94 |
|
|
95 |
int d = (depth==0 ? 1 : depth); |
int d = (depth==0 ? 1 : depth); |
99 |
data[i] = 0; |
data[i] = 0; |
100 |
|
|
101 |
|
|
102 |
if (turb) { |
if (fbm) { |
103 |
float *tmp = new float[n]; |
float *tmp = new float[n]; |
104 |
|
|
105 |
for (float f = freq; f <= freq2; f += f) { |
for (float f = freq; f <= freq2; f += f) { |
110 |
float m = 1.0 / (log(f)/log(2) + 1); |
float m = 1.0 / (log(f)/log(2) + 1); |
111 |
|
|
112 |
for(int i = 0; i<n; i++) |
for(int i = 0; i<n; i++) |
113 |
data[i] += m * fabs(tmp[i]); |
data[i] += m * func(tmp[i]); |
114 |
} |
} |
115 |
|
|
116 |
for(int i = 0; i<n; i++) |
for(int i = 0; i<n; i++) |