// -*-C++-*- /** * This is just the fnoise.texture with sin and cos replaceby a saw wave */ #include #define FPARAM(name, default) float name = params->getFloat(#name, default); #define a b static double drand() { return random() / (double)RAND_MAX; } float saw_sin(float x) { return asin(sin(x))/M_PI_2; } float saw_cos(float x) { return saw_sin(x + M_PI_2); } /* Add a fourier noise to the data. */ static void fourier_noise(int width, int height, int depth, int components, float *data, float freq, float df) { int nf = (int)(2 * freq); float xsin[2][nf][width]; for(int i=0; i freq+df) continue; for(int xsc = 0; xsc < 2; xsc++) { for(int ysc = 0; ysc < 2; ysc++) { float coeff[components]; for(int co = 0; co < components; co++) coeff[co] = drand()-0.5; int ind = 0; for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { for(int co = 0; co < components; co++) data[ind++] += xsin[xsc][xf][i] * ysin[ysc][yf][j] * coeff[co]; } } } } } } } else { float zsin[width][nf]; // 3D } } void GENERATE(TextureParam *params, int width, int height, int depth, int components, float *data) { FPARAM(bias, 0); FPARAM(scale, 1); FPARAM(freq, 5); FPARAM(df, 2); int d = (depth==0 ? 1 : depth); for(int i = 0; i