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.102 by greg, Sun Apr 24 16:21:32 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 131 | 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 276 | 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 302 | 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 401 | 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 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