--- ray/src/util/ranimove1.c 2004/03/26 21:36:20 3.8 +++ ray/src/util/ranimove1.c 2010/11/05 04:36:24 3.16 @@ -1,10 +1,10 @@ #ifndef lint -static const char RCSid[] = "$Id: ranimove1.c,v 3.8 2004/03/26 21:36:20 schorsch Exp $"; +static const char RCSid[] = "$Id: ranimove1.c,v 3.16 2010/11/05 04:36:24 greg Exp $"; #endif /* * ranimove1.c * - * Basic frame rendering routines for ranimate(1). + * Basic frame rendering routines for ranimove(1). * * Created by Gregory Ward on Wed Jan 08 2003. */ @@ -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)) { @@ -140,6 +143,10 @@ next_frame(void) /* prepare next frame buffer */ (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 */ @@ -367,10 +374,12 @@ init_frame_sample(void) /* sample our initial frame * continue; } if (!sample_here(x, y)) { /* just cast */ - rayorigin(&ir, NULL, PRIMARY, 1.0); + 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; @@ -385,7 +394,7 @@ init_frame_sample(void) /* sample our initial frame * } if (nprocs > 1) { /* get sample */ int rval; - rayorigin(&ir, NULL, PRIMARY, 1.0); + rayorigin(&ir, PRIMARY, NULL, NULL); ir.rno = n; rval = ray_pqueue(&ir); if (!rval) @@ -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) { @@ -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 } @@ -745,51 +745,57 @@ filter_frame(void) /* interpolation, motion-blur, an printf("\tFiltering frame\n"); fflush(stdout); } - /* normalize samples */ - for (y = vres; y--; ) { - for (x = hres; x--; ) { - n = fndx(x, y); - if (sbuffer[n] <= 1) + /* normalize samples */ + for (y = vres; y--; ) + for (x = hres; x--; ) { + n = fndx(x, y); + if (sbuffer[n] <= 1) + continue; + w = 1.0/(double)sbuffer[n]; + scalecolor(cbuffer[n], w); + } + /* interpolate samples */ + for (y = vres; y--; ) + for (x = hres; x--; ) { + n = fndx(x, y); + if (sbuffer[n]) + 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; - w = 1.0/(double)sbuffer[n]; - scalecolor(cbuffer[n], w); + copycolor(cbuffer[n], cbuffer[nc]); + continue; } - } - /* interpolate samples */ - for (y = vres; y--; ) { - for (x = hres; x--; ) { - n = fndx(x, y); - if (sbuffer[n]) - continue; - nc = getclosest(neigh, NPINTERP, x, y); - setcolor(cbuffer[n], 0., 0., 0.); - wsum = 0.; - while (nc-- > 0) { - copycolor(cval, cbuffer[neigh[nc]]); - w = sample_wt((neigh[nc]%hres) - x, - (neigh[nc]/hres) - y); - scalecolor(cval, w); - addcolor(cbuffer[n], cval); - wsum += w; - } - if (wsum > FTINY) { - w = 1.0/wsum; - scalecolor(cbuffer[n], w); - } + wsum = 0.; + while (nc-- > 0) { + copycolor(cval, cbuffer[neigh[nc]]); + w = sample_wt((neigh[nc]%hres) - x, + (neigh[nc]/hres) - y); + scalecolor(cval, w); + addcolor(cbuffer[n], cval); + wsum += w; } - } - /* motion blur if requested */ + w = 1.0/wsum; + scalecolor(cbuffer[n], w); + } + /* motion blur if requested */ if (mblur > .02) { - int xs, ys, xl, yl; - int rise, run; - long rise2, run2; - int n2; - int cnt; - /* sum in motion streaks */ - memset(outbuffer, '\0', sizeof(COLOR)*hres*vres); - memset(wbuffer, '\0', sizeof(float)*hres*vres); - for (y = vres; y--; ) { - for (x = hres; x--; ) { + int xs, ys, xl, yl; + int rise, run; + long rise2, run2; + int n2; + int cnt; + /* sum in motion streaks */ + memset(outbuffer, '\0', sizeof(COLOR)*hres*vres); + memset(wbuffer, '\0', sizeof(float)*hres*vres); + for (y = vres; y--; ) + for (x = hres; x--; ) { n = fndx(x, y); if (xmbuffer[n] == MO_UNK) { run = rise = 0; @@ -810,76 +816,71 @@ filter_frame(void) /* interpolation, motion-blur, an else ys = 1; rise2 = run2 = 0L; if (rise > run) { - cnt = rise + 1; - w = 1./cnt; - copycolor(cval, cbuffer[n]); - scalecolor(cval, w); - while (cnt) { - if (rise2 >= run2) { - if ((xl >= 0) & (xl < hres) & + cnt = rise + 1; + w = 1./cnt; + copycolor(cval, cbuffer[n]); + scalecolor(cval, w); + while (cnt) + if (rise2 >= run2) { + if ((xl >= 0) & (xl < hres) & (yl >= 0) & (yl < vres)) { - n2 = fndx(xl, yl); - addcolor(outbuffer[n2], cval); - wbuffer[n2] += w; - } - yl += ys; - run2 += run; - cnt--; - } else { - xl += xs; - rise2 += rise; - } - } + n2 = fndx(xl, yl); + addcolor(outbuffer[n2], + cval); + wbuffer[n2] += w; + } + yl += ys; + run2 += run; + cnt--; + } else { + xl += xs; + rise2 += rise; + } } else { cnt = run + 1; w = 1./cnt; copycolor(cval, cbuffer[n]); scalecolor(cval, w); - while (cnt) { - if (run2 >= rise2) { - if ((xl >= 0) & (xl < hres) & + while (cnt) + if (run2 >= rise2) { + if ((xl >= 0) & (xl < hres) & (yl >= 0) & (yl < vres)) { - n2 = fndx(xl, yl); - addcolor(outbuffer[n2], - cval); - wbuffer[n2] += w; + n2 = fndx(xl, yl); + addcolor(outbuffer[n2], + cval); + wbuffer[n2] += w; + } + xl += xs; + rise2 += rise; + cnt--; + } else { + yl += ys; + run2 += run; } - xl += xs; - rise2 += rise; - cnt--; - } else { - yl += ys; - run2 += run; - } - } } - } - /* compute final results */ - for (y = vres; y--; ) { - for (x = hres; x--; ) { - n = fndx(x, y); - if (wbuffer[n] <= FTINY) - continue; - w = 1./wbuffer[n]; - scalecolor(outbuffer[n], w); - } - } - } - } else { - for (n = hres*vres; n--; ) { + } + /* compute final results */ + for (y = vres; y--; ) + for (x = hres; x--; ) { + n = fndx(x, y); + if (wbuffer[n] <= FTINY) + continue; + w = 1./wbuffer[n]; + scalecolor(outbuffer[n], w); + } + } else + for (n = hres*vres; n--; ) copycolor(outbuffer[n], cbuffer[n]); - } - } /* for (n = hres*vres; n--; ) - if (!sbuffer[n]) - setcolor(outbuffer[n], 0., 0., 0.); + if (!sbuffer[n]) + setcolor(outbuffer[n], 0., 0., 0.); */ /* adjust exposure */ if ((expval < 0.99) | (expval > 1.01)) for (n = hres*vres; n--; ) scalecolor(outbuffer[n], expval); - return; +#if 0 { float *sbuf = (float *)malloc(sizeof(float)*hres*vres); char fnm[256]; @@ -890,6 +891,7 @@ filter_frame(void) /* interpolation, motion-blur, an write_map(sbuf, fnm); free((void *)sbuf); } +#endif } @@ -902,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);