--- ray/src/gen/mkillum2.c 2007/09/21 05:53:21 2.21 +++ ray/src/gen/mkillum2.c 2007/12/05 20:07:34 2.24 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: mkillum2.c,v 2.21 2007/09/21 05:53:21 greg Exp $"; +static const char RCSid[] = "$Id: mkillum2.c,v 2.24 2007/12/05 20:07:34 greg Exp $"; #endif /* * Routines to do the actual calculation for mkillum @@ -22,7 +22,7 @@ newdist( /* allocate & clear distribution array */ int siz ) { - if (siz == 0) { + if (siz <= 0) { if (distsiz > 0) free((void *)distarr); distarr = NULL; @@ -46,7 +46,7 @@ process_ray(RAY *r, int rv) { COLORV *colp; - if (rv == 0) + if (rv == 0) /* no result ready */ return(0); if (rv < 0) error(USER, "ray tracing process died"); @@ -127,9 +127,9 @@ rounddir( /* compute uniform spherical direction */ } -static void +void flatdir( /* compute uniform hemispherical direction */ - register FVECT dv, + FVECT dv, double alt, double azi ) @@ -184,13 +184,6 @@ my_face( /* make an illum face */ return(my_default(ob, il, nm)); } /* set up sampling */ - if (il->sampdens <= 0) { - nalt = nazi = 1; /* diffuse assumption */ - } else { - n = PI * il->sampdens; - nalt = sqrt(n/PI) + .5; - nazi = PI*nalt + .5; - } if (il->sd != NULL) { if (!getBSDF_xfm(xfm, fa->norm, il->udir)) { objerror(ob, WARNING, "illegal up direction"); @@ -198,8 +191,16 @@ my_face( /* make an illum face */ return(my_default(ob, il, nm)); } n = il->sd->ninc; - } else + } else { + if (il->sampdens <= 0) { + nalt = nazi = 1; /* diffuse assumption */ + } else { + n = PI * il->sampdens; + nalt = sqrt(n/PI) + .5; + nazi = PI*nalt + .5; + } n = nazi*nalt; + } newdist(n); /* take first edge >= sqrt(area) */ for (j = fa->nv-1, i = 0; i < fa->nv; j = i++) { @@ -231,7 +232,7 @@ my_face( /* make an illum face */ nmisses = 0; for (dim[1] = 0; dim[1] < n; dim[1]++) for (i = 0; i < il->nsamps; i++) { - /* random direction */ + /* randomize direction */ h = ilhash(dim, 2) + i; if (il->sd != NULL) { r_BSDF_incvec(dir, il->sd, dim[1], urand(h), xfm); @@ -245,7 +246,7 @@ my_face( /* make an illum face */ dir[j] = -dn[0]*u[j] - dn[1]*v[j] - dn[2]*fa->norm[j]; } - /* random location */ + /* randomize location */ do { multisamp(sp, 2, urand(h+4862+nmisses)); r1 = ur[0] + (ur[1]-ur[0]) * sp[0]; @@ -270,8 +271,11 @@ my_face( /* make an illum face */ raysamp(dim[1], org, dir); } rayclean(); - if (il->sd != NULL) /* run distribution through BSDF */ + if (il->sd != NULL) { /* run distribution through BSDF */ + nalt = sqrt(il->sd->nout/PI) + .5; + nazi = PI*nalt + .5; redistribute(il->sd, nalt, nazi, u, v, fa->norm, xfm); + } /* write out the face and its distribution */ if (average(il, distarr, n)) { if (il->sampdens > 0) @@ -374,13 +378,6 @@ my_ring( /* make an illum ring */ /* get/check arguments */ co = getcone(ob, 0); /* set up sampling */ - if (il->sampdens <= 0) - nalt = nazi = 1; - else { - n = PI * il->sampdens; - nalt = sqrt(n/PI) + .5; - nazi = PI*nalt + .5; - } if (il->sd != NULL) { if (!getBSDF_xfm(xfm, co->ad, il->udir)) { objerror(ob, WARNING, "illegal up direction"); @@ -388,8 +385,16 @@ my_ring( /* make an illum ring */ return(my_default(ob, il, nm)); } n = il->sd->ninc; - } else + } else { + if (il->sampdens <= 0) { + nalt = nazi = 1; /* diffuse assumption */ + } else { + n = PI * il->sampdens; + nalt = sqrt(n/PI) + .5; + nazi = PI*nalt + .5; + } n = nazi*nalt; + } newdist(n); mkaxes(u, v, co->ad); dim[0] = random(); @@ -398,7 +403,7 @@ my_ring( /* make an illum ring */ for (i = 0; i < il->nsamps; i++) { /* next sample point */ h = ilhash(dim,2) + i; - /* random direction */ + /* randomize direction */ if (il->sd != NULL) { r_BSDF_incvec(dir, il->sd, dim[1], urand(h), xfm); } else { @@ -408,9 +413,9 @@ my_ring( /* make an illum ring */ r2 = (dim[1] - alti*nazi + 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]; + dir[j] = -dn[0]*u[j] - dn[1]*v[j] - dn[2]*co->ad[j]; } - /* random location */ + /* randomize location */ multisamp(sp, 2, urand(h+8371)); r3 = sqrt(CO_R0(co)*CO_R0(co) + sp[0]*(CO_R1(co)*CO_R1(co) - CO_R0(co)*CO_R0(co))); @@ -428,8 +433,11 @@ my_ring( /* make an illum ring */ raysamp(dim[1], org, dir); } rayclean(); - if (il->sd != NULL) /* run distribution through BSDF */ + if (il->sd != NULL) { /* run distribution through BSDF */ + nalt = sqrt(il->sd->nout/PI) + .5; + nazi = PI*nalt + .5; redistribute(il->sd, nalt, nazi, u, v, co->ad, xfm); + } /* write out the ring and its distribution */ if (average(il, distarr, n)) { if (il->sampdens > 0)