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