| 98 | 
  | 
#include  "ambient.h" | 
| 99 | 
  | 
#include  "otypes.h" | 
| 100 | 
  | 
#include  "random.h" | 
| 101 | 
+ | 
#include  "func.h" | 
| 102 | 
  | 
#include  "data.h" | 
| 103 | 
  | 
#include  "font.h" | 
| 104 | 
  | 
#include  "pmapray.h" | 
| 107 | 
  | 
 | 
| 108 | 
  | 
char    *octname;                       /* octree name we are given */ | 
| 109 | 
  | 
 | 
| 109 | 
– | 
char    *shm_boundary = NULL;           /* boundary of shared memory */ | 
| 110 | 
– | 
 | 
| 110 | 
  | 
CUBE    thescene;                       /* our scene */ | 
| 111 | 
  | 
OBJECT  nsceneobjs;                     /* number of objects in our scene */ | 
| 112 | 
  | 
 | 
| 118 | 
  | 
 | 
| 119 | 
  | 
void    (*addobjnotify[8])() = {ambnotify, NULL}; | 
| 120 | 
  | 
 | 
| 121 | 
+ | 
int     castonly = 0;                   /* only doing ray-casting? */ | 
| 122 | 
+ | 
 | 
| 123 | 
  | 
int     do_irrad = 0;                   /* compute irradiance? */ | 
| 124 | 
  | 
 | 
| 125 | 
  | 
int     rand_samp = 1;                  /* pure Monte Carlo sampling? */ | 
| 143 | 
  | 
int     backvis = 1;                    /* back face visibility */ | 
| 144 | 
  | 
 | 
| 145 | 
  | 
int     maxdepth = -10;                 /* maximum recursion depth */ | 
| 146 | 
< | 
double  minweight = 2e-3;               /* minimum ray weight */ | 
| 146 | 
> | 
double  minweight = 1e-4;               /* minimum ray weight */ | 
| 147 | 
  | 
 | 
| 148 | 
  | 
char    *ambfile = NULL;                /* ambient file name */ | 
| 149 | 
  | 
COLOR   ambval = BLKCOLOR;              /* ambient value */ | 
| 157 | 
  | 
int     ambincl = -1;                   /* include == 1, exclude == 0 */ | 
| 158 | 
  | 
 | 
| 159 | 
  | 
 | 
| 160 | 
+ | 
static void | 
| 161 | 
+ | 
reset_random(void)              /* re-initialize random number generator */ | 
| 162 | 
+ | 
{ | 
| 163 | 
+ | 
        if (rand_samp) { | 
| 164 | 
+ | 
                srandom((long)time(0)); | 
| 165 | 
+ | 
                initurand(0); | 
| 166 | 
+ | 
        } else { | 
| 167 | 
+ | 
                srandom(0L); | 
| 168 | 
+ | 
                initurand(2048); | 
| 169 | 
+ | 
        } | 
| 170 | 
+ | 
} | 
| 171 | 
+ | 
 | 
| 172 | 
+ | 
 | 
| 173 | 
  | 
void | 
| 174 | 
  | 
ray_init(                       /* initialize ray-tracing calculation */ | 
| 175 | 
  | 
        char    *otnm | 
| 180 | 
  | 
                                        /* initialize object types */ | 
| 181 | 
  | 
        if (ofun[OBJ_SPHERE].funp == o_default) | 
| 182 | 
  | 
                initotypes(); | 
| 183 | 
+ | 
                                        /* initialize calcomp routines */ | 
| 184 | 
+ | 
        initfunc(); | 
| 185 | 
  | 
                                        /* initialize urand */ | 
| 186 | 
< | 
        if (rand_samp) { | 
| 187 | 
< | 
                srandom((long)time(0)); | 
| 188 | 
< | 
                initurand(0); | 
| 189 | 
< | 
        } else { | 
| 190 | 
< | 
                srandom(0L); | 
| 191 | 
< | 
                initurand(2048); | 
| 192 | 
< | 
        } | 
| 177 | 
< | 
                                        /* read scene octree */ | 
| 178 | 
< | 
        readoct(octname = otnm, ~(IO_FILES|IO_INFO), &thescene, NULL); | 
| 186 | 
> | 
        reset_random(); | 
| 187 | 
> | 
                                        /* initialize spectral sampling */ | 
| 188 | 
> | 
        if (setspectrsamp(CNDX, WLPART) < 0) | 
| 189 | 
> | 
                error(USER, "unsupported spectral sampling"); | 
| 190 | 
> | 
 | 
| 191 | 
> | 
        octname = savqstr(otnm);        /* read scene octree */ | 
| 192 | 
> | 
        readoct(octname, ~(IO_FILES|IO_INFO), &thescene, NULL); | 
| 193 | 
  | 
        nsceneobjs = nobjects; | 
| 194 | 
< | 
                                        /* PMAP: Init & load photon maps */ | 
| 195 | 
< | 
        ray_init_pmap(); | 
| 196 | 
< | 
                                        /* find and mark sources */ | 
| 197 | 
< | 
        marksources(); | 
| 198 | 
< | 
                                        /* initialize ambient calculation */ | 
| 199 | 
< | 
        setambient(); | 
| 200 | 
< | 
                                        /* ready to go... (almost) */ | 
| 194 | 
> | 
 | 
| 195 | 
> | 
        if (!castonly) {                /* any actual ray traversal to do? */ | 
| 196 | 
> | 
 | 
| 197 | 
> | 
                ray_init_pmap();        /* PMAP: set up & load photon maps */ | 
| 198 | 
> | 
 | 
| 199 | 
> | 
                marksources();          /* find and mark sources */ | 
| 200 | 
> | 
 | 
| 201 | 
> | 
                setambient();           /* initialize ambient calculation */ | 
| 202 | 
> | 
        } else | 
| 203 | 
> | 
                distantsources();       /* else mark only distant sources */ | 
| 204 | 
  | 
} | 
| 205 | 
  | 
 | 
| 206 | 
+ | 
 | 
| 207 | 
  | 
void | 
| 208 | 
  | 
ray_trace(                      /* trace a primary ray */ | 
| 209 | 
  | 
        RAY     *r | 
| 228 | 
  | 
        donesets(); | 
| 229 | 
  | 
        octdone(); | 
| 230 | 
  | 
        thescene.cutree = EMPTY; | 
| 231 | 
< | 
        octname = NULL; | 
| 231 | 
> | 
        freeqstr(octname); octname = NULL; | 
| 232 | 
  | 
        retainfonts = 0; | 
| 233 | 
  | 
        if (freall) { | 
| 234 | 
  | 
                freefont(NULL); | 
| 308 | 
  | 
        RAYPARAMS       *rp | 
| 309 | 
  | 
) | 
| 310 | 
  | 
{ | 
| 311 | 
< | 
        register int    i; | 
| 311 | 
> | 
        int     i; | 
| 312 | 
  | 
 | 
| 313 | 
  | 
        if (rp == NULL) {               /* restore defaults */ | 
| 314 | 
  | 
                RAYPARAMS       dflt; | 
| 318 | 
  | 
        } | 
| 319 | 
  | 
                                        /* restore saved settings */ | 
| 320 | 
  | 
        do_irrad = rp->do_irrad; | 
| 321 | 
< | 
        rand_samp = rp->rand_samp; | 
| 321 | 
> | 
        if (!rand_samp != !rp->rand_samp) { | 
| 322 | 
> | 
                rand_samp = rp->rand_samp; | 
| 323 | 
> | 
                reset_random(); | 
| 324 | 
> | 
        } | 
| 325 | 
  | 
        dstrsrc = rp->dstrsrc; | 
| 326 | 
  | 
        shadthresh = rp->shadthresh; | 
| 327 | 
  | 
        shadcert = rp->shadcert; | 
| 343 | 
  | 
        ambdiv = rp->ambdiv; | 
| 344 | 
  | 
        ambssamp = rp->ambssamp; | 
| 345 | 
  | 
        ambounce = rp->ambounce; | 
| 346 | 
+ | 
                                        /* a bit dangerous if not static */ | 
| 347 | 
  | 
        for (i = 0; rp->amblndx[i] >= 0; i++) | 
| 348 | 
  | 
                amblist[i] = rp->amblval + rp->amblndx[i]; | 
| 349 | 
  | 
        while (i <= AMBLLEN) | 
| 351 | 
  | 
        ambincl = rp->ambincl; | 
| 352 | 
  | 
                                        /* update ambient calculation */ | 
| 353 | 
  | 
        ambnotify(OVOID); | 
| 354 | 
< | 
        if (thescene.cutree != EMPTY) { | 
| 354 | 
> | 
        if ((thescene.cutree != EMPTY) & !castonly) { | 
| 355 | 
  | 
                int     newamb = (ambfile == NULL) ?  rp->ambfile[0] : | 
| 356 | 
  | 
                                        strcmp(ambfile, rp->ambfile) ; | 
| 357 | 
  | 
 | 
| 392 | 
  | 
        rp->do_irrad = 0; | 
| 393 | 
  | 
        rp->rand_samp = 1; | 
| 394 | 
  | 
        rp->dstrsrc = 0.0; | 
| 395 | 
< | 
        rp->shadthresh = .03; | 
| 396 | 
< | 
        rp->shadcert = .75; | 
| 395 | 
> | 
        rp->shadthresh = 0.03; | 
| 396 | 
> | 
        rp->shadcert = 0.75; | 
| 397 | 
  | 
        rp->directrelay = 2; | 
| 398 | 
  | 
        rp->vspretest = 512; | 
| 399 | 
  | 
        rp->directvis = 1; | 
| 402 | 
  | 
        setcolor(rp->salbedo, 0., 0., 0.); | 
| 403 | 
  | 
        rp->seccg = 0.; | 
| 404 | 
  | 
        rp->ssampdist = 0.; | 
| 405 | 
< | 
        rp->specthresh = .15; | 
| 405 | 
> | 
        rp->specthresh = 0.15; | 
| 406 | 
  | 
        rp->specjitter = 1.; | 
| 407 | 
  | 
        rp->backvis = 1; | 
| 408 | 
  | 
        rp->maxdepth = -10; | 
| 409 | 
< | 
        rp->minweight = 2e-3; | 
| 409 | 
> | 
        rp->minweight = 1e-4; | 
| 410 | 
  | 
        memset(rp->ambfile, '\0', sizeof(rp->ambfile)); | 
| 411 | 
  | 
        setcolor(rp->ambval, 0., 0., 0.); | 
| 412 | 
  | 
        rp->ambvwt = 0; | 
| 413 | 
  | 
        rp->ambres = 256; | 
| 414 | 
< | 
        rp->ambacc = 0.15; | 
| 414 | 
> | 
        rp->ambacc = 0.1; | 
| 415 | 
  | 
        rp->ambdiv = 1024; | 
| 416 | 
  | 
        rp->ambssamp = 512; | 
| 417 | 
  | 
        rp->ambounce = 0; |