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.6 by greg, Thu Jul 25 12:52:18 1991 UTC vs.
Revision 1.13 by greg, Mon Aug 26 10:16:56 1991 UTC

# Line 38 | 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;
44 >        double  sp[2], r1, r2;
45          FVECT  dn, org, dir;
46          FVECT  u, v;
47          double  ur[2], vr[2];
# Line 56 | 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 81 | 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)))/nazi;
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] - .5)/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];
95                                          /* random location */
96                      do {
97 <                        dim[3] = 3;
98 <                        r1 = ur[0] + (ur[1]-ur[0]) *
99 <                                        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));
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 111 | 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 face w/ distribution */
119 <        flatout(il, distarr, nalt, nazi, u, v, fa->norm);
120 <        illumout(il, ob);
118 >                                /* write out the face and its distribution */
119 >        if (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 >        } else if (!(il->flags & IL_LIGHT))
124 >                printobj(il->altmat, ob);
125                                  /* clean up */
126          freeface(ob);
127          free((char *)distarr);
# Line 130 | Line 135 | struct illum_args  *il;
135   struct rtproc  *rt;
136   char  *nm;
137   {
138 <        int  dim[4];
138 >        int  dim[3];
139          int  n, nalt, nazi;
140          float  *distarr;
141 <        double  r1, r2, r3;
141 >        double  sp[4], r1, r2, r3;
142          FVECT  org, dir;
143          FVECT  u, v;
144          register int  i, j;
# Line 141 | Line 146 | char  *nm;
146          if (ob->oargs.nfargs != 4)
147                  objerror(ob, USER, "bad # of arguments");
148                                  /* set up sampling */
149 <        n = 4.*PI * il->sampdens;
150 <        nalt = sqrt(n/PI) + .5;
151 <        nazi = PI*nalt + .5;
149 >        if (il->sampdens <= 0)
150 >                nalt = nazi = 1;
151 >        else {
152 >                n = 4.*PI * il->sampdens;
153 >                nalt = sqrt(n/PI) + .5;
154 >                nazi = PI*nalt + .5;
155 >        }
156          n = nalt*nazi;
157          distarr = (float *)calloc(n, 3*sizeof(float));
158          if (distarr == NULL)
# Line 151 | Line 160 | char  *nm;
160          dim[0] = random();
161                                  /* sample sphere */
162          for (dim[1] = 0; dim[1] < nalt; dim[1]++)
163 <            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 <                }
163 >            for (dim[2] = 0; dim[2] < nazi; dim[2]++)
164                  for (i = 0; i < il->nsamps; i++) {
165 +                                        /* next sample point */
166 +                    multisamp(sp, 4, urand(ilhash(dim,3)+i));
167                                          /* random direction */
168 <                    dim[3] = 1;
169 <                    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;
168 >                    r1 = (dim[1] + sp[0])/nalt;
169 >                    r2 = (dim[2] + sp[1] - .5)/nazi;
170                      rounddir(dir, r1, r2);
171                                          /* random location */
172 <                    if (il->nsamps <= 2 || nazi <= 20)
173 <                        mkaxes(u, v, dir);              /* yuck! */
174 <                    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));
172 >                    mkaxes(u, v, dir);          /* yuck! */
173 >                    r3 = sqrt(sp[2]);
174 >                    r2 = 2.*PI*sp[3];
175                      r1 = r3*ob->oargs.farg[3]*cos(r2);
176                      r2 = r3*ob->oargs.farg[3]*sin(r2);
177                      r3 = ob->oargs.farg[3]*sqrt(1.01-r3*r3);
# Line 179 | Line 181 | char  *nm;
181                          dir[j] = -dir[j];
182                      }
183                                          /* send sample */
184 <                    raysamp(distarr+dim[1]*nazi+dim[2], org, dir, rt);
184 >                    raysamp(distarr+3*(dim[1]*nazi+dim[2]), org, dir, rt);
185                  }
184            }
186          rayflush(rt);
187 <                                /* write out the sphere w/ distribution */
188 <        roundout(il, distarr, nalt, nazi);
189 <        illumout(il, ob);
187 >                                /* write out the sphere and its distribution */
188 >        if (average(il, distarr, nalt*nazi)) {
189 >                if (il->sampdens > 0)
190 >                        roundout(il, distarr, nalt, nazi);
191 >                else
192 >                        objerror(ob, WARNING, "diffuse distribution");
193 >                illumout(il, ob);
194 >        } else if (!(il->flags & IL_LIGHT))
195 >                printobj(il->altmat, ob);
196                                  /* clean up */
197          free((char *)distarr);
198   }
# Line 197 | Line 204 | struct illum_args  *il;
204   struct rtproc  *rt;
205   char  *nm;
206   {
207 <        int  dim[4];
207 >        int  dim[3];
208          int  n, nalt, nazi;
209          float  *distarr;
210 <        double  r1, r2, r3;
210 >        double  sp[4], r1, r2, r3;
211          FVECT  dn, org, dir;
212          FVECT  u, v;
213          register CONE  *co;
# Line 208 | Line 215 | char  *nm;
215                                  /* get/check arguments */
216          co = getcone(ob, 0);
217                                  /* set up sampling */
218 <        n = PI * il->sampdens;
219 <        nalt = sqrt(n/PI) + .5;
220 <        nazi = PI*nalt + .5;
218 >        if (il->sampdens <= 0)
219 >                nalt = nazi = 1;
220 >        else {
221 >                n = PI * il->sampdens;
222 >                nalt = sqrt(n/PI) + .5;
223 >                nazi = PI*nalt + .5;
224 >        }
225          n = nalt*nazi;
226          distarr = (float *)calloc(n, 3*sizeof(float));
227          if (distarr == NULL)
# Line 221 | Line 232 | char  *nm;
232          for (dim[1] = 0; dim[1] < nalt; dim[1]++)
233              for (dim[2] = 0; dim[2] < nazi; dim[2]++)
234                  for (i = 0; i < il->nsamps; i++) {
235 +                                        /* next sample point */
236 +                    multisamp(sp, 4, urand(ilhash(dim,3)+i));
237                                          /* random direction */
238 <                    dim[3] = 1;
239 <                    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;
238 >                    r1 = (dim[1] + sp[0])/nalt;
239 >                    r2 = (dim[2] + sp[1] - .5)/nazi;
240                      flatdir(dn, r1, r2);
241                      for (j = 0; j < 3; j++)
242                          dir[j] = -dn[0]*u[j] - dn[1]*v[j] - dn[2]*co->ad[j];
243                                          /* random location */
233                    dim[3] = 3;
244                      r3 = sqrt(CO_R0(co)*CO_R0(co) +
245 <                                urand(urind(ilhash(dim,4),i))*
246 <                                (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));
245 >                            sp[2]*(CO_R1(co)*CO_R1(co) - CO_R0(co)*CO_R0(co)));
246 >                    r2 = 2.*PI*sp[3];
247                      r1 = r3*cos(r2);
248                      r2 = r3*sin(r2);
249                      for (j = 0; j < 3; j++)
# Line 243 | Line 251 | char  *nm;
251                                          .001*co->ad[j];
252  
253                                          /* send sample */
254 <                    raysamp(distarr+dim[1]*nazi+dim[2], org, dir, rt);
254 >                    raysamp(distarr+3*(dim[1]*nazi+dim[2]), org, dir, rt);
255                  }
256          rayflush(rt);
257 <                                /* write out the ring w/ distribution */
258 <        flatout(il, distarr, nalt, nazi, u, v, co->ad);
259 <        illumout(il, ob);
257 >                                /* write out the ring and its distribution */
258 >        if (average(il, distarr, nalt*nazi)) {
259 >                if (il->sampdens > 0)
260 >                        flatout(il, distarr, nalt, nazi, u, v, co->ad);
261 >                illumout(il, ob);
262 >        } else if (!(il->flags & IL_LIGHT))
263 >                printobj(il->altmat, ob);
264                                  /* clean up */
265          freecone(ob);
266          free((char *)distarr);
# Line 278 | Line 290 | register struct rtproc  *rt;
290  
291          if (rt->nrays <= 0)
292                  return;
293 <        i = 6*rt->nrays + 3;
282 <        rt->buf[i++] = 0.; rt->buf[i++] = 0.; rt->buf[i] = 0.;
293 >        bzero(rt->buf+6*rt->nrays, 6*sizeof(float));
294          if ( process(rt->pd, (char *)rt->buf, (char *)rt->buf,
295                          3*sizeof(float)*rt->nrays,
296                          6*sizeof(float)*(rt->nrays+1)) <

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines