2 |
#include <math.h> |
#include <math.h> |
3 |
|
|
4 |
#define FPARAM(name, default) float name = params->getFloat(#name, default); |
#define FPARAM(name, default) float name = params->getFloat(#name, default); |
5 |
|
#define SQR(A) ((A) * (A)) |
6 |
|
|
7 |
float pyramid(float x, float y) { |
float pyramid(float x, float y) { |
8 |
x -= floor(x); |
x -= floor(x); |
51 |
return (x < .4999999); |
return (x < .4999999); |
52 |
} |
} |
53 |
|
|
54 |
|
float circle(float x, float y) { |
55 |
|
return ((SQR(x - 0.5) + SQR(y - 0.5)) <= SQR(0.5)); |
56 |
|
} |
57 |
|
|
58 |
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) { |
59 |
FPARAM(type, 0); |
FPARAM(type, 0); |
60 |
FPARAM(scale, 1); |
FPARAM(scale, 1); |
116 |
if (components >= 2) data[ind++] = stripe(y); |
if (components >= 2) data[ind++] = stripe(y); |
117 |
if (components >= 3) data[ind++] = stripe(1 - xstep - x); |
if (components >= 3) data[ind++] = stripe(1 - xstep - x); |
118 |
if (components >= 4) data[ind++] = stripe(1 - ystep - y); |
if (components >= 4) data[ind++] = stripe(1 - ystep - y); |
|
break; |
|
119 |
case 7: |
case 7: |
120 |
if (components >= 1) data[ind++] = rand() / (RAND_MAX + 1.0); |
if (components >= 1) data[ind++] = rand() / (RAND_MAX + 1.0); |
121 |
if (components >= 2) data[ind++] = rand() / (RAND_MAX + 1.0); |
if (components >= 2) data[ind++] = rand() / (RAND_MAX + 1.0); |
122 |
if (components >= 3) data[ind++] = rand() / (RAND_MAX + 1.0); |
if (components >= 3) data[ind++] = rand() / (RAND_MAX + 1.0); |
123 |
if (components >= 4) data[ind++] = rand() / (RAND_MAX + 1.0); |
if (components >= 4) data[ind++] = rand() / (RAND_MAX + 1.0); |
124 |
break; |
break; |
125 |
|
case 8: |
126 |
} |
if (components >= 1) data[ind++] = circle(x + 0.5/width, y + 0.5/height); |
127 |
|
if (components >= 2) data[ind++] = circle(x + 0.5/width, y + 0.5/height); |
128 |
|
if (components >= 3) data[ind++] = circle(x + 0.5/width, y + 0.5/height); |
129 |
|
if (components >= 4) data[ind++] = circle(x + 0.5/width, y + 0.5/height); |
130 |
|
break; |
131 |
|
} |
132 |
} |
} |
133 |
} |
} |
134 |
|
|
137 |
} |
} |
138 |
|
|
139 |
} |
} |
140 |
|
|
141 |
|
|
142 |
|
|