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.11 by greg, Thu Aug 22 12:12:23 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 65 | Line 38 | struct rtproc  *rt;
38   char  *nm;
39   {
40   #define MAXMISS         (5*n*il->nsamps)
41 <        int  dim[4];
42 <        int  n, nalt, nazi;
41 >        int  dim[3];
42 >        int  n, nalt, nazi, h;
43          float  *distarr;
44 <        double  r1, r2;
45 <        FVECT  dn, pos, dir;
44 >        double  sp[2], r1, r2;
45 >        FVECT  dn, org, dir;
46          FVECT  u, v;
47          double  ur[2], vr[2];
48          int  nmisses;
# Line 83 | Line 56 | char  *nm;
56                  return;
57          }
58                                  /* set up sampling */
59 <        n = PI * il->sampdens;
60 <        nalt = sqrt(n/PI) + .5;
61 <        nazi = PI*nalt + .5;
59 >        if (il->sampdens <= 0)
60 >                nalt = nazi = 1;
61 >        else {
62 >                n = PI * il->sampdens;
63 >                nalt = sqrt(n/PI) + .5;
64 >                nazi = PI*nalt + .5;
65 >        }
66          n = nalt*nazi;
67          distarr = (float *)calloc(n, 3*sizeof(float));
68          if (distarr == NULL)
# Line 108 | Line 85 | char  *nm;
85              for (dim[2] = 0; dim[2] < nazi; dim[2]++)
86                  for (i = 0; i < il->nsamps; i++) {
87                                          /* random direction */
88 <                    dim[3] = 1;
89 <                    r1 = (dim[1]+urand(urind(ilhash(dim,4),i)))/nalt;
90 <                    dim[3] = 2;
91 <                    r2 = (dim[2]+urand(urind(ilhash(dim,4),i)))/nalt;
88 >                    h = ilhash(dim, 3) + i;
89 >                    multisamp(sp, 2, urand(h));
90 >                    r1 = (dim[1] + sp[0])/nalt;
91 >                    r2 = (dim[2] + sp[1])/nazi;
92                      flatdir(dn, r1, r2);
93                      for (j = 0; j < 3; j++)
94 <                        dir[j] = dn[0]*u[j] + dn[1]*v[j] - dn[2]*fa->norm[j];
94 >                        dir[j] = -dn[0]*u[j] - dn[1]*v[j] - dn[2]*fa->norm[j];
95                                          /* random location */
96                      do {
97 <                        dim[3] = 3;
98 <                        r1 = ur[0] +
99 <                                (ur[1]-ur[0])*urand(urind(ilhash(dim,4),i));
123 <                        dim[3] = 4;
124 <                        r2 = vr[0] +
125 <                                (vr[1]-vr[0])*urand(urind(ilhash(dim,4),i));
97 >                        multisamp(sp, 2, urand(h+4862+nmisses));
98 >                        r1 = ur[0] + (ur[1]-ur[0]) * sp[0];
99 >                        r2 = vr[0] + (vr[1]-vr[0]) * sp[1];
100                          for (j = 0; j < 3; j++)
101                              org[j] = r1*u[j] + r2*v[j]
102                                          + fa->offset*fa->norm[j];
# Line 138 | Line 112 | char  *nm;
112                      for (j = 0; j < 3; j++)
113                          org[j] += .001*fa->norm[j];
114                                          /* send sample */
115 <                    raysamp(distarr+dim[1]*nazi+dim[2], org, dir, rt);
115 >                    raysamp(distarr+3*(dim[1]*nazi+dim[2]), org, dir, rt);
116                  }
117          rayflush(rt);
118 <                                /* write out the distribution */
119 <        flatdist(distarr, nalt, nazi, il, ob);
118 >                                /* write out the face and its distribution */
119 >        average(il, distarr, nalt*nazi);
120 >        if (il->sampdens > 0)
121 >                flatout(il, distarr, nalt, nazi, u, v, fa->norm);
122 >        illumout(il, ob);
123                                  /* clean up */
124          freeface(ob);
125          free((char *)distarr);
# Line 156 | Line 133 | struct illum_args  *il;
133   struct rtproc  *rt;
134   char  *nm;
135   {
136 <        int  dim[4];
136 >        int  dim[3];
137          int  n, nalt, nazi;
138          float  *distarr;
139 <        double  r1, r2;
140 <        FVECT  pos, dir;
139 >        double  sp[4], r1, r2, r3;
140 >        FVECT  org, dir;
141          FVECT  u, v;
142          register int  i, j;
143                                  /* check arguments */
144          if (ob->oargs.nfargs != 4)
145                  objerror(ob, USER, "bad # of arguments");
146                                  /* set up sampling */
147 <        n = 4.*PI * il->sampdens;
148 <        nalt = sqrt(n/PI) + .5;
149 <        nazi = PI*nalt + .5;
147 >        if (il->sampdens <= 0)
148 >                nalt = nazi = 1;
149 >        else {
150 >                n = 4.*PI * il->sampdens;
151 >                nalt = sqrt(n/PI) + .5;
152 >                nazi = PI*nalt + .5;
153 >        }
154          n = nalt*nazi;
155          distarr = (float *)calloc(n, 3*sizeof(float));
156          if (distarr == NULL)
# Line 179 | Line 160 | char  *nm;
160          for (dim[1] = 0; dim[1] < nalt; dim[1]++)
161              for (dim[2] = 0; dim[2] < nazi; dim[2]++)
162                  for (i = 0; i < il->nsamps; i++) {
163 +                                        /* next sample point */
164 +                    multisamp(sp, 4, urand(ilhash(dim,3)+i));
165                                          /* random direction */
166 <                    dim[3] = 1;
167 <                    r1 = (dim[1]+urand(urind(ilhash(dim,4),i)))/nalt;
185 <                    dim[3] = 2;
186 <                    r2 = (dim[2]+urand(urind(ilhash(dim,4),i)))/nalt;
166 >                    r1 = (dim[1] + sp[0])/nalt;
167 >                    r2 = (dim[2] + sp[1])/nazi;
168                      rounddir(dir, r1, r2);
169                                          /* random location */
170                      mkaxes(u, v, dir);          /* yuck! */
171 <                    dim[3] = 3;
172 <                    r1 = sqrt(urand(urind(ilhash(dim,4),i)));
173 <                    dim[3] = 4;
174 <                    r2 = 2.*PI*urand(urind(ilhash(dim,4),i));
175 <                    for (j = 0; j < 3; j++)
176 <                        org[j] = obj->oargs.farg[j] + obj->oargs.farg[3] *
177 <                                        ( r1*cos(r2)*u[j] + r1*sin(r2)*v[j]
178 <                                                - sqrt(1.01-r1*r1)*dir[j] );
179 <
171 >                    r3 = sqrt(sp[2]);
172 >                    r2 = 2.*PI*sp[3];
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          rayflush(rt);
185 <                                /* write out the distribution */
186 <        rounddist(distarr, nalt, nazi, il, ob);
185 >                                /* write out the sphere and its distribution */
186 >        average(il, distarr, nalt*nazi);
187 >        if (il->sampdens > 0)
188 >                roundout(il, distarr, nalt, nazi);
189 >        else
190 >                objerror(ob, WARNING, "diffuse distribution");
191 >        illumout(il, ob);
192                                  /* clean up */
193          free((char *)distarr);
194   }
# Line 213 | Line 200 | struct illum_args  *il;
200   struct rtproc  *rt;
201   char  *nm;
202   {
203 <        int  dim[4];
203 >        int  dim[3];
204          int  n, nalt, nazi;
205          float  *distarr;
206 <        double  r1, r2;
207 <        FVECT  dn, pos, dir;
206 >        double  sp[4], r1, r2, r3;
207 >        FVECT  dn, org, dir;
208          FVECT  u, v;
209          register CONE  *co;
210          register int  i, j;
211                                  /* get/check arguments */
212          co = getcone(ob, 0);
213                                  /* set up sampling */
214 <        n = PI * il->sampdens;
215 <        nalt = sqrt(n/PI) + .5;
216 <        nazi = PI*nalt + .5;
214 >        if (il->sampdens <= 0)
215 >                nalt = nazi = 1;
216 >        else {
217 >                n = PI * il->sampdens;
218 >                nalt = sqrt(n/PI) + .5;
219 >                nazi = PI*nalt + .5;
220 >        }
221          n = nalt*nazi;
222          distarr = (float *)calloc(n, 3*sizeof(float));
223          if (distarr == NULL)
# Line 237 | Line 228 | char  *nm;
228          for (dim[1] = 0; dim[1] < nalt; dim[1]++)
229              for (dim[2] = 0; dim[2] < nazi; dim[2]++)
230                  for (i = 0; i < il->nsamps; i++) {
231 +                                        /* next sample point */
232 +                    multisamp(sp, 4, urand(ilhash(dim,3)+i));
233                                          /* random direction */
234 <                    dim[3] = 1;
235 <                    r1 = (dim[1]+urand(urind(ilhash(dim,4),i)))/nalt;
243 <                    dim[3] = 2;
244 <                    r2 = (dim[2]+urand(urind(ilhash(dim,4),i)))/nalt;
234 >                    r1 = (dim[1] + sp[0])/nalt;
235 >                    r2 = (dim[2] + sp[1])/nalt;
236                      flatdir(dn, r1, r2);
237                      for (j = 0; j < 3; j++)
238 <                        dir[j] = dn[0]*u[j] + dn[1]*v[j] - dn[2]*co->ad[j];
238 >                        dir[j] = -dn[0]*u[j] - dn[1]*v[j] - dn[2]*co->ad[j];
239                                          /* random location */
240 <                    dim[3] = 3;
241 <                    r1 = sqrt(CO_R0(co)*CO_R0(co) +
242 <                                urand(urind(ilhash(dim,4),i))*
243 <                                (CO_R1(co)*CO_R1(co) - CO_R0(co)*CO_R0(co)));
244 <                    dim[3] = 4;
254 <                    r2 = 2.*PI*urand(urind(ilhash(dim,4),i));
240 >                    r3 = sqrt(CO_R0(co)*CO_R0(co) +
241 >                            sp[2]*(CO_R1(co)*CO_R1(co) - CO_R0(co)*CO_R0(co)));
242 >                    r2 = 2.*PI*sp[3];
243 >                    r1 = r3*cos(r2);
244 >                    r2 = r3*sin(r2);
245                      for (j = 0; j < 3; j++)
246 <                        org[j] = CO_P0(co)[j] +
247 <                                        r1*cos(r2)*u[j] + r1*sin(r2)*v[j]
258 <                                        + .001*co->ad[j];
246 >                        org[j] = CO_P0(co)[j] + r1*u[j] + r1*v[j] +
247 >                                        .001*co->ad[j];
248  
249                                          /* send sample */
250 <                    raysamp(distarr+dim[1]*nazi+dim[2], org, dir, rt);
250 >                    raysamp(distarr+3*(dim[1]*nazi+dim[2]), org, dir, rt);
251                  }
252          rayflush(rt);
253 <                                /* write out the distribution */
254 <        flatdist(distarr, nalt, nazi, il, ob);
253 >                                /* write out the ring and its distribution */
254 >        average(il, distarr, nalt*nazi);
255 >        if (il->sampdens > 0)
256 >                flatout(il, distarr, nalt, nazi, u, v, co->ad);
257 >        illumout(il, ob);
258                                  /* clean up */
259          freecone(ob);
260          free((char *)distarr);
# Line 292 | Line 284 | register struct rtproc  *rt;
284  
285          if (rt->nrays <= 0)
286                  return;
287 <        i = 6*rt->nrays + 3;
296 <        rt->buf[i++] = 0.; rt->buf[i++] = 0.; rt->buf[i] = 0.;
287 >        bzero(rt->buf+6*rt->nrays, 6*sizeof(float));
288          if ( process(rt->pd, (char *)rt->buf, (char *)rt->buf,
289                          3*sizeof(float)*rt->nrays,
290                          6*sizeof(float)*(rt->nrays+1)) <
# Line 306 | Line 297 | register struct rtproc  *rt;
297                  rt->dest[i][2] += rt->buf[3*i+2];
298          }
299          rt->nrays = 0;
300 + }
301 +
302 +
303 + mkaxes(u, v, n)                 /* compute u and v to go with n */
304 + FVECT  u, v, n;
305 + {
306 +        register int  i;
307 +
308 +        v[0] = v[1] = v[2] = 0.0;
309 +        for (i = 0; i < 3; i++)
310 +                if (n[i] < 0.6 && n[i] > -0.6)
311 +                        break;
312 +        v[i] = 1.0;
313 +        fcross(u, v, n);
314 +        normalize(u);
315 +        fcross(v, n, u);
316 + }
317 +
318 +
319 + rounddir(dv, alt, azi)          /* compute uniform spherical direction */
320 + register FVECT  dv;
321 + double  alt, azi;
322 + {
323 +        double  d1, d2;
324 +
325 +        dv[2] = 1. - 2.*alt;
326 +        d1 = sqrt(1. - dv[2]*dv[2]);
327 +        d2 = 2.*PI * azi;
328 +        dv[0] = d1*cos(d2);
329 +        dv[1] = d1*sin(d2);
330 + }
331 +
332 +
333 + flatdir(dv, alt, azi)           /* compute uniform hemispherical direction */
334 + register FVECT  dv;
335 + double  alt, azi;
336 + {
337 +        double  d1, d2;
338 +
339 +        d1 = sqrt(alt);
340 +        d2 = 2.*PI * azi;
341 +        dv[0] = d1*cos(d2);
342 +        dv[1] = d1*sin(d2);
343 +        dv[2] = sqrt(1. - alt);
344   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines