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.7 by greg, Thu Jul 25 14:12:22 1991 UTC vs.
Revision 2.3 by greg, Wed Aug 12 14:44:15 1992 UTC

# Line 26 | Line 26 | char  *nm;
26          sprintf(errmsg, "(%s): cannot make illum for %s \"%s\"",
27                          nm, ofun[ob->otype].funame, ob->oname);
28          error(WARNING, errmsg);
29 <        if (!(il->flags & IL_LIGHT))
30 <                printobj(il->altmat, ob);
29 >        printobj(il->altmat, ob);
30   }
31  
32  
# Line 38 | Line 37 | struct rtproc  *rt;
37   char  *nm;
38   {
39   #define MAXMISS         (5*n*il->nsamps)
40 <        int  dim[4];
41 <        int  n, nalt, nazi;
40 >        int  dim[3];
41 >        int  n, nalt, nazi, h;
42          float  *distarr;
43 <        double  r1, r2;
43 >        double  sp[2], r1, r2;
44          FVECT  dn, org, dir;
45          FVECT  u, v;
46          double  ur[2], vr[2];
# Line 56 | Line 55 | char  *nm;
55                  return;
56          }
57                                  /* set up sampling */
58 <        n = PI * il->sampdens;
59 <        nalt = sqrt(n/PI) + .5;
60 <        nazi = PI*nalt + .5;
58 >        if (il->sampdens <= 0)
59 >                nalt = nazi = 1;
60 >        else {
61 >                n = PI * il->sampdens;
62 >                nalt = sqrt(n/PI) + .5;
63 >                nazi = PI*nalt + .5;
64 >        }
65          n = nalt*nazi;
66          distarr = (float *)calloc(n, 3*sizeof(float));
67          if (distarr == NULL)
68                  error(SYSTEM, "out of memory in o_face");
69 <        mkaxes(u, v, fa->norm);
69 >                                /* take first edge longer than sqrt(area) */
70 >        for (i = 1; i < fa->nv; i++) {
71 >                for (j = 0; j < 3; j++)
72 >                        u[j] = VERTEX(fa,i)[j] - VERTEX(fa,i-1)[j];
73 >                if (DOT(u,u) >= fa->area-FTINY)
74 >                        break;
75 >        }
76 >        if (i < fa->nv) {       /* got one! -- let's align our axes */
77 >                normalize(u);
78 >                fcross(v, fa->norm, u);
79 >        } else                  /* oh well, we'll just have to wing it */
80 >                mkaxes(u, v, fa->norm);
81 >                                /* now, find limits in (u,v) coordinates */
82          ur[0] = vr[0] = FHUGE;
83          ur[1] = vr[1] = -FHUGE;
84          for (i = 0; i < fa->nv; i++) {
# Line 81 | Line 96 | char  *nm;
96              for (dim[2] = 0; dim[2] < nazi; dim[2]++)
97                  for (i = 0; i < il->nsamps; i++) {
98                                          /* random direction */
99 <                    dim[3] = 1;
100 <                    r1 = (dim[1]+urand(urind(ilhash(dim,4),i)))/nalt;
101 <                    dim[3] = 2;
102 <                    r2 = (dim[2]+urand(urind(ilhash(dim,4),i)))/nazi;
99 >                    h = ilhash(dim, 3) + i;
100 >                    multisamp(sp, 2, urand(h));
101 >                    r1 = (dim[1] + sp[0])/nalt;
102 >                    r2 = (dim[2] + sp[1] - .5)/nazi;
103                      flatdir(dn, r1, r2);
104                      for (j = 0; j < 3; j++)
105                          dir[j] = -dn[0]*u[j] - dn[1]*v[j] - dn[2]*fa->norm[j];
106                                          /* random location */
107                      do {
108 <                        dim[3] = 3;
109 <                        r1 = ur[0] + (ur[1]-ur[0]) *
110 <                                        urand(urind(ilhash(dim,4),i+nmisses));
96 <                        dim[3] = 4;
97 <                        r2 = vr[0] + (vr[1]-vr[0]) *
98 <                                        urand(urind(ilhash(dim,4),i+nmisses));
108 >                        multisamp(sp, 2, urand(h+4862+nmisses));
109 >                        r1 = ur[0] + (ur[1]-ur[0]) * sp[0];
110 >                        r2 = vr[0] + (vr[1]-vr[0]) * sp[1];
111                          for (j = 0; j < 3; j++)
112                              org[j] = r1*u[j] + r2*v[j]
113                                          + fa->offset*fa->norm[j];
# Line 114 | Line 126 | char  *nm;
126                      raysamp(distarr+3*(dim[1]*nazi+dim[2]), org, dir, rt);
127                  }
128          rayflush(rt);
129 <                                /* write out the face w/ distribution */
130 <        flatout(il, distarr, nalt, nazi, u, v, fa->norm);
131 <        illumout(il, ob);
129 >                                /* write out the face and its distribution */
130 >        if (average(il, distarr, nalt*nazi)) {
131 >                if (il->sampdens > 0)
132 >                        flatout(il, distarr, nalt, nazi, u, v, fa->norm);
133 >                illumout(il, ob);
134 >        } else
135 >                printobj(il->altmat, ob);
136                                  /* clean up */
137          freeface(ob);
138          free((char *)distarr);
# Line 130 | Line 146 | struct illum_args  *il;
146   struct rtproc  *rt;
147   char  *nm;
148   {
149 <        int  dim[4];
149 >        int  dim[3];
150          int  n, nalt, nazi;
151          float  *distarr;
152 <        double  r1, r2, r3;
152 >        double  sp[4], r1, r2, r3;
153          FVECT  org, dir;
154          FVECT  u, v;
155          register int  i, j;
# Line 141 | Line 157 | char  *nm;
157          if (ob->oargs.nfargs != 4)
158                  objerror(ob, USER, "bad # of arguments");
159                                  /* set up sampling */
160 <        n = 4.*PI * il->sampdens;
161 <        nalt = sqrt(n/PI) + .5;
162 <        nazi = PI*nalt + .5;
160 >        if (il->sampdens <= 0)
161 >                nalt = nazi = 1;
162 >        else {
163 >                n = 4.*PI * il->sampdens;
164 >                nalt = sqrt(n/PI) + .5;
165 >                nazi = PI*nalt + .5;
166 >        }
167          n = nalt*nazi;
168          distarr = (float *)calloc(n, 3*sizeof(float));
169          if (distarr == NULL)
# Line 151 | Line 171 | char  *nm;
171          dim[0] = random();
172                                  /* sample sphere */
173          for (dim[1] = 0; dim[1] < nalt; dim[1]++)
174 <            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 <                }
174 >            for (dim[2] = 0; dim[2] < nazi; dim[2]++)
175                  for (i = 0; i < il->nsamps; i++) {
176 +                                        /* next sample point */
177 +                    multisamp(sp, 4, urand(ilhash(dim,3)+i));
178                                          /* random direction */
179 <                    dim[3] = 1;
180 <                    r1 = (dim[1]+urand(urind(ilhash(dim,4),i)))/nalt;
163 <                    dim[3] = 2;
164 <                    r2 = (dim[2]+urand(urind(ilhash(dim,4),i)))/nazi;
179 >                    r1 = (dim[1] + sp[0])/nalt;
180 >                    r2 = (dim[2] + sp[1] - .5)/nazi;
181                      rounddir(dir, r1, r2);
182                                          /* random location */
183 <                    if (il->nsamps <= 2 || nazi <= 20)
184 <                        mkaxes(u, v, dir);              /* yuck! */
185 <                    dim[3] = 3;
170 <                    r3 = sqrt(urand(urind(ilhash(dim,4),i)));
171 <                    dim[3] = 4;
172 <                    r2 = 2.*PI*urand(urind(ilhash(dim,4),i));
183 >                    mkaxes(u, v, dir);          /* yuck! */
184 >                    r3 = sqrt(sp[2]);
185 >                    r2 = 2.*PI*sp[3];
186                      r1 = r3*ob->oargs.farg[3]*cos(r2);
187                      r2 = r3*ob->oargs.farg[3]*sin(r2);
188                      r3 = ob->oargs.farg[3]*sqrt(1.01-r3*r3);
# Line 181 | Line 194 | char  *nm;
194                                          /* send sample */
195                      raysamp(distarr+3*(dim[1]*nazi+dim[2]), org, dir, rt);
196                  }
184            }
197          rayflush(rt);
198 <                                /* write out the sphere w/ distribution */
199 <        roundout(il, distarr, nalt, nazi);
200 <        illumout(il, ob);
198 >                                /* write out the sphere and its distribution */
199 >        if (average(il, distarr, nalt*nazi)) {
200 >                if (il->sampdens > 0)
201 >                        roundout(il, distarr, nalt, nazi);
202 >                else
203 >                        objerror(ob, WARNING, "diffuse distribution");
204 >                illumout(il, ob);
205 >        } else
206 >                printobj(il->altmat, ob);
207                                  /* clean up */
208          free((char *)distarr);
209   }
# Line 197 | Line 215 | struct illum_args  *il;
215   struct rtproc  *rt;
216   char  *nm;
217   {
218 <        int  dim[4];
218 >        int  dim[3];
219          int  n, nalt, nazi;
220          float  *distarr;
221 <        double  r1, r2, r3;
221 >        double  sp[4], r1, r2, r3;
222          FVECT  dn, org, dir;
223          FVECT  u, v;
224          register CONE  *co;
# Line 208 | Line 226 | char  *nm;
226                                  /* get/check arguments */
227          co = getcone(ob, 0);
228                                  /* set up sampling */
229 <        n = PI * il->sampdens;
230 <        nalt = sqrt(n/PI) + .5;
231 <        nazi = PI*nalt + .5;
229 >        if (il->sampdens <= 0)
230 >                nalt = nazi = 1;
231 >        else {
232 >                n = PI * il->sampdens;
233 >                nalt = sqrt(n/PI) + .5;
234 >                nazi = PI*nalt + .5;
235 >        }
236          n = nalt*nazi;
237          distarr = (float *)calloc(n, 3*sizeof(float));
238          if (distarr == NULL)
# Line 221 | Line 243 | char  *nm;
243          for (dim[1] = 0; dim[1] < nalt; dim[1]++)
244              for (dim[2] = 0; dim[2] < nazi; dim[2]++)
245                  for (i = 0; i < il->nsamps; i++) {
246 +                                        /* next sample point */
247 +                    multisamp(sp, 4, urand(ilhash(dim,3)+i));
248                                          /* random direction */
249 <                    dim[3] = 1;
250 <                    r1 = (dim[1]+urand(urind(ilhash(dim,4),i)))/nalt;
227 <                    dim[3] = 2;
228 <                    r2 = (dim[2]+urand(urind(ilhash(dim,4),i)))/nalt;
249 >                    r1 = (dim[1] + sp[0])/nalt;
250 >                    r2 = (dim[2] + sp[1] - .5)/nazi;
251                      flatdir(dn, r1, r2);
252                      for (j = 0; j < 3; j++)
253                          dir[j] = -dn[0]*u[j] - dn[1]*v[j] - dn[2]*co->ad[j];
254                                          /* random location */
233                    dim[3] = 3;
255                      r3 = sqrt(CO_R0(co)*CO_R0(co) +
256 <                                urand(urind(ilhash(dim,4),i))*
257 <                                (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));
256 >                            sp[2]*(CO_R1(co)*CO_R1(co) - CO_R0(co)*CO_R0(co)));
257 >                    r2 = 2.*PI*sp[3];
258                      r1 = r3*cos(r2);
259                      r2 = r3*sin(r2);
260                      for (j = 0; j < 3; j++)
# Line 246 | Line 265 | char  *nm;
265                      raysamp(distarr+3*(dim[1]*nazi+dim[2]), org, dir, rt);
266                  }
267          rayflush(rt);
268 <                                /* write out the ring w/ distribution */
269 <        flatout(il, distarr, nalt, nazi, u, v, co->ad);
270 <        illumout(il, ob);
268 >                                /* write out the ring and its distribution */
269 >        if (average(il, distarr, nalt*nazi)) {
270 >                if (il->sampdens > 0)
271 >                        flatout(il, distarr, nalt, nazi, u, v, co->ad);
272 >                illumout(il, ob);
273 >        } else
274 >                printobj(il->altmat, ob);
275                                  /* clean up */
276          freecone(ob);
277          free((char *)distarr);
# Line 278 | Line 301 | register struct rtproc  *rt;
301  
302          if (rt->nrays <= 0)
303                  return;
304 <        i = 6*rt->nrays + 3;
305 <        rt->buf[i++] = 0.; rt->buf[i++] = 0.; rt->buf[i] = 0.;
304 >        bzero(rt->buf+6*rt->nrays, 6*sizeof(float));
305 >        errno = 0;
306          if ( process(rt->pd, (char *)rt->buf, (char *)rt->buf,
307                          3*sizeof(float)*rt->nrays,
308                          6*sizeof(float)*(rt->nrays+1)) <

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines