ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/t_func.c
Revision: 1.1
Committed: Thu Feb 2 10:41:46 1989 UTC (35 years, 3 months ago) by greg
Content type: text/plain
Branch: MAIN
Log Message:
Initial revision

File Contents

# Content
1 /* Copyright (c) 1986 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 /*
16 * A procedural texture perturbs the surface normal
17 * at the point of intersection with an object. It has
18 * the form:
19 *
20 * modifier texfunc name
21 * 4+ xvarname yvarname zvarname filename xf
22 * 0
23 * n A1 A2 ..
24 *
25 * Filename is the name of the file where the variable definitions
26 * can be found. The list of real arguments can be accessed by
27 * definitions in the file. The xf is a transformation to get
28 * from the original coordinates to the current coordinates.
29 */
30
31 typedef struct {
32 struct {
33 double sca; /* scale factor */
34 double xfm[4][4]; /* transformation matrix */
35 } fore, back;
36 } XFORM;
37
38
39 t_func(m, r) /* compute texture for ray */
40 register OBJREC *m;
41 register RAY *r;
42 {
43 #define mxf ((XFORM *)m->os)
44 extern double varvalue();
45 extern int errno;
46 FVECT disp;
47 register int i;
48 register char **sa;
49
50 if (m->oargs.nsargs < 4)
51 objerror(m, USER, "bad # arguments");
52 sa = m->oargs.sarg;
53
54 if (mxf == NULL) {
55 mxf = (XFORM *)malloc(sizeof(XFORM));
56 if (mxf == NULL)
57 goto memerr;
58 mxf->fore.sca = 1.0;
59 setident4(mxf->fore.xfm);
60 if (xf(mxf->fore.xfm, &mxf->fore.sca,
61 m->oargs.nsargs-4, sa+4) != m->oargs.nsargs-4)
62 objerror(m, USER, "bad transform");
63 if (mxf->fore.sca < 0.0)
64 mxf->fore.sca = -mxf->fore.sca;
65 mxf->back.sca = 1.0;
66 setident4(mxf->back.xfm);
67 invxf(mxf->back.xfm, &mxf->back.sca,
68 m->oargs.nsargs-4, sa+4);
69 if (mxf->back.sca < 0.0)
70 mxf->back.sca = -mxf->back.sca;
71 }
72
73 setmap(m, r, mxf->back.sca, mxf->back.xfm);
74
75 if (!vardefined(sa[0]))
76 loadfunc(sa[3]);
77 errno = 0;
78 for (i = 0; i < 3; i++)
79 disp[i] = varvalue(sa[i]);
80 if (errno) {
81 objerror(m, WARNING, "compute error");
82 return;
83 }
84 if (mxf->fore.xfm == NULL)
85 for (i = 0; i < 3; i++)
86 r->pert[i] += disp[i];
87 else
88 for (i = 0; i < 3; i++)
89 r->pert[i] += ( disp[0]*mxf->fore.xfm[0][i] +
90 disp[1]*mxf->fore.xfm[1][i] +
91 disp[2]*mxf->fore.xfm[2][i] )
92 / mxf->fore.sca;
93 return;
94 memerr:
95 error(SYSTEM, "out of memory in t_func");
96 #undef mxf
97 }