| 20 |
|
#include "ray.h" |
| 21 |
|
#include "ambient.h" |
| 22 |
|
#include "random.h" |
| 23 |
+ |
#include "source.h" |
| 24 |
+ |
#include "otypes.h" |
| 25 |
+ |
#include "otspecial.h" |
| 26 |
|
|
| 27 |
|
#ifndef OLDAMB |
| 28 |
|
|
| 140 |
|
if (ar.rt*ap->d < 1.0) /* new/closer distance? */ |
| 141 |
|
ap->d = 1.0/ar.rt; |
| 142 |
|
if (!n) { /* record first vertex & value */ |
| 143 |
< |
if (ar.rt > 10.0*thescene.cusize) |
| 144 |
< |
ar.rt = 10.0*thescene.cusize; |
| 143 |
> |
if (ar.rt > 10.0*thescene.cusize + 1000.) |
| 144 |
> |
ar.rt = 10.0*thescene.cusize + 1000.; |
| 145 |
|
VSUM(ap->p, ar.rorg, ar.rdir, ar.rt); |
| 146 |
|
copycolor(ap->v, ar.rcol); |
| 147 |
|
} else { /* else update recorded value */ |
| 163 |
|
static float * |
| 164 |
|
getambdiffs(AMBHEMI *hp) |
| 165 |
|
{ |
| 166 |
+ |
const double normf = 1./bright(hp->acoef); |
| 167 |
|
float *earr = (float *)calloc(hp->ns*hp->ns, sizeof(float)); |
| 168 |
|
float *ep; |
| 169 |
|
AMBSAMP *ap; |
| 177 |
|
for (j = 0; j < hp->ns; j++, ap++, ep++) { |
| 178 |
|
b = bright(ap[0].v); |
| 179 |
|
if (i) { /* from above */ |
| 180 |
< |
d2 = b - bright(ap[-hp->ns].v); |
| 180 |
> |
d2 = normf*(b - bright(ap[-hp->ns].v)); |
| 181 |
|
d2 *= d2; |
| 182 |
|
ep[0] += d2; |
| 183 |
|
ep[-hp->ns] += d2; |
| 184 |
|
} |
| 185 |
|
if (!j) continue; |
| 186 |
|
/* from behind */ |
| 187 |
< |
d2 = b - bright(ap[-1].v); |
| 187 |
> |
d2 = normf*(b - bright(ap[-1].v)); |
| 188 |
|
d2 *= d2; |
| 189 |
|
ep[0] += d2; |
| 190 |
|
ep[-1] += d2; |
| 191 |
|
if (!i) continue; |
| 192 |
|
/* diagonal */ |
| 193 |
< |
d2 = b - bright(ap[-hp->ns-1].v); |
| 193 |
> |
d2 = normf*(b - bright(ap[-hp->ns-1].v)); |
| 194 |
|
d2 *= d2; |
| 195 |
|
ep[0] += d2; |
| 196 |
|
ep[-hp->ns-1] += d2; |
| 234 |
|
goto done; /* nothing left to do */ |
| 235 |
|
nss = *ep/e2rem*cnt + frandom(); |
| 236 |
|
for (n = 1; n <= nss && ambsample(hp,i,j,n); n++) |
| 237 |
< |
--cnt; |
| 237 |
> |
if (!--cnt) goto done; |
| 238 |
|
e2rem -= *ep++; /* update remainder */ |
| 239 |
|
} |
| 240 |
|
done: |
| 252 |
|
AMBHEMI *hp; |
| 253 |
|
double d; |
| 254 |
|
int n, i, j; |
| 255 |
+ |
/* insignificance check */ |
| 256 |
+ |
if (bright(rcol) <= FTINY) |
| 257 |
+ |
return(NULL); |
| 258 |
|
/* set number of divisions */ |
| 259 |
|
if (ambacc <= FTINY && |
| 260 |
|
wt > (d = 0.8*intens(rcol)*r->rweight/(ambdiv*minweight))) |
| 649 |
|
FVECT vec; |
| 650 |
|
double u, v; |
| 651 |
|
double ang, a1; |
| 652 |
+ |
OBJREC *m; |
| 653 |
|
int i, j; |
| 654 |
|
/* don't bother for a few samples */ |
| 655 |
|
if (hp->ns < 8) |
| 679 |
|
flgs |= 1L<<(int)(16/PI*(a1 + 2.*PI*(a1 < 0))); |
| 680 |
|
} |
| 681 |
|
/* add low-angle incident (< 20deg) */ |
| 682 |
< |
if (fabs(hp->rp->rod) <= 0.342) { |
| 682 |
> |
if (fabs(hp->rp->rod) <= 0.342 && hp->rp->parent != NULL && |
| 683 |
> |
(m = findmaterial(hp->rp->parent->ro)) != NULL && |
| 684 |
> |
isopaque(m->otype)) { |
| 685 |
|
u = -DOT(hp->rp->rdir, uv[0]); |
| 686 |
|
v = -DOT(hp->rp->rdir, uv[1]); |
| 687 |
|
if ((r0*r0*u*u + r1*r1*v*v) > hp->rp->rot*hp->rp->rot) { |