1 |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
|
3 |
#ifndef lint |
4 |
static char SCCSid[] = "$SunId$ LBL"; |
5 |
#endif |
6 |
|
7 |
/* |
8 |
* t_func.c - routine for procedural textures. |
9 |
* |
10 |
* 4/8/86 |
11 |
*/ |
12 |
|
13 |
#include "ray.h" |
14 |
|
15 |
#include "func.h" |
16 |
|
17 |
/* |
18 |
* A procedural texture perturbs the surface normal |
19 |
* at the point of intersection with an object. It has |
20 |
* the form: |
21 |
* |
22 |
* modifier texfunc name |
23 |
* 4+ xvarname yvarname zvarname filename xf |
24 |
* 0 |
25 |
* n A1 A2 .. |
26 |
* |
27 |
* Filename is the name of the file where the variable definitions |
28 |
* can be found. The list of real arguments can be accessed by |
29 |
* definitions in the file. The xf is a transformation to get |
30 |
* from the original coordinates to the current coordinates. |
31 |
*/ |
32 |
|
33 |
|
34 |
t_func(m, r) /* compute texture for ray */ |
35 |
register OBJREC *m; |
36 |
register RAY *r; |
37 |
{ |
38 |
FVECT disp; |
39 |
double d; |
40 |
register MFUNC *mf; |
41 |
register int i; |
42 |
|
43 |
if (m->oargs.nsargs < 4) |
44 |
objerror(m, USER, "bad # arguments"); |
45 |
mf = getfunc(m, 3, 0x7, 1); |
46 |
setfunc(m, r); |
47 |
errno = 0; |
48 |
for (i = 0; i < 3; i++) { |
49 |
disp[i] = evalue(mf->ep[i]); |
50 |
if (errno) { |
51 |
objerror(m, WARNING, "compute error"); |
52 |
return; |
53 |
} |
54 |
} |
55 |
if (mf->f != &unitxf) |
56 |
multv3(disp, disp, mf->f->xfm); |
57 |
if (r->rox != NULL) { |
58 |
multv3(disp, disp, r->rox->f.xfm); |
59 |
d = 1.0 / (mf->f->sca * r->rox->f.sca); |
60 |
} else |
61 |
d = 1.0 / mf->f->sca; |
62 |
for (i = 0; i < 3; i++) |
63 |
r->pert[i] += disp[i] * d; |
64 |
} |