3 |
|
|
4 |
#define FPARAM(name, default) float name = params->getFloat(#name, default); |
#define FPARAM(name, default) float name = params->getFloat(#name, default); |
5 |
|
|
6 |
|
#define INVERT(i, x) ((i) + 2 * (0.5 - (i)) * (x)) |
7 |
|
|
8 |
float func(float x, float y) { |
float func(float x, float y) { |
9 |
float t = x*10; |
float t = x*10; |
10 |
float u = y*10; |
float u = y*10; |
11 |
return .5 + .2 * sin(x*M_PI*2*4) - .2*(t-floor(t)) + .2*sin(y*M_PI*2) |
return .5 + .2 * sin(x*M_PI*2*4) - .2*(t-floor(t)) + .2*sin(y*M_PI*2) |
12 |
+ .2*(u-floor(u)); |
+ .2*(u-floor(u)); |
13 |
} |
} |
14 |
|
|
15 |
float filter(float *data, int w, int h, int c, float x, float y) { |
float filter(float *data, int w, int h, int c, float x, float y) { |
34 |
FPARAM(bias, 0); |
FPARAM(bias, 0); |
35 |
FPARAM(scale, 1); |
FPARAM(scale, 1); |
36 |
FPARAM(eps, .25); |
FPARAM(eps, .25); |
37 |
|
FPARAM(invert, 0); |
38 |
|
|
39 |
// Note: radius is specified in texels |
// Note: radius is specified in texels |
40 |
FPARAM(radius, 2); |
FPARAM(radius, 2); |
53 |
ind = 3; |
ind = 3; |
54 |
for (j = 0, y = 0; j < height; j++, y += ystep) { |
for (j = 0, y = 0; j < height; j++, y += ystep) { |
55 |
for (i = 0, x = 0; i < width; i++, x += xstep) { |
for (i = 0, x = 0; i < width; i++, x += xstep) { |
56 |
data[ind] = func(x,y) * scale + bias; |
data[ind] = INVERT(invert, func(x,y)) * scale + bias; |
57 |
|
|
58 |
// Add outer edge to quantized inner edge |
// Add outer edge to quantized inner edge |
59 |
data[ind] = floor(data[ind] * 255.0 + 0.5) / 255.0; |
data[ind] = floor(data[ind] * 255.0 + 0.5) / 255.0; |