1 |
// -*-C++-*- |
// -*-C++-*- |
2 |
#include <math.h> |
#include <math.h> |
3 |
|
#include <stdio.h> |
4 |
|
|
5 |
#define FPARAM(name, default) float name = params->getFloat(#name, default); |
#define FPARAM(name, default) float name = params->getFloat(#name, default); |
6 |
|
|
46 |
FPARAM(ripple_scale, 0.25); |
FPARAM(ripple_scale, 0.25); |
47 |
|
|
48 |
if(components != 4) return; |
if(components != 4) return; |
49 |
|
if(depth != 1) return; |
50 |
if(width != height) return; |
if(width != height) return; |
51 |
|
|
52 |
int ind=0, i, j; |
int ind=0, i, j; |
54 |
float xstep = 1.0 / width; |
float xstep = 1.0 / width; |
55 |
float ystep = 1.0 / height; |
float ystep = 1.0 / height; |
56 |
|
|
57 |
|
{ |
58 |
|
char s[1000]; |
59 |
|
sprintf(s, "gfx/libtexture/sawnoise.bin %d %d %d %d " |
60 |
|
"bias 0.5 scale 0.15 freq 1 df 2 scale2 0.25 freq2 10 df2 .5", |
61 |
|
width, height, depth, components); |
62 |
|
|
63 |
|
fprintf(stderr, "popen: %s", s); |
64 |
|
|
65 |
|
// XXX SECURITY |
66 |
|
FILE *f = popen(s, "r"); |
67 |
|
if(f == 0) { |
68 |
|
perror("POPEN FAILED!!!"); |
69 |
|
return; |
70 |
|
} |
71 |
|
|
72 |
|
fread(data, sizeof(float), width * height * depth * components, f); |
73 |
|
pclose(f); |
74 |
|
fprintf(stderr, "\n"); |
75 |
|
} |
76 |
|
|
77 |
ind = 3; |
ind = 3; |
78 |
for (j = 0, y = 0; j < height; j++, y += ystep) { |
for (j = 0, y = 0; j < height; j++, y += ystep) { |
79 |
for (i = 0, x = 0; i < width; i++, x += xstep) { |
for (i = 0, x = 0; i < width; i++, x += xstep) { |
80 |
data[ind] = INVERT(invert, func(x,y)) * scale + bias; |
float f = INVERT(invert, /*func(x,y)*/data[ind]); |
81 |
|
if (f > 1) f = 1; |
82 |
|
if (f < 0) f = 0; |
83 |
|
|
84 |
|
// Scale down to make space for the border |
85 |
|
f *= (1 - radius / (width * ripple_scale)); |
86 |
|
if (f < 0) f = 0; |
87 |
|
|
88 |
|
data[ind] = f * scale + bias; |
89 |
|
|
90 |
// Add outer edge to quantized inner edge |
// Add outer edge to quantized inner edge |
91 |
data[ind] = floor(data[ind] * 255.0 + 0.5) / 255.0; |
data[ind] = floor(data[ind] * 255.0 + 0.5) / 255.0; |