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.11 by greg, Thu Aug 22 12:12:23 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])/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);
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);
# Line 130 | 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, r3;
139 >        double  sp[4], r1, r2, r3;
140          FVECT  org, dir;
141          FVECT  u, v;
142          register int  i, j;
# Line 141 | Line 144 | char  *nm;
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 151 | Line 158 | char  *nm;
158          dim[0] = random();
159                                  /* sample sphere */
160          for (dim[1] = 0; dim[1] < nalt; dim[1]++)
161 <            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 <                }
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;
163 <                    dim[3] = 2;
164 <                    r2 = (dim[2]+urand(urind(ilhash(dim,4),i)))/nazi;
166 >                    r1 = (dim[1] + sp[0])/nalt;
167 >                    r2 = (dim[2] + sp[1])/nazi;
168                      rounddir(dir, r1, r2);
169                                          /* random location */
170 <                    if (il->nsamps <= 2 || nazi <= 20)
171 <                        mkaxes(u, v, dir);              /* yuck! */
172 <                    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));
170 >                    mkaxes(u, v, dir);          /* yuck! */
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);
# Line 179 | Line 179 | char  *nm;
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            }
184          rayflush(rt);
185 <                                /* write out the sphere w/ distribution */
186 <        roundout(il, distarr, nalt, nazi);
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);
# Line 197 | 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, r3;
206 >        double  sp[4], r1, r2, r3;
207          FVECT  dn, org, dir;
208          FVECT  u, v;
209          register CONE  *co;
# Line 208 | Line 211 | char  *nm;
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 221 | 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;
227 <                    dim[3] = 2;
228 <                    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];
239                                          /* random location */
233                    dim[3] = 3;
240                      r3 = sqrt(CO_R0(co)*CO_R0(co) +
241 <                                urand(urind(ilhash(dim,4),i))*
242 <                                (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));
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++)
# Line 243 | Line 247 | char  *nm;
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 ring w/ distribution */
254 <        flatout(il, distarr, nalt, nazi, u, v, co->ad);
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);
# Line 278 | Line 284 | register struct rtproc  *rt;
284  
285          if (rt->nrays <= 0)
286                  return;
287 <        i = 6*rt->nrays + 3;
282 <        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)) <

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines