16 #define TACHYON_INTERNAL 1 40 tex = (texture *) malloc(
sizeof(texture));
46 standard_texture * tex;
47 tex = (standard_texture *) malloc(
sizeof(standard_texture));
49 return (texture *) tex;
54 tex = (vcstri_texture *) malloc(
sizeof(vcstri_texture));
56 return (texture *) tex;
60 standard_texture * tex = (standard_texture *) voidtex;
61 if (tex->img != NULL) {
62 if ((tex->texfunc == (color (*)(
const void *,
const void *,
void *))
image_plane_texture) ||
63 (tex->texfunc == (color (*)(
const void *,
const void *,
void *))
image_cyl_texture) ||
69 printf(
"XXX Doh, unrecognized image map type!\n");
78 return ry->scene->bgtex.bg_color;
86 flt IdotG =
VDot(&ry->d, &ry->scene->bgtex.bg_grad_updir);
87 flt val = (IdotG - ry->scene->bgtex.bg_grad_botval) *
88 ry->scene->bgtex.bg_grad_invrange;
96 unsigned int randval =
tea4(ry->idx, ry->idx);
98 flt noise = ry->scene->bgtex.bg_grad_noisemag * (u - 0.5);
101 tmp = (val > 1.0) ? 1.0 : val;
102 val = (tmp < 0.0) ? 0.0 : tmp;
104 col.r = ry->scene->bgtex.bg_grad_top.r * val +
105 ry->scene->bgtex.bg_grad_bot.r * (1.0 - val);
106 col.g = ry->scene->bgtex.bg_grad_top.g * val +
107 ry->scene->bgtex.bg_grad_bot.g * (1.0 - val);
108 col.b = ry->scene->bgtex.bg_grad_top.b * val +
109 ry->scene->bgtex.bg_grad_bot.b * (1.0 - val);
119 flt IdotG =
VDot(&ry->o, &ry->scene->bgtex.bg_grad_updir);
120 flt val = (IdotG - ry->scene->bgtex.bg_grad_botval) *
121 ry->scene->bgtex.bg_grad_invrange;
129 unsigned int randval =
tea4(ry->idx, ry->idx);
131 flt noise = ry->scene->bgtex.bg_grad_noisemag * (u - 0.5);
134 tmp = (val > 1.0) ? 1.0 : val;
135 val = (tmp < 0.0) ? 0.0 : tmp;
137 col.r = ry->scene->bgtex.bg_grad_top.r * val +
138 ry->scene->bgtex.bg_grad_bot.r * (1.0 - val);
139 col.g = ry->scene->bgtex.bg_grad_top.g * val +
140 ry->scene->bgtex.bg_grad_bot.g * (1.0 - val);
141 col.b = ry->scene->bgtex.bg_grad_top.b * val +
142 ry->scene->bgtex.bg_grad_bot.b * (1.0 - val);
150 standard_texture * tex = (standard_texture *) tx;
157 flt u, v, miprad, maxscale, cyrad;
158 standard_texture * tex = (standard_texture *) tx;
160 rh.x=hit->x - tex->ctr.x;
161 rh.z=hit->y - tex->ctr.y;
162 rh.y=hit->z - tex->ctr.z;
166 u = u * tex->scale.x;
171 v = v * tex->scale.y;
176 cyrad = EPSILON + 8.0 *
SQRT(rh.x*rh.x + rh.y*rh.y + rh.z*rh.z);
178 maxscale = (
FABS(tex->scale.x) >
FABS(tex->scale.y)) ?
179 tex->scale.x : tex->scale.y;
181 miprad = (0.05 * ry->opticdist *
FABS(maxscale)) / cyrad;
183 return MIPMap(tex->img, u, v, miprad);
189 flt u, v, miprad, maxscale, sprad;
190 standard_texture * tex = (standard_texture *) tx;
192 rh.x=hit->x - tex->ctr.x;
193 rh.y=hit->y - tex->ctr.y;
194 rh.z=hit->z - tex->ctr.z;
198 u = u * tex->scale.x;
203 v = v * tex->scale.y;
208 sprad = EPSILON + 8.0 *
SQRT(rh.x*rh.x + rh.y*rh.y + rh.z*rh.z);
210 maxscale = (
FABS(tex->scale.x) >
FABS(tex->scale.y)) ?
211 tex->scale.x : tex->scale.y;
213 miprad = (0.05 * ry->opticdist *
FABS(maxscale)) / sprad;
215 return MIPMap(tex->img, u, v, miprad);
221 flt u, v, miprad, maxscale;
222 standard_texture * tex = (standard_texture *) tx;
224 pnt.x=hit->x - tex->ctr.x;
225 pnt.y=hit->y - tex->ctr.y;
226 pnt.z=hit->z - tex->ctr.z;
228 VDOT(u, tex->uaxs, pnt);
229 VDOT(v, tex->vaxs, pnt);
231 u = u * tex->scale.x;
234 if (u < 0.0) u += 1.0;
236 v = v * tex->scale.y;
239 if (v < 0.0) v += 1.0;
242 maxscale = (
FABS(tex->scale.x) >
FABS(tex->scale.y)) ?
243 tex->scale.x : tex->scale.y;
245 miprad = 0.05 * ry->opticdist *
FABS(maxscale);
247 return MIPMap(tex->img, u, v, miprad);
254 flt u, v, w, miprad, maxscale;
255 standard_texture * tex = (standard_texture *) tx;
257 pnt.x=hit->x - tex->ctr.x;
258 pnt.y=hit->y - tex->ctr.y;
259 pnt.z=hit->z - tex->ctr.z;
261 VDOT(u, tex->uaxs, pnt);
262 VDOT(v, tex->vaxs, pnt);
263 VDOT(w, tex->waxs, pnt);
265 u = u * tex->scale.x;
268 if (u < 0.0) u += 1.0;
270 v = v * tex->scale.y;
273 if (v < 0.0) v += 1.0;
275 w = w * tex->scale.z;
278 if (w < 0.0) w += 1.0;
280 maxscale = (
FABS(tex->scale.x) >
FABS(tex->scale.y)) ?
281 tex->scale.x : tex->scale.y;
282 if (
FABS(tex->scale.z) >
FABS(maxscale))
283 maxscale = tex->scale.z;
285 miprad = 0.05 * ry->opticdist *
FABS(maxscale);
287 return VolMIPMap(tex->img, u, v, w, miprad);
291 color
grit_texture(
const vector * hit,
const texture * tx,
const ray * ry) {
295 standard_texture * tex = (standard_texture *) tx;
298 fnum=(rnum / 4096.0 * 0.2) + 0.8;
300 col.r=tex->col.r * fnum;
301 col.g=tex->col.g * fnum;
302 col.b=tex->col.b * fnum;
311 standard_texture * tex = (standard_texture *) tx;
313 xh=hit->x - tex->ctr.x;
314 x=(long) ((
FABS(xh) * 3) + 0.5);
316 yh=hit->y - tex->ctr.y;
317 y=(long) ((
FABS(yh) * 3) + 0.5);
319 zh=hit->z - tex->ctr.z;
320 z=(long) ((
FABS(zh) * 3) + 0.5);
323 if (((x + y + z) % 2)==1) {
342 standard_texture * tex = (standard_texture *) tx;
344 rh.x=hit->x - tex->ctr.x;
345 rh.y=hit->y - tex->ctr.y;
346 rh.z=hit->z - tex->ctr.z;
350 x=(long) (
FABS(u) * 18.0);
352 y=(long) (
FABS(v) * 10.0);
355 if (((x + y) % 2)==1) {
370 color
wood_texture(
const vector * hit,
const texture * tx,
const ray * ry) {
375 standard_texture * tex = (standard_texture *) tx;
377 x=(hit->x - tex->ctr.x) / tex->scale.x;
378 y=(hit->y - tex->ctr.y) / tex->scale.y;
379 z=(hit->z - tex->ctr.z) / tex->scale.z;
381 radius=sqrt(x*x + z*z);
387 radius=radius + 3.0 *
SIN(20 * angle + y / 150.0);
388 grain=((int) (radius + 0.5)) % 60;
410 unsigned int rndval = 1234567;
412 for (x=0; x<
NMAX; x++) {
413 for (y=0; y<
NMAX; y++) {
414 for (z=0; z<
NMAX; z++) {
435 int p000, p001, p010, p011;
436 int p100, p101, p110, p111;
437 int p00, p01, p10, p11;
439 int d00, d01, d10, d11;
468 p00=(int) ((
int) d00*ox) + p000;
469 p01=(int) ((
int) d01*ox) + p001;
470 p10=(int) ((
int) d10*ox) + p010;
471 p11=(int) ((
int) d11*ox) + p011;
474 p0=(int) ((
int) d0*oy) + p00;
475 p1=(int) ((
int) d1*oy) + p01;
478 return (
int) ((int) d*oz) + p0;
495 d=x + 0.0006 *
Noise(x, (y * 1.0), (z * 1.0));
496 d=d*(((int) d) % 25);
497 i=0.0 + 0.10 *
FABS(d - 10.0f - 20.0f * ((
int) d * 0.05f));
499 t = (i > 1.0) ? 1.0 : i;
500 i = (t < 0.0) ? 0.0 : t;
508 col.r = (1.0 +
SIN(i * 6.28)) / 2.0;
509 col.g = (1.0 +
SIN(i * 16.28)) / 2.0;
510 col.b = (1.0 +
COS(i * 30.28)) / 2.0;
519 standard_texture * tex = (standard_texture *) tx;
521 f=
Noise((hit->x - tex->ctr.x),
522 (hit->y - tex->ctr.y),
523 (hit->z - tex->ctr.z));
525 t = (f > 1.0) ? 1.0 : f;
526 f = (t < 0.01) ? 0.01 : t;
528 col.r=tex->col.r * f;
529 col.g=tex->col.g * f;
530 col.b=tex->col.b * f;
void free_standard_texture(void *voidtex)
color VolMIPMap(const mipmap *mip, flt u, flt v, flt w, flt d)
color sky_plane_background_texture(ray *ry)
unsigned int rt_rand(unsigned int *idum)
void FreeMIPMap(mipmap *mip)
color solid_background_texture(ray *ry)
texture * new_standard_texture(void)
color sky_sphere_background_texture(ray *ry)
color marble_texture(const vector *hit, const texture *tx, const ray *ry)
color gnoise_texture(const vector *hit, const texture *tx, const ray *ry)
static texture_methods standard_methods
color image_volume_texture(const vector *hit, const texture *tx, const ray *ry)
color grit_texture(const vector *hit, const texture *tx, const ray *ry)
flt VDot(apivector *a, apivector *b)
color cyl_checker_texture(const vector *hit, const texture *tx, const ray *ry)
texture * new_vcstri_texture(void)
double flt
generic floating point number, using double
static texture_methods normal_methods
#define VDOT(return, a, b)
color MIPMap(const mipmap *mip, flt u, flt v, flt d)
color image_sphere_texture(const vector *hit, const texture *tx, const ray *ry)
color wood_texture(const vector *hit, const texture *tx, const ray *ry)
Tachyon cross-platform timers, special math function wrappers, and RNGs.
int Noise(flt x, flt y, flt z)
color image_plane_texture(const vector *hit, const texture *tx, const ray *ry)
short int NoiseMatrix[NMAX][NMAX][NMAX]
static texture_methods vcstri_methods
color checker_texture(const vector *hit, const texture *tx, const ray *ry)
unsigned int tea4(unsigned int v0, unsigned int v1)
texture * new_texture(void)
Tachyon public API function prototypes and declarations used to drive the ray tracing engine...
void xyztocyl(vector pnt, flt height, flt *u, flt *v)
color image_cyl_texture(const vector *hit, const texture *tx, const ray *ry)
void xyztospr(vector pnt, flt *u, flt *v)
color constant_texture(const vector *hit, const texture *tx, const ray *ry)