76 |
|
#define AMBFLUSH (BUFSIZ/AMBVALSIZ) |
77 |
|
|
78 |
|
#define newambval() (AMBVAL *)malloc(sizeof(AMBVAL)) |
79 |
– |
#define freeav(av) free((void *)av); |
79 |
|
|
80 |
|
static void initambfile(int creat); |
81 |
|
static void avsave(AMBVAL *av); |
276 |
|
{ |
277 |
|
static int rdepth = 0; /* ambient recursion */ |
278 |
|
COLOR acol, caustic; |
279 |
< |
int ok; |
279 |
> |
int i, ok; |
280 |
|
double d, l; |
281 |
|
|
282 |
|
/* PMAP: Factor in ambient from photon map, if enabled and ray is |
302 |
|
goto dumbamb; |
303 |
|
|
304 |
|
if (ambacc <= FTINY) { /* no ambient storage */ |
305 |
+ |
FVECT uvd[2]; |
306 |
+ |
float dgrad[2], *dgp = NULL; |
307 |
+ |
|
308 |
+ |
if (nrm != r->ron && DOT(nrm,r->ron) < 0.9999) |
309 |
+ |
dgp = dgrad; /* compute rotational grad. */ |
310 |
|
copycolor(acol, aval); |
311 |
|
rdepth++; |
312 |
|
ok = doambient(acol, r, r->rweight, |
313 |
< |
NULL, NULL, NULL, NULL, NULL); |
313 |
> |
uvd, NULL, NULL, dgp, NULL); |
314 |
|
rdepth--; |
315 |
|
if (!ok) |
316 |
|
goto dumbamb; |
317 |
+ |
if ((ok > 0) & (dgp != NULL)) { /* apply texture */ |
318 |
+ |
FVECT v1; |
319 |
+ |
VCROSS(v1, r->ron, nrm); |
320 |
+ |
d = 1.0; |
321 |
+ |
for (i = 3; i--; ) |
322 |
+ |
d += v1[i] * (dgp[0]*uvd[0][i] + dgp[1]*uvd[1][i]); |
323 |
+ |
if (d >= 0.05) |
324 |
+ |
scalecolor(acol, d); |
325 |
+ |
} |
326 |
|
copycolor(aval, acol); |
327 |
|
|
328 |
|
/* PMAP: add in caustic */ |
1085 |
|
} |
1086 |
|
atp = atfreelist; |
1087 |
|
atfreelist = atp->kid; |
1088 |
< |
memset((char *)atp, '\0', 8*sizeof(AMBTREE)); |
1088 |
> |
memset(atp, 0, 8*sizeof(AMBTREE)); |
1089 |
|
return(atp); |
1090 |
|
} |
1091 |
|
|
1111 |
|
/* transfer values at this node */ |
1112 |
|
for (av = at->alist; av != NULL; av = at->alist) { |
1113 |
|
at->alist = av->next; |
1114 |
+ |
av->next = NULL; |
1115 |
|
(*f)(av); |
1116 |
|
} |
1117 |
|
if (at->kid == NULL) |
1189 |
|
{ |
1190 |
|
AMBVAL **avlpp; |
1191 |
|
|
1192 |
< |
avlpp = (AMBVAL **)bsearch((char *)&avaddr, (char *)avlist2, |
1193 |
< |
nambvals, sizeof(AMBVAL *), &aposcmp); |
1192 |
> |
avlpp = (AMBVAL **)bsearch(&avaddr, avlist2, |
1193 |
> |
nambvals, sizeof(AMBVAL *), aposcmp); |
1194 |
|
if (avlpp == NULL) |
1195 |
|
error(CONSISTENCY, "address not found in avlmemi"); |
1196 |
|
return(avlpp - avlist2); |
1233 |
|
} |
1234 |
|
if (avlist1 == NULL) { /* no time tracking -- rebuild tree? */ |
1235 |
|
if (avlist2 != NULL) |
1236 |
< |
free((void *)avlist2); |
1236 |
> |
free(avlist2); |
1237 |
|
if (always) { /* rebuild without sorting */ |
1238 |
|
oldatrunk = atrunk; |
1239 |
|
atrunk.alist = NULL; |
1260 |
|
if (i_avlist < nambvals) |
1261 |
|
error(CONSISTENCY, "missing ambient values in sortambvals"); |
1262 |
|
#endif |
1263 |
< |
qsort((char *)avlist1, nambvals, sizeof(struct avl), alatcmp); |
1264 |
< |
qsort((char *)avlist2, nambvals, sizeof(AMBVAL *), aposcmp); |
1263 |
> |
qsort(avlist1, nambvals, sizeof(struct avl), alatcmp); |
1264 |
> |
qsort(avlist2, nambvals, sizeof(AMBVAL *), aposcmp); |
1265 |
|
for (i = 0; i < nambvals; i++) { |
1266 |
|
if (avlist1[i].p == NULL) |
1267 |
|
continue; |
1277 |
|
avinsert(avlist2[j]); |
1278 |
|
avlist1[j].p = NULL; |
1279 |
|
} |
1280 |
< |
free((void *)avlist1); |
1281 |
< |
free((void *)avlist2); |
1280 |
> |
free(avlist1); |
1281 |
> |
free(avlist2); |
1282 |
|
/* compute new sort interval */ |
1283 |
|
sortintvl = ambclock - lastsort; |
1284 |
|
if (sortintvl >= MAX_SORT_INTVL/2) |