ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/ambient.c
(Generate patch)

Comparing ray/src/rt/ambient.c (file contents):
Revision 2.101 by schorsch, Sun Mar 6 01:13:17 2016 UTC vs.
Revision 2.107 by greg, Sat Feb 16 00:09:53 2019 UTC

# Line 12 | Line 12 | static const char      RCSid[] = "$Id$";
12   #include  "platform.h"
13   #include  "ray.h"
14   #include  "otypes.h"
15 + #include  "otspecial.h"
16   #include  "resolu.h"
17   #include  "ambient.h"
18   #include  "random.h"
# Line 76 | Line 77 | static long  lastpos = -1;             /* last flush position */
77   #define  AMBFLUSH       (BUFSIZ/AMBVALSIZ)
78  
79   #define  newambval()    (AMBVAL *)malloc(sizeof(AMBVAL))
79 #define  freeav(av)     free((void *)av);
80  
81   static void initambfile(int creat);
82   static void avsave(AMBVAL *av);
# Line 132 | Line 132 | setambacc(                             /* set ambient accuracy */
132          newa *= (newa > 0);
133          if (fabs(newa - olda) >= .05*(newa + olda)) {
134                  ambacc = newa;
135 <                if (nambvals > 0)
135 >                if (ambacc > FTINY && nambvals > 0)
136                          sortambvals(1);         /* rebuild tree */
137          }
138   }
# Line 277 | Line 277 | multambient(           /* compute ambient component & multiply
277   {
278          static int  rdepth = 0;                 /* ambient recursion */
279          COLOR   acol, caustic;
280 <        int     ok;
280 >        int     i, ok;
281          double  d, l;
282  
283          /* PMAP: Factor in ambient from photon map, if enabled and ray is
# Line 303 | Line 303 | multambient(           /* compute ambient component & multiply
303                  goto dumbamb;
304  
305          if (ambacc <= FTINY) {                  /* no ambient storage */
306 +                FVECT   uvd[2];
307 +                float   dgrad[2], *dgp = NULL;
308 +
309 +                if (nrm != r->ron && DOT(nrm,r->ron) < 0.9999)
310 +                        dgp = dgrad;            /* compute rotational grad. */
311                  copycolor(acol, aval);
312                  rdepth++;
313                  ok = doambient(acol, r, r->rweight,
314 <                                NULL, NULL, NULL, NULL, NULL);
314 >                                uvd, NULL, NULL, dgp, NULL);
315                  rdepth--;
316                  if (!ok)
317                          goto dumbamb;
318 +                if ((ok > 0) & (dgp != NULL)) { /* apply texture */
319 +                        FVECT   v1;
320 +                        VCROSS(v1, r->ron, nrm);
321 +                        d = 1.0;
322 +                        for (i = 3; i--; )
323 +                                d += v1[i] * (dgp[0]*uvd[0][i] + dgp[1]*uvd[1][i]);
324 +                        if (d >= 0.05)
325 +                                scalecolor(acol, d);
326 +                }
327                  copycolor(aval, acol);
328  
329                  /* PMAP: add in caustic */
# Line 402 | Line 416 | plugaleak(RAY *r, AMBVAL *ap, FVECT anorm, double ang)
416          VSUM(rtst.rdir, vdif, anorm, t[1]);     /* further dist. > plane */
417          rtst.rmax = normalize(rtst.rdir);       /* short ray test */
418          while (localhit(&rtst, &thescene)) {    /* check for occluder */
419 <                if (rtst.ro->omod != OVOID &&
419 >                OBJREC  *m = findmaterial(rtst.ro);
420 >                if (m != NULL && !istransp(m->otype) && !isBSDFproxy(m) &&
421                                  (rtst.clipset == NULL ||
422                                          !inset(rtst.clipset, rtst.ro->omod)))
423                          return(1);              /* plug light leak */
# Line 1072 | Line 1087 | newambtree(void)                               /* allocate 8 ambient tree structs
1087          }
1088          atp = atfreelist;
1089          atfreelist = atp->kid;
1090 <        memset((char *)atp, '\0', 8*sizeof(AMBTREE));
1090 >        memset(atp, 0, 8*sizeof(AMBTREE));
1091          return(atp);
1092   }
1093  
# Line 1098 | Line 1113 | unloadatree(                   /* unload an ambient value tree */
1113                                          /* transfer values at this node */
1114          for (av = at->alist; av != NULL; av = at->alist) {
1115                  at->alist = av->next;
1116 +                av->next = NULL;
1117                  (*f)(av);
1118          }
1119          if (at->kid == NULL)
# Line 1175 | Line 1191 | avlmemi(                               /* find list position from address */
1191   {
1192          AMBVAL  **avlpp;
1193  
1194 <        avlpp = (AMBVAL **)bsearch((char *)&avaddr, (char *)avlist2,
1195 <                        nambvals, sizeof(AMBVAL *), &aposcmp);
1194 >        avlpp = (AMBVAL **)bsearch(&avaddr, avlist2,
1195 >                        nambvals, sizeof(AMBVAL *), aposcmp);
1196          if (avlpp == NULL)
1197                  error(CONSISTENCY, "address not found in avlmemi");
1198          return(avlpp - avlist2);
# Line 1219 | Line 1235 | sortambvals(                   /* resort ambient values */
1235          }
1236          if (avlist1 == NULL) {          /* no time tracking -- rebuild tree? */
1237                  if (avlist2 != NULL)
1238 <                        free((void *)avlist2);
1238 >                        free(avlist2);
1239                  if (always) {           /* rebuild without sorting */
1240                          oldatrunk = atrunk;
1241                          atrunk.alist = NULL;
# Line 1246 | Line 1262 | sortambvals(                   /* resort ambient values */
1262                  if (i_avlist < nambvals)
1263                          error(CONSISTENCY, "missing ambient values in sortambvals");
1264   #endif
1265 <                qsort((char *)avlist1, nambvals, sizeof(struct avl), alatcmp);
1266 <                qsort((char *)avlist2, nambvals, sizeof(AMBVAL *), aposcmp);
1265 >                qsort(avlist1, nambvals, sizeof(struct avl), alatcmp);
1266 >                qsort(avlist2, nambvals, sizeof(AMBVAL *), aposcmp);
1267                  for (i = 0; i < nambvals; i++) {
1268                          if (avlist1[i].p == NULL)
1269                                  continue;
# Line 1263 | Line 1279 | sortambvals(                   /* resort ambient values */
1279                          avinsert(avlist2[j]);
1280                          avlist1[j].p = NULL;
1281                  }
1282 <                free((void *)avlist1);
1283 <                free((void *)avlist2);
1282 >                free(avlist1);
1283 >                free(avlist2);
1284                                                  /* compute new sort interval */
1285                  sortintvl = ambclock - lastsort;
1286                  if (sortintvl >= MAX_SORT_INTVL/2)
# Line 1313 | Line 1329 | ambsync(void)                  /* synchronize ambient file */
1329          if ((flen = lseek(fileno(ambfp), (off_t)0, SEEK_END)) < 0)
1330                  goto seekerr;
1331          if ((n = flen - lastpos) > 0) {         /* file has grown */
1332 <                if (ambinp == NULL) {           /* use duplicate filedes */
1333 <                        ambinp = fdopen(dup(fileno(ambfp)), "r");
1332 >                if (ambinp == NULL) {           /* get new file pointer */
1333 >                        ambinp = fopen(ambfile, "rb");
1334                          if (ambinp == NULL)
1335 <                                error(SYSTEM, "fdopen failed in ambsync");
1335 >                                error(SYSTEM, "fopen failed in ambsync");
1336                  }
1337                  if (fseek(ambinp, lastpos, SEEK_SET) < 0)
1338                          goto seekerr;
# Line 1331 | Line 1347 | ambsync(void)                  /* synchronize ambient file */
1347                          avstore(&avs);
1348                          n -= AMBVALSIZ;
1349                  }
1350 <                lastpos = flen - n;
1351 <                /*** seek always as safety measure
1352 <                if (n) ***/                     /* alignment */
1337 <                        if (lseek(fileno(ambfp), (off_t)lastpos, SEEK_SET) < 0)
1338 <                                goto seekerr;
1350 >                lastpos = flen - n;             /* check alignment */
1351 >                if (n && lseek(fileno(ambfp), (off_t)lastpos, SEEK_SET) < 0)
1352 >                        goto seekerr;
1353          }
1354          n = fflush(ambfp);                      /* calls write() at last */
1355 <        if (n != EOF)
1342 <                lastpos += (long)nunflshed*AMBVALSIZ;
1343 <        else if ((lastpos = lseek(fileno(ambfp), (off_t)0, SEEK_CUR)) < 0)
1344 <                goto seekerr;
1345 <                
1355 >        lastpos += (long)nunflshed*AMBVALSIZ;
1356          aflock(F_UNLCK);                        /* release file */
1357          nunflshed = 0;
1358          return(n);
1359   seekerr:
1360          error(SYSTEM, "seek failed in ambsync");
1361 <        return -1; /* pro forma return */
1361 >        return(EOF);    /* pro forma return */
1362   }
1363  
1364   #else   /* ! F_SETLKW */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines