--- ray/src/gen/mkillum2.c 1991/07/25 12:52:18 1.6 +++ ray/src/gen/mkillum2.c 1992/03/11 12:25:47 2.2 @@ -26,8 +26,7 @@ char *nm; sprintf(errmsg, "(%s): cannot make illum for %s \"%s\"", nm, ofun[ob->otype].funame, ob->oname); error(WARNING, errmsg); - if (!(il->flags & IL_LIGHT)) - printobj(il->altmat, ob); + printobj(il->altmat, ob); } @@ -38,10 +37,10 @@ struct rtproc *rt; char *nm; { #define MAXMISS (5*n*il->nsamps) - int dim[4]; - int n, nalt, nazi; + int dim[3]; + int n, nalt, nazi, h; float *distarr; - double r1, r2; + double sp[2], r1, r2; FVECT dn, org, dir; FVECT u, v; double ur[2], vr[2]; @@ -56,9 +55,13 @@ char *nm; return; } /* set up sampling */ - n = PI * il->sampdens; - nalt = sqrt(n/PI) + .5; - nazi = PI*nalt + .5; + if (il->sampdens <= 0) + nalt = nazi = 1; + else { + n = PI * il->sampdens; + nalt = sqrt(n/PI) + .5; + nazi = PI*nalt + .5; + } n = nalt*nazi; distarr = (float *)calloc(n, 3*sizeof(float)); if (distarr == NULL) @@ -81,21 +84,18 @@ char *nm; for (dim[2] = 0; dim[2] < nazi; dim[2]++) for (i = 0; i < il->nsamps; i++) { /* random direction */ - dim[3] = 1; - r1 = (dim[1]+urand(urind(ilhash(dim,4),i)))/nalt; - dim[3] = 2; - r2 = (dim[2]+urand(urind(ilhash(dim,4),i)))/nazi; + h = ilhash(dim, 3) + i; + multisamp(sp, 2, urand(h)); + r1 = (dim[1] + sp[0])/nalt; + r2 = (dim[2] + sp[1] - .5)/nazi; flatdir(dn, r1, r2); for (j = 0; j < 3; j++) dir[j] = -dn[0]*u[j] - dn[1]*v[j] - dn[2]*fa->norm[j]; /* random location */ do { - dim[3] = 3; - r1 = ur[0] + (ur[1]-ur[0]) * - urand(urind(ilhash(dim,4),i+nmisses)); - dim[3] = 4; - r2 = vr[0] + (vr[1]-vr[0]) * - urand(urind(ilhash(dim,4),i+nmisses)); + multisamp(sp, 2, urand(h+4862+nmisses)); + r1 = ur[0] + (ur[1]-ur[0]) * sp[0]; + r2 = vr[0] + (vr[1]-vr[0]) * sp[1]; for (j = 0; j < 3; j++) org[j] = r1*u[j] + r2*v[j] + fa->offset*fa->norm[j]; @@ -111,12 +111,16 @@ char *nm; for (j = 0; j < 3; j++) org[j] += .001*fa->norm[j]; /* send sample */ - raysamp(distarr+dim[1]*nazi+dim[2], org, dir, rt); + raysamp(distarr+3*(dim[1]*nazi+dim[2]), org, dir, rt); } rayflush(rt); - /* write out the face w/ distribution */ - flatout(il, distarr, nalt, nazi, u, v, fa->norm); - illumout(il, ob); + /* write out the face and its distribution */ + if (average(il, distarr, nalt*nazi)) { + if (il->sampdens > 0) + flatout(il, distarr, nalt, nazi, u, v, fa->norm); + illumout(il, ob); + } else + printobj(il->altmat, ob); /* clean up */ freeface(ob); free((char *)distarr); @@ -130,10 +134,10 @@ struct illum_args *il; struct rtproc *rt; char *nm; { - int dim[4]; + int dim[3]; int n, nalt, nazi; float *distarr; - double r1, r2, r3; + double sp[4], r1, r2, r3; FVECT org, dir; FVECT u, v; register int i, j; @@ -141,9 +145,13 @@ char *nm; if (ob->oargs.nfargs != 4) objerror(ob, USER, "bad # of arguments"); /* set up sampling */ - n = 4.*PI * il->sampdens; - nalt = sqrt(n/PI) + .5; - nazi = PI*nalt + .5; + if (il->sampdens <= 0) + nalt = nazi = 1; + else { + n = 4.*PI * il->sampdens; + nalt = sqrt(n/PI) + .5; + nazi = PI*nalt + .5; + } n = nalt*nazi; distarr = (float *)calloc(n, 3*sizeof(float)); if (distarr == NULL) @@ -151,25 +159,18 @@ char *nm; dim[0] = random(); /* sample sphere */ for (dim[1] = 0; dim[1] < nalt; dim[1]++) - for (dim[2] = 0; dim[2] < nazi; dim[2]++) { - if (il->nsamps > 2 && nazi > 20) { - rounddir(dir, (dim[1]+.5)/nalt, (dim[2]+.5)/nazi); - mkaxes(u, v, dir); - } + for (dim[2] = 0; dim[2] < nazi; dim[2]++) for (i = 0; i < il->nsamps; i++) { + /* next sample point */ + multisamp(sp, 4, urand(ilhash(dim,3)+i)); /* random direction */ - dim[3] = 1; - r1 = (dim[1]+urand(urind(ilhash(dim,4),i)))/nalt; - dim[3] = 2; - r2 = (dim[2]+urand(urind(ilhash(dim,4),i)))/nazi; + r1 = (dim[1] + sp[0])/nalt; + r2 = (dim[2] + sp[1] - .5)/nazi; rounddir(dir, r1, r2); /* random location */ - if (il->nsamps <= 2 || nazi <= 20) - mkaxes(u, v, dir); /* yuck! */ - dim[3] = 3; - r3 = sqrt(urand(urind(ilhash(dim,4),i))); - dim[3] = 4; - r2 = 2.*PI*urand(urind(ilhash(dim,4),i)); + mkaxes(u, v, dir); /* yuck! */ + r3 = sqrt(sp[2]); + r2 = 2.*PI*sp[3]; r1 = r3*ob->oargs.farg[3]*cos(r2); r2 = r3*ob->oargs.farg[3]*sin(r2); r3 = ob->oargs.farg[3]*sqrt(1.01-r3*r3); @@ -179,13 +180,18 @@ char *nm; dir[j] = -dir[j]; } /* send sample */ - raysamp(distarr+dim[1]*nazi+dim[2], org, dir, rt); + raysamp(distarr+3*(dim[1]*nazi+dim[2]), org, dir, rt); } - } rayflush(rt); - /* write out the sphere w/ distribution */ - roundout(il, distarr, nalt, nazi); - illumout(il, ob); + /* write out the sphere and its distribution */ + if (average(il, distarr, nalt*nazi)) { + if (il->sampdens > 0) + roundout(il, distarr, nalt, nazi); + else + objerror(ob, WARNING, "diffuse distribution"); + illumout(il, ob); + } else + printobj(il->altmat, ob); /* clean up */ free((char *)distarr); } @@ -197,10 +203,10 @@ struct illum_args *il; struct rtproc *rt; char *nm; { - int dim[4]; + int dim[3]; int n, nalt, nazi; float *distarr; - double r1, r2, r3; + double sp[4], r1, r2, r3; FVECT dn, org, dir; FVECT u, v; register CONE *co; @@ -208,9 +214,13 @@ char *nm; /* get/check arguments */ co = getcone(ob, 0); /* set up sampling */ - n = PI * il->sampdens; - nalt = sqrt(n/PI) + .5; - nazi = PI*nalt + .5; + if (il->sampdens <= 0) + nalt = nazi = 1; + else { + n = PI * il->sampdens; + nalt = sqrt(n/PI) + .5; + nazi = PI*nalt + .5; + } n = nalt*nazi; distarr = (float *)calloc(n, 3*sizeof(float)); if (distarr == NULL) @@ -221,21 +231,18 @@ char *nm; for (dim[1] = 0; dim[1] < nalt; dim[1]++) for (dim[2] = 0; dim[2] < nazi; dim[2]++) for (i = 0; i < il->nsamps; i++) { + /* next sample point */ + multisamp(sp, 4, urand(ilhash(dim,3)+i)); /* random direction */ - dim[3] = 1; - r1 = (dim[1]+urand(urind(ilhash(dim,4),i)))/nalt; - dim[3] = 2; - r2 = (dim[2]+urand(urind(ilhash(dim,4),i)))/nalt; + r1 = (dim[1] + sp[0])/nalt; + r2 = (dim[2] + sp[1] - .5)/nazi; flatdir(dn, r1, r2); for (j = 0; j < 3; j++) dir[j] = -dn[0]*u[j] - dn[1]*v[j] - dn[2]*co->ad[j]; /* random location */ - dim[3] = 3; r3 = sqrt(CO_R0(co)*CO_R0(co) + - urand(urind(ilhash(dim,4),i))* - (CO_R1(co)*CO_R1(co) - CO_R0(co)*CO_R0(co))); - dim[3] = 4; - r2 = 2.*PI*urand(urind(ilhash(dim,4),i)); + sp[2]*(CO_R1(co)*CO_R1(co) - CO_R0(co)*CO_R0(co))); + r2 = 2.*PI*sp[3]; r1 = r3*cos(r2); r2 = r3*sin(r2); for (j = 0; j < 3; j++) @@ -243,12 +250,16 @@ char *nm; .001*co->ad[j]; /* send sample */ - raysamp(distarr+dim[1]*nazi+dim[2], org, dir, rt); + raysamp(distarr+3*(dim[1]*nazi+dim[2]), org, dir, rt); } rayflush(rt); - /* write out the ring w/ distribution */ - flatout(il, distarr, nalt, nazi, u, v, co->ad); - illumout(il, ob); + /* write out the ring and its distribution */ + if (average(il, distarr, nalt*nazi)) { + if (il->sampdens > 0) + flatout(il, distarr, nalt, nazi, u, v, co->ad); + illumout(il, ob); + } else + printobj(il->altmat, ob); /* clean up */ freecone(ob); free((char *)distarr); @@ -278,8 +289,8 @@ register struct rtproc *rt; if (rt->nrays <= 0) return; - i = 6*rt->nrays + 3; - rt->buf[i++] = 0.; rt->buf[i++] = 0.; rt->buf[i] = 0.; + bzero(rt->buf+6*rt->nrays, 6*sizeof(float)); + errno = 0; if ( process(rt->pd, (char *)rt->buf, (char *)rt->buf, 3*sizeof(float)*rt->nrays, 6*sizeof(float)*(rt->nrays+1)) <