ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/mkillum2.c
(Generate patch)

Comparing ray/src/gen/mkillum2.c (file contents):
Revision 1.3 by greg, Wed Jul 24 13:32:05 1991 UTC vs.
Revision 1.7 by greg, Thu Jul 25 14:12:22 1991 UTC

# Line 5 | Line 5 | static char SCCSid[] = "$SunId$ LBL";
5   #endif
6  
7   /*
8 < * Routines to do the actual calcultion and output for mkillum
8 > * Routines to do the actual calculation for mkillum
9   */
10  
11   #include  "mkillum.h"
# Line 17 | Line 17 | static char SCCSid[] = "$SunId$ LBL";
17   #include  "random.h"
18  
19  
20 printobj(mod, obj)              /* print out an object */
21 char  *mod;
22 register OBJREC  *obj;
23 {
24        register int  i;
25
26        printf("\n%s %s %s", mod, ofun[obj->otype].funame, obj->oname);
27        printf("\n%d", obj->oargs.nsargs);
28        for (i = 0; i < obj->oargs.nsargs; i++)
29                printf(" %s", obj->oargs.sarg[i]);
30 #ifdef  IARGS
31        printf("\n%d", obj->oargs.niargs);
32        for (i = 0; i < obj->oargs.niargs; i++)
33                printf(" %d", obj->oargs.iarg[i]);
34 #else
35        printf("\n0");
36 #endif
37        printf("\n%d", obj->oargs.nfargs);
38        for (i = 0; i < obj->oargs.nfargs; i++) {
39                if (i%3 == 0)
40                        putchar('\n');
41                printf(" %18.12g", obj->oargs.farg[i]);
42        }
43        putchar('\n');
44 }
45
46
20   o_default(ob, il, rt, nm)       /* default illum action */
21   OBJREC  *ob;
22   struct illum_args  *il;
# Line 54 | Line 27 | char  *nm;
27                          nm, ofun[ob->otype].funame, ob->oname);
28          error(WARNING, errmsg);
29          if (!(il->flags & IL_LIGHT))
30 <                printobj(il->altname, ob);
30 >                printobj(il->altmat, ob);
31   }
32  
33  
# Line 69 | Line 42 | char  *nm;
42          int  n, nalt, nazi;
43          float  *distarr;
44          double  r1, r2;
45 <        FVECT  dn, pos, dir;
45 >        FVECT  dn, org, dir;
46          FVECT  u, v;
47          double  ur[2], vr[2];
48          int  nmisses;
# Line 111 | Line 84 | char  *nm;
84                      dim[3] = 1;
85                      r1 = (dim[1]+urand(urind(ilhash(dim,4),i)))/nalt;
86                      dim[3] = 2;
87 <                    r2 = (dim[2]+urand(urind(ilhash(dim,4),i)))/nalt;
87 >                    r2 = (dim[2]+urand(urind(ilhash(dim,4),i)))/nazi;
88                      flatdir(dn, r1, r2);
89                      for (j = 0; j < 3; j++)
90 <                        dir[j] = dn[0]*u[j] + dn[1]*v[j] - dn[2]*fa->norm[j];
90 >                        dir[j] = -dn[0]*u[j] - dn[1]*v[j] - dn[2]*fa->norm[j];
91                                          /* random location */
92                      do {
93                          dim[3] = 3;
94 <                        r1 = ur[0] +
95 <                                (ur[1]-ur[0])*urand(urind(ilhash(dim,4),i));
94 >                        r1 = ur[0] + (ur[1]-ur[0]) *
95 >                                        urand(urind(ilhash(dim,4),i+nmisses));
96                          dim[3] = 4;
97 <                        r2 = vr[0] +
98 <                                (vr[1]-vr[0])*urand(urind(ilhash(dim,4),i));
97 >                        r2 = vr[0] + (vr[1]-vr[0]) *
98 >                                        urand(urind(ilhash(dim,4),i+nmisses));
99                          for (j = 0; j < 3; j++)
100                              org[j] = r1*u[j] + r2*v[j]
101                                          + fa->offset*fa->norm[j];
# Line 138 | Line 111 | char  *nm;
111                      for (j = 0; j < 3; j++)
112                          org[j] += .001*fa->norm[j];
113                                          /* send sample */
114 <                    raysamp(distarr+dim[1]*nazi+dim[2], org, dir, rt);
114 >                    raysamp(distarr+3*(dim[1]*nazi+dim[2]), org, dir, rt);
115                  }
116          rayflush(rt);
117 <                                /* write out the distribution */
118 <        flatdist(distarr, nalt, nazi, il, ob);
117 >                                /* write out the face w/ distribution */
118 >        flatout(il, distarr, nalt, nazi, u, v, fa->norm);
119 >        illumout(il, ob);
120                                  /* clean up */
121          freeface(ob);
122          free((char *)distarr);
# Line 159 | Line 133 | char  *nm;
133          int  dim[4];
134          int  n, nalt, nazi;
135          float  *distarr;
136 <        double  r1, r2;
137 <        FVECT  pos, dir;
136 >        double  r1, r2, r3;
137 >        FVECT  org, dir;
138          FVECT  u, v;
139          register int  i, j;
140                                  /* check arguments */
# Line 177 | Line 151 | char  *nm;
151          dim[0] = random();
152                                  /* sample sphere */
153          for (dim[1] = 0; dim[1] < nalt; dim[1]++)
154 <            for (dim[2] = 0; dim[2] < nazi; dim[2]++)
154 >            for (dim[2] = 0; dim[2] < nazi; dim[2]++) {
155 >                if (il->nsamps > 2 && nazi > 20) {
156 >                    rounddir(dir, (dim[1]+.5)/nalt, (dim[2]+.5)/nazi);
157 >                    mkaxes(u, v, dir);
158 >                }
159                  for (i = 0; i < il->nsamps; i++) {
160                                          /* random direction */
161                      dim[3] = 1;
162                      r1 = (dim[1]+urand(urind(ilhash(dim,4),i)))/nalt;
163                      dim[3] = 2;
164 <                    r2 = (dim[2]+urand(urind(ilhash(dim,4),i)))/nalt;
164 >                    r2 = (dim[2]+urand(urind(ilhash(dim,4),i)))/nazi;
165                      rounddir(dir, r1, r2);
166                                          /* random location */
167 <                    mkaxes(u, v, dir);          /* yuck! */
167 >                    if (il->nsamps <= 2 || nazi <= 20)
168 >                        mkaxes(u, v, dir);              /* yuck! */
169                      dim[3] = 3;
170 <                    r1 = sqrt(urand(urind(ilhash(dim,4),i)));
170 >                    r3 = sqrt(urand(urind(ilhash(dim,4),i)));
171                      dim[3] = 4;
172                      r2 = 2.*PI*urand(urind(ilhash(dim,4),i));
173 <                    for (j = 0; j < 3; j++)
174 <                        org[j] = obj->oargs.farg[j] + obj->oargs.farg[3] *
175 <                                        ( r1*cos(r2)*u[j] + r1*sin(r2)*v[j]
176 <                                                - sqrt(1.01-r1*r1)*dir[j] );
177 <
173 >                    r1 = r3*ob->oargs.farg[3]*cos(r2);
174 >                    r2 = r3*ob->oargs.farg[3]*sin(r2);
175 >                    r3 = ob->oargs.farg[3]*sqrt(1.01-r3*r3);
176 >                    for (j = 0; j < 3; j++) {
177 >                        org[j] = ob->oargs.farg[j] + r1*u[j] + r2*v[j] +
178 >                                        r3*dir[j];
179 >                        dir[j] = -dir[j];
180 >                    }
181                                          /* send sample */
182 <                    raysamp(distarr+dim[1]*nazi+dim[2], org, dir, rt);
182 >                    raysamp(distarr+3*(dim[1]*nazi+dim[2]), org, dir, rt);
183                  }
184 +            }
185          rayflush(rt);
186 <                                /* write out the distribution */
187 <        rounddist(distarr, nalt, nazi, il, ob);
186 >                                /* write out the sphere w/ distribution */
187 >        roundout(il, distarr, nalt, nazi);
188 >        illumout(il, ob);
189                                  /* clean up */
190          free((char *)distarr);
191   }
# Line 216 | Line 200 | char  *nm;
200          int  dim[4];
201          int  n, nalt, nazi;
202          float  *distarr;
203 <        double  r1, r2;
204 <        FVECT  dn, pos, dir;
203 >        double  r1, r2, r3;
204 >        FVECT  dn, org, dir;
205          FVECT  u, v;
206          register CONE  *co;
207          register int  i, j;
# Line 244 | Line 228 | char  *nm;
228                      r2 = (dim[2]+urand(urind(ilhash(dim,4),i)))/nalt;
229                      flatdir(dn, r1, r2);
230                      for (j = 0; j < 3; j++)
231 <                        dir[j] = dn[0]*u[j] + dn[1]*v[j] - dn[2]*co->ad[j];
231 >                        dir[j] = -dn[0]*u[j] - dn[1]*v[j] - dn[2]*co->ad[j];
232                                          /* random location */
233                      dim[3] = 3;
234 <                    r1 = sqrt(CO_R0(co)*CO_R0(co) +
234 >                    r3 = sqrt(CO_R0(co)*CO_R0(co) +
235                                  urand(urind(ilhash(dim,4),i))*
236                                  (CO_R1(co)*CO_R1(co) - CO_R0(co)*CO_R0(co)));
237                      dim[3] = 4;
238                      r2 = 2.*PI*urand(urind(ilhash(dim,4),i));
239 +                    r1 = r3*cos(r2);
240 +                    r2 = r3*sin(r2);
241                      for (j = 0; j < 3; j++)
242 <                        org[j] = CO_P0(co)[j] +
243 <                                        r1*cos(r2)*u[j] + r1*sin(r2)*v[j]
258 <                                        + .001*co->ad[j];
242 >                        org[j] = CO_P0(co)[j] + r1*u[j] + r1*v[j] +
243 >                                        .001*co->ad[j];
244  
245                                          /* send sample */
246 <                    raysamp(distarr+dim[1]*nazi+dim[2], org, dir, rt);
246 >                    raysamp(distarr+3*(dim[1]*nazi+dim[2]), org, dir, rt);
247                  }
248          rayflush(rt);
249 <                                /* write out the distribution */
250 <        flatdist(distarr, nalt, nazi, il, ob);
249 >                                /* write out the ring w/ distribution */
250 >        flatout(il, distarr, nalt, nazi, u, v, co->ad);
251 >        illumout(il, ob);
252                                  /* clean up */
253          freecone(ob);
254          free((char *)distarr);
# Line 306 | Line 292 | register struct rtproc  *rt;
292                  rt->dest[i][2] += rt->buf[3*i+2];
293          }
294          rt->nrays = 0;
295 + }
296 +
297 +
298 + mkaxes(u, v, n)                 /* compute u and v to go with n */
299 + FVECT  u, v, n;
300 + {
301 +        register int  i;
302 +
303 +        v[0] = v[1] = v[2] = 0.0;
304 +        for (i = 0; i < 3; i++)
305 +                if (n[i] < 0.6 && n[i] > -0.6)
306 +                        break;
307 +        v[i] = 1.0;
308 +        fcross(u, v, n);
309 +        normalize(u);
310 +        fcross(v, n, u);
311 + }
312 +
313 +
314 + rounddir(dv, alt, azi)          /* compute uniform spherical direction */
315 + register FVECT  dv;
316 + double  alt, azi;
317 + {
318 +        double  d1, d2;
319 +
320 +        dv[2] = 1. - 2.*alt;
321 +        d1 = sqrt(1. - dv[2]*dv[2]);
322 +        d2 = 2.*PI * azi;
323 +        dv[0] = d1*cos(d2);
324 +        dv[1] = d1*sin(d2);
325 + }
326 +
327 +
328 + flatdir(dv, alt, azi)           /* compute uniform hemispherical direction */
329 + register FVECT  dv;
330 + double  alt, azi;
331 + {
332 +        double  d1, d2;
333 +
334 +        d1 = sqrt(alt);
335 +        d2 = 2.*PI * azi;
336 +        dv[0] = d1*cos(d2);
337 +        dv[1] = d1*sin(d2);
338 +        dv[2] = sqrt(1. - alt);
339   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines