ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/m_direct.c
Revision: 2.2
Committed: Mon Nov 25 09:51:06 1991 UTC (32 years, 5 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.1: +38 -58 lines
Log Message:
changed function file calls to allow expressions instead of just vars

File Contents

# Content
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 * Routines for light-redirecting materials and
9 * their associated virtual light sources
10 */
11
12 #include "ray.h"
13
14 #include "otypes.h"
15
16 #include "source.h"
17
18 #include "func.h"
19
20 /*
21 * The arguments for MAT_DIRECT1 are:
22 *
23 * 5+ coef1 dx1 dy1 dz1 funcfile transform..
24 * 0
25 * n A1 A2 .. An
26 *
27 * The arguments for MAT_DIRECT2 are:
28 *
29 * 9+ coef1 dx1 dy1 dz1 coef2 dx2 dy2 dz2 funcfile transform..
30 * 0
31 * n A1 A2 .. An
32 */
33
34
35 int dir_proj();
36 VSMATERIAL direct1_vs = {dir_proj, 1};
37 VSMATERIAL direct2_vs = {dir_proj, 2};
38
39 #define getdfunc(m) ( (m)->otype == MAT_DIRECT1 ? \
40 getfunc(m, 4, 0xf, 1) : \
41 getfunc(m, 8, 0xff, 1) )
42
43
44 m_direct(m, r) /* shade redirected ray */
45 register OBJREC *m;
46 register RAY *r;
47 {
48 /* check if source ray */
49 if (r->rsrc >= 0 && source[r->rsrc].so != r->ro)
50 return; /* got the wrong guy */
51 /* compute first projection */
52 if (m->otype == MAT_DIRECT1 ||
53 (r->rsrc < 0 || source[r->rsrc].sa.sv.pn == 0))
54 redirect(m, r, 0);
55 /* compute second projection */
56 if (m->otype == MAT_DIRECT2 &&
57 (r->rsrc < 0 || source[r->rsrc].sa.sv.pn == 1))
58 redirect(m, r, 1);
59 }
60
61
62 redirect(m, r, n) /* compute n'th ray redirection */
63 OBJREC *m;
64 RAY *r;
65 int n;
66 {
67 MFUNC *mf;
68 register EPNODE **va;
69 RAY nr;
70 double coef;
71 register int j;
72 /* set up function */
73 mf = getdfunc(m);
74 setfunc(m, r);
75 /* compute coefficient */
76 errno = 0;
77 va = mf->ep + 4*n;
78 coef = evalue(va[0]);
79 if (errno)
80 goto computerr;
81 if (coef <= FTINY || rayorigin(&nr, r, TRANS, coef) < 0)
82 return(0);
83 va++; /* compute direction */
84 for (j = 0; j < 3; j++) {
85 nr.rdir[j] = evalue(va[j]);
86 if (errno)
87 goto computerr;
88 }
89 if (mf->f != &unitxf)
90 multv3(nr.rdir, nr.rdir, mf->f->xfm);
91 if (r->rox != NULL)
92 multv3(nr.rdir, nr.rdir, r->rox->f.xfm);
93 if (normalize(nr.rdir) == 0.0)
94 goto computerr;
95 /* compute value */
96 if (r->rsrc >= 0)
97 nr.rsrc = source[r->rsrc].sa.sv.sn;
98 rayvalue(&nr);
99 scalecolor(nr.rcol, coef);
100 addcolor(r->rcol, nr.rcol);
101 return(1);
102 computerr:
103 objerror(m, WARNING, "compute error");
104 return(-1);
105 }
106
107
108 dir_proj(pm, o, s, n) /* compute a director's projection */
109 MAT4 pm;
110 OBJREC *o;
111 SRCREC *s;
112 int n;
113 {
114 RAY tr;
115 OBJREC *m;
116 MFUNC *mf;
117 EPNODE **va;
118 FVECT cent, newdir, nv, h;
119 double coef, olddot, newdot, od;
120 register int i, j;
121 /* initialize test ray */
122 getmaxdisk(cent, o);
123 if (s->sflags & SDISTANT)
124 for (i = 0; i < 3; i++) {
125 tr.rdir[i] = -s->sloc[i];
126 tr.rorg[i] = cent[i] - tr.rdir[i];
127 }
128 else {
129 for (i = 0; i < 3; i++) {
130 tr.rdir[i] = cent[i] - s->sloc[i];
131 tr.rorg[i] = s->sloc[i];
132 }
133 if (normalize(tr.rdir) == 0.0)
134 return(0); /* at source! */
135 }
136 od = getplaneq(nv, o);
137 olddot = DOT(tr.rdir, nv);
138 if (olddot <= FTINY && olddot >= -FTINY)
139 return(0); /* old dir parallels plane */
140 rayorigin(&tr, NULL, PRIMARY, 1.0);
141 if (!(*ofun[o->otype].funp)(o, &tr))
142 return(0); /* no intersection! */
143 /* compute redirection */
144 m = vsmaterial(o);
145 mf = getdfunc(m);
146 setfunc(m, &tr);
147 errno = 0;
148 va = mf->ep + 4*n;
149 coef = evalue(va[0]);
150 if (errno)
151 goto computerr;
152 if (coef <= FTINY)
153 return(0); /* insignificant */
154 va++;
155 for (i = 0; i < 3; i++) {
156 newdir[i] = evalue(va[i]);
157 if (errno)
158 goto computerr;
159 }
160 if (mf->f != &unitxf)
161 multv3(newdir, newdir, mf->f->xfm);
162 /* normalization unnecessary */
163 newdot = DOT(newdir, nv);
164 if (newdot <= FTINY && newdot >= -FTINY)
165 return(0); /* new dir parallels plane */
166 /* everything OK -- compute shear */
167 for (i = 0; i < 3; i++)
168 h[i] = newdir[i]/newdot - tr.rdir[i]/olddot;
169 setident4(pm);
170 for (j = 0; j < 3; j++) {
171 for (i = 0; i < 3; i++)
172 pm[i][j] += nv[i]*h[j];
173 pm[3][j] = -od*h[j];
174 }
175 if (newdot > 0.0 ^ olddot > 0.0) /* add mirroring */
176 for (j = 0; j < 3; j++) {
177 for (i = 0; i < 3; i++)
178 pm[i][j] -= 2.*nv[i]*nv[j];
179 pm[3][j] += 2.*od*nv[j];
180 }
181 return(1);
182 computerr:
183 objerror(m, WARNING, "projection compute error");
184 return(0);
185 }