--- ray/src/gen/mkillum2.c 2007/09/21 05:53:21 2.21 +++ ray/src/gen/mkillum2.c 2007/11/05 23:40:26 2.23 @@ -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.23 2007/11/05 23:40:26 greg Exp $"; #endif /* * Routines to do the actual calculation for mkillum @@ -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 { @@ -410,7 +415,7 @@ my_ring( /* make an illum ring */ for (j = 0; j < 3; 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)