--- ray/src/util/ranimove1.c 2005/07/24 21:11:53 3.11 +++ ray/src/util/ranimove1.c 2011/05/20 02:06:39 3.17 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: ranimove1.c,v 3.11 2005/07/24 21:11:53 greg Exp $"; +static const char RCSid[] = "$Id: ranimove1.c,v 3.17 2011/05/20 02:06:39 greg Exp $"; #endif /* * ranimove1.c @@ -30,14 +30,14 @@ float *zbuffer; /* depth at each pixel */ OBJECT *obuffer; /* object id at each pixel */ short *xmbuffer; /* x motion at each pixel */ short *ymbuffer; /* y motion at each pixel */ -BYTE *abuffer; /* accuracy at each pixel */ -BYTE *sbuffer; /* sample count per pixel */ +uby8 *abuffer; /* accuracy at each pixel */ +uby8 *sbuffer; /* sample count per pixel */ VIEW vwprev; /* last frame's view */ COLOR *cprev; /* last frame colors */ float *zprev; /* last frame depth */ OBJECT *oprev; /* last frame objects */ -BYTE *aprev; /* last frame accuracy */ +uby8 *aprev; /* last frame accuracy */ float *cerrmap; /* conspicuous error map */ COLOR *val2map; /* value-squared map for variance */ @@ -54,6 +54,7 @@ static void setmotion(int n, FVECT wpos); static void init_frame_sample(void); +#if 0 extern void write_map( /* write out float map (debugging) */ float *mp, @@ -79,6 +80,7 @@ write_map( /* write out float map (debugging) */ } fclose(fp); } +#endif static void @@ -105,6 +107,7 @@ next_frame(void) /* prepare next frame buffer */ error(USER, errmsg); } if (cbuffer == NULL) { + int n; /* compute resolution and allocate */ switch (sscanf(vval(RESOLUTION), "%d %d %lf", &hres, &vres, &pixaspect)) { @@ -128,30 +131,34 @@ next_frame(void) /* prepare next frame buffer */ obuffer = (OBJECT *)malloc(sizeof(OBJECT)*hres*vres); xmbuffer = (short *)malloc(sizeof(short)*hres*vres); ymbuffer = (short *)malloc(sizeof(short)*hres*vres); - abuffer = (BYTE *)calloc(hres*vres, sizeof(BYTE)); - sbuffer = (BYTE *)calloc(hres*vres, sizeof(BYTE)); + abuffer = (uby8 *)calloc(hres*vres, sizeof(uby8)); + sbuffer = (uby8 *)calloc(hres*vres, sizeof(uby8)); cprev = (COLOR *)malloc(sizeof(COLOR)*hres*vres); zprev = (float *)malloc(sizeof(float)*hres*vres); oprev = (OBJECT *)malloc(sizeof(OBJECT)*hres*vres); - aprev = (BYTE *)malloc(sizeof(BYTE)*hres*vres); + aprev = (uby8 *)malloc(sizeof(uby8)*hres*vres); if ((cbuffer==NULL) | (zbuffer==NULL) | (obuffer==NULL) | (xmbuffer==NULL) | (ymbuffer==NULL) | (abuffer==NULL) | (sbuffer==NULL) | (cprev==NULL) | (zprev == NULL) | (oprev==NULL) | (aprev==NULL)) error(SYSTEM, "out of memory in init_frame"); + for (n = hres*vres; n--; ) { + zprev[n] = -1.f; + oprev[n] = OVOID; + } frm_stop = getTime() + rtperfrm; } else { COLOR *cp; /* else just swap buffers */ float *fp; OBJECT *op; - BYTE *bp; + uby8 *bp; cp = cprev; cprev = cbuffer; cbuffer = cp; fp = zprev; zprev = zbuffer; zbuffer = fp; op = oprev; oprev = obuffer; obuffer = op; bp = aprev; aprev = abuffer; abuffer = bp; - memset(abuffer, '\0', sizeof(BYTE)*hres*vres); - memset(sbuffer, '\0', sizeof(BYTE)*hres*vres); + memset(abuffer, '\0', sizeof(uby8)*hres*vres); + memset(sbuffer, '\0', sizeof(uby8)*hres*vres); frm_stop += rtperfrm; } cerrmap = NULL; @@ -369,8 +376,10 @@ init_frame_sample(void) /* sample our initial frame * if (!sample_here(x, y)) { /* just cast */ rayorigin(&ir, PRIMARY, NULL, NULL); if (!localhit(&ir, &thescene)) { - if (ir.ro != &Aftplane) - sourcehit(&ir); + if (ir.ro != &Aftplane && sourcehit(&ir)) { + rayshade(&ir, ir.ro->omod); + rayparticipate(&ir); + } copycolor(cbuffer[n], ir.rcol); zbuffer[n] = ir.rot; obuffer[n] = ir.robj; @@ -399,7 +408,7 @@ init_frame_sample(void) /* sample our initial frame * zbuffer[n] = ir.rot; obuffer[n] = ir.robj; sbuffer[n] = 1; - if (ir.rot >= FHUGE) + if (ir.rot >= 0.99*FHUGE) abuffer[n] = ADISTANT; else { abuffer[n] = ALOWQ; @@ -452,15 +461,12 @@ getambcolor( /* get ambient color for object if we ca if (obj == OVOID) return(0); - op = objptr(obj); - if ((op->otype == OBJ_INSTANCE) & (op->omod == OVOID)) + op = objptr(obj); /* search for material */ + if (op->omod == OVOID) return(0); - /* search for material */ - do { - if (op->omod == OVOID || ofun[op->otype].flags & T_X) - return(0); - op = objptr(op->omod); - } while (!ismaterial(op->otype)); + op = findmaterial(objptr(op->omod)); + if (op == NULL) + return(0); /* * Since this routine is called to compute the difference * from rendering with and without interreflections, @@ -474,7 +480,7 @@ getambcolor( /* get ambient color for object if we ca if (lv[0] == op->oname[0] && !strcmp(lv+1, op->oname+1)) break; - if ((lv != NULL) != hirendparams.ambincl) + if ((lv != NULL) ^ hirendparams.ambincl) return(0); } switch (op->otype) { @@ -578,7 +584,7 @@ comperr( /* estimate relative error in neighborhood * extern void comp_frame_error(void) /* initialize frame error values */ { - BYTE *edone = NULL; + uby8 *edone = NULL; COLOR objamb; double eest; int neigh[NSAMPOK]; @@ -602,7 +608,7 @@ comp_frame_error(void) /* initialize frame error valu * error should be less than the ambient value divided * by the returned ray value -- we take half of this. */ - edone = (BYTE *)calloc(hres*vres, sizeof(BYTE)); + edone = (uby8 *)calloc(hres*vres, sizeof(uby8)); for (y = vres; y--; ) for (x = hres; x--; ) { n = fndx(x, y); @@ -658,19 +664,12 @@ extern void init_frame(void) /* render base (low quality) frame */ { int restart; - /* allocate/swap buffers */ next_frame(); /* check rendering status */ restart = (!nobjects || vdef(MOVE)); if (!restart && curparams != &lorendparams && nprocs > 1) restart = -1; - if (restart > 0) { - if (nprocs > 1) - ray_pdone(1); - else - ray_done(1); - } /* post low quality parameters */ if (curparams != &lorendparams) ray_restore(curparams = &lorendparams); @@ -702,7 +701,7 @@ init_frame(void) /* render base (low quality) frame init_frame_sample(); /* initialize frame error */ comp_frame_error(); -return; +#if 0 { float *ebuf = (float *)malloc(sizeof(float)*hres*vres); char fnm[256]; @@ -714,6 +713,7 @@ return; write_map(ebuf, fnm); free((void *)ebuf); } +#endif } @@ -762,6 +762,16 @@ filter_frame(void) /* interpolation, motion-blur, an continue; nc = getclosest(neigh, NPINTERP, x, y); setcolor(cbuffer[n], 0., 0., 0.); + if (nc <= 0) { /* no acceptable neighbors */ + if (y < vres-1) + nc = fndx(x, y+1); + else if (x < hres-1) + nc = fndx(x+1, y); + else + continue; + copycolor(cbuffer[n], cbuffer[nc]); + continue; + } wsum = 0.; while (nc-- > 0) { copycolor(cval, cbuffer[neigh[nc]]); @@ -771,10 +781,8 @@ filter_frame(void) /* interpolation, motion-blur, an addcolor(cbuffer[n], cval); wsum += w; } - if (wsum > FTINY) { - w = 1.0/wsum; - scalecolor(cbuffer[n], w); - } + w = 1.0/wsum; + scalecolor(cbuffer[n], w); } /* motion blur if requested */ if (mblur > .02) { @@ -896,7 +904,7 @@ send_frame(void) /* send frame to destination */ int y; /* open output picture */ sprintf(pfname, vval(BASENAME), fcur); - strcat(pfname, ".pic"); + strcat(pfname, ".hdr"); fp = fopen(pfname, "w"); if (fp == NULL) { sprintf(errmsg, "cannot open output frame \"%s\"", pfname);