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.105 by greg, Tue Jan 9 05:01:15 2018 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  "source.h"
19   #include  "random.h"
20   #include  "pmapamb.h"
21  
# Line 276 | Line 278 | multambient(           /* compute ambient component & multiply
278   {
279          static int  rdepth = 0;                 /* ambient recursion */
280          COLOR   acol, caustic;
281 <        int     ok;
281 >        int     i, ok;
282          double  d, l;
283  
284          /* PMAP: Factor in ambient from photon map, if enabled and ray is
# Line 302 | Line 304 | multambient(           /* compute ambient component & multiply
304                  goto dumbamb;
305  
306          if (ambacc <= FTINY) {                  /* no ambient storage */
307 +                FVECT   uvd[2];
308 +                float   dgrad[2], *dgp = NULL;
309 +
310 +                if (nrm != r->ron && DOT(nrm,r->ron) < 0.9999)
311 +                        dgp = dgrad;            /* compute rotational grad. */
312                  copycolor(acol, aval);
313                  rdepth++;
314                  ok = doambient(acol, r, r->rweight,
315 <                                NULL, NULL, NULL, NULL, NULL);
315 >                                uvd, NULL, NULL, dgp, NULL);
316                  rdepth--;
317                  if (!ok)
318                          goto dumbamb;
319 +                if ((ok > 0) & (dgp != NULL)) { /* apply texture */
320 +                        FVECT   v1;
321 +                        VCROSS(v1, r->ron, nrm);
322 +                        d = 1.0;
323 +                        for (i = 3; i--; )
324 +                                d += v1[i] * (dgp[0]*uvd[0][i] + dgp[1]*uvd[1][i]);
325 +                        if (d >= 0.05)
326 +                                scalecolor(acol, d);
327 +                }
328                  copycolor(aval, acol);
329  
330                  /* PMAP: add in caustic */
# Line 401 | Line 417 | plugaleak(RAY *r, AMBVAL *ap, FVECT anorm, double ang)
417          VSUM(rtst.rdir, vdif, anorm, t[1]);     /* further dist. > plane */
418          rtst.rmax = normalize(rtst.rdir);       /* short ray test */
419          while (localhit(&rtst, &thescene)) {    /* check for occluder */
420 <                if (rtst.ro->omod != OVOID &&
420 >                OBJREC  *m = findmaterial(rtst.ro);
421 >                if (m != NULL && !istransp(m->otype) && !isBSDFproxy(m) &&
422                                  (rtst.clipset == NULL ||
423                                          !inset(rtst.clipset, rtst.ro->omod)))
424                          return(1);              /* plug light leak */
# Line 1313 | Line 1330 | ambsync(void)                  /* synchronize ambient file */
1330          if ((flen = lseek(fileno(ambfp), (off_t)0, SEEK_END)) < 0)
1331                  goto seekerr;
1332          if ((n = flen - lastpos) > 0) {         /* file has grown */
1333 <                if (ambinp == NULL) {           /* use duplicate filedes */
1334 <                        ambinp = fdopen(dup(fileno(ambfp)), "r");
1333 >                if (ambinp == NULL) {           /* get new file pointer */
1334 >                        ambinp = fopen(ambfile, "rb");
1335                          if (ambinp == NULL)
1336 <                                error(SYSTEM, "fdopen failed in ambsync");
1336 >                                error(SYSTEM, "fopen failed in ambsync");
1337                  }
1338                  if (fseek(ambinp, lastpos, SEEK_SET) < 0)
1339                          goto seekerr;
# Line 1331 | Line 1348 | ambsync(void)                  /* synchronize ambient file */
1348                          avstore(&avs);
1349                          n -= AMBVALSIZ;
1350                  }
1351 <                lastpos = flen - n;
1352 <                /*** seek always as safety measure
1353 <                if (n) ***/                     /* alignment */
1337 <                        if (lseek(fileno(ambfp), (off_t)lastpos, SEEK_SET) < 0)
1338 <                                goto seekerr;
1351 >                lastpos = flen - n;             /* check alignment */
1352 >                if (n && lseek(fileno(ambfp), (off_t)lastpos, SEEK_SET) < 0)
1353 >                        goto seekerr;
1354          }
1355          n = fflush(ambfp);                      /* calls write() at last */
1356 <        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 <                
1356 >        lastpos += (long)nunflshed*AMBVALSIZ;
1357          aflock(F_UNLCK);                        /* release file */
1358          nunflshed = 0;
1359          return(n);
1360   seekerr:
1361          error(SYSTEM, "seek failed in ambsync");
1362 <        return -1; /* pro forma return */
1362 >        return(EOF);    /* pro forma return */
1363   }
1364  
1365   #else   /* ! F_SETLKW */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines