ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/t_func.c
Revision: 1.8
Committed: Sat Dec 15 15:03:38 1990 UTC (33 years, 4 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.7: +16 -23 lines
Log Message:
changed handling of matrix transformations with new MAT4 & XF types
dynamic allocation of ray transformations with newrayxf()
added missing light source vector transformation to m_brdf.c

File Contents

# User Rev Content
1 greg 1.8 /* Copyright (c) 1990 Regents of the University of California */
2 greg 1.1
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    
32     t_func(m, r) /* compute texture for ray */
33     register OBJREC *m;
34     register RAY *r;
35     {
36     extern double varvalue();
37     extern int errno;
38     FVECT disp;
39 greg 1.6 double d;
40 greg 1.8 register FULLXF *mxf;
41 greg 1.1 register int i;
42     register char **sa;
43    
44     if (m->oargs.nsargs < 4)
45     objerror(m, USER, "bad # arguments");
46     sa = m->oargs.sarg;
47    
48 greg 1.8 if ((mxf = (FULLXF *)m->os) == NULL) {
49     mxf = (FULLXF *)malloc(sizeof(FULLXF));
50 greg 1.1 if (mxf == NULL)
51     goto memerr;
52 greg 1.8 if (fullxf(mxf, m->oargs.nsargs-4, sa+4) != m->oargs.nsargs-4)
53 greg 1.1 objerror(m, USER, "bad transform");
54 greg 1.8 if (mxf->f.sca < 0.0)
55     mxf->f.sca = -mxf->f.sca;
56     if (mxf->b.sca < 0.0)
57     mxf->b.sca = -mxf->b.sca;
58 greg 1.2 m->os = (char *)mxf;
59 greg 1.1 }
60    
61 greg 1.8 setmap(m, r, &mxf->b);
62 greg 1.1
63     if (!vardefined(sa[0]))
64     loadfunc(sa[3]);
65     errno = 0;
66     for (i = 0; i < 3; i++)
67     disp[i] = varvalue(sa[i]);
68     if (errno) {
69     objerror(m, WARNING, "compute error");
70     return;
71     }
72 greg 1.8 multv3(disp, disp, mxf->f.xfm);
73     if (r->rox != NULL) {
74     multv3(disp, disp, r->rox->f.xfm);
75     d = 1.0 / (mxf->f.sca * r->rox->f.sca);
76     } else
77     d = 1.0 / mxf->f.sca;
78 greg 1.4 for (i = 0; i < 3; i++)
79 greg 1.6 r->pert[i] += disp[i] * d;
80 greg 1.1 return;
81     memerr:
82     error(SYSTEM, "out of memory in t_func");
83     }