// -*-C++-*- #include #define FPARAM(name, default) float name = params->getFloat(#name, default); float pyramid(float x, float y) { x -= floor(x); y -= floor(y); x = fabs(x - .5); y = fabs(y - .5); return 1 - 2 * (x > y ? x : y); } float checkerboard(float x, float y) { x -= floor(x); y -= floor(y); return (x - .5) * (y - .5) < 0; } float cone(float x, float y) { x -= floor(x); y -= floor(y); x -= .5; y -= .5; return 1 - 2 * sqrt(.5 * (x * x + y * y)); } float checkerboard2(float x, float y) { x -= floor(x); y -= floor(y); return x < .5 && y < .5; } void GENERATE(TextureParam *params, int width, int height, int depth, int components, float *data) { FPARAM(type, 0) if(components > 4) return; int ind=0, i, j; float x, y; float xstep = 1.0 / width; float ystep = 1.0 / height; for (j = 0, y = 0; j < height; j++, y += ystep) { for (i = 0, x = 0; i < width; i++, x += xstep) { switch ((int)type) { case 0: if (components >= 1) data[ind++] = pyramid(x, y); if (components >= 2) data[ind++] = pyramid(x + .5, y); if (components >= 3) data[ind++] = pyramid(x, y + .5); if (components >= 4) data[ind++] = pyramid(x + .5, y + .5); break; case 1: if (components >= 1) data[ind++] = checkerboard(x, y); if (components >= 2) data[ind++] = checkerboard(x + .25, y); if (components >= 3) data[ind++] = checkerboard(x, y + .25); if (components >= 4) data[ind++] = checkerboard(x + .25, y + .25); break; case 2: if (components >= 1) data[ind++] = cone(x, y); if (components >= 2) data[ind++] = cone(x + .5, y); if (components >= 3) data[ind++] = cone(x, y + .5); if (components >= 4) data[ind++] = cone(x + .5, y + .5); break; case 3: if (components >= 1) data[ind++] = checkerboard2(x, y); if (components >= 2) data[ind++] = checkerboard2(x + .5, y); if (components >= 3) data[ind++] = checkerboard2(x, y + .5); if (components >= 4) data[ind++] = checkerboard2(x + .5, y + .5); break; } } } }