13 |
|
|
14 |
|
#include "ray.h" |
15 |
|
#include "rpaint.h" |
16 |
+ |
#include "otypes.h" |
17 |
+ |
#include "otspecial.h" |
18 |
|
#include "random.h" |
19 |
|
|
20 |
|
#ifndef WFLUSH |
21 |
< |
#define WFLUSH 64 /* flush after this many rays */ |
21 |
> |
#define WFLUSH 64 /* flush after this many primary rays */ |
22 |
|
#endif |
23 |
+ |
#ifndef WFLUSH1 |
24 |
+ |
#define WFLUSH1 512 /* or this many total rays */ |
25 |
+ |
#endif |
26 |
|
|
27 |
+ |
|
28 |
|
#ifdef SMLFLT |
29 |
|
#define sscanvec(s,v) (sscanf(s,"%f %f %f",v,v+1,v+2)==3) |
30 |
|
#else |
31 |
|
#define sscanvec(s,v) (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3) |
32 |
|
#endif |
33 |
|
|
34 |
< |
static unsigned long niflush; /* flushes since newimage() */ |
34 |
> |
extern int ray_pnprocs; |
35 |
|
|
36 |
+ |
static RNUMBER niflush; /* flushes since newimage() */ |
37 |
+ |
|
38 |
|
int |
39 |
|
getrect( /* get a box */ |
40 |
|
char *s, |
116 |
|
} |
117 |
|
if (!direc || ourview.type == VT_PAR) { |
118 |
|
rayorigin(&thisray, PRIMARY, NULL, NULL); |
119 |
< |
if (!localhit(&thisray, &thescene)) { |
119 |
> |
while (localhit(&thisray, &thescene)) { |
120 |
> |
OBJREC *m = findmaterial(thisray.ro); |
121 |
> |
if (m != NULL && !istransp(m->otype) && |
122 |
> |
!isBSDFproxy(m) && |
123 |
> |
(thisray.clipset == NULL || |
124 |
> |
!inset(thisray.clipset, |
125 |
> |
thisray.ro->omod))) |
126 |
> |
break; /* found something */ |
127 |
> |
VCOPY(thisray.rorg, thisray.rop); |
128 |
> |
rayclear(&thisray); /* skip invisible */ |
129 |
> |
} |
130 |
> |
if ((thisray.ro == NULL) | (thisray.ro == &Aftplane)) { |
131 |
|
error(COMMAND, "not a local object"); |
132 |
|
return(-1); |
133 |
|
} |
152 |
|
} |
153 |
|
|
154 |
|
|
155 |
< |
float * /* keep consistent with COLOR typedef */ |
155 |
> |
COLORV * |
156 |
|
greyof( /* convert color to greyscale */ |
157 |
|
COLOR col |
158 |
|
) |
191 |
|
PNODE *p |
192 |
|
) |
193 |
|
{ |
175 |
– |
extern int ray_pnprocs; |
176 |
– |
static unsigned long lastflush = 0; |
194 |
|
static RAY thisray; |
178 |
– |
int flushintvl; |
195 |
|
double h, v; |
196 |
|
|
197 |
< |
if (p->xmax - p->xmin <= 0 || p->ymax - p->ymin <= 0) { /* empty */ |
197 |
> |
if ((p->xmax <= p->xmin) | (p->ymax <= p->ymin)) { /* empty */ |
198 |
|
p->x = p->xmin; |
199 |
|
p->y = p->ymin; |
200 |
|
setcolor(p->v, 0.0, 0.0, 0.0); |
207 |
|
if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, &ourview, |
208 |
|
h/hresolu, v/vresolu)) < -FTINY) { |
209 |
|
setcolor(thisray.rcol, 0.0, 0.0, 0.0); |
210 |
< |
} else { |
211 |
< |
int rval; |
210 |
> |
} else if (!ray_pnprocs) { /* immediate mode */ |
211 |
> |
ray_trace(&thisray); |
212 |
> |
} else { /* queuing mode */ |
213 |
> |
int rval; |
214 |
|
rayorigin(&thisray, PRIMARY, NULL, NULL); |
215 |
< |
thisray.rno = (unsigned long)p; |
215 |
> |
thisray.rno = (RNUMBER)p; |
216 |
|
rval = ray_pqueue(&thisray); |
217 |
|
if (!rval) |
218 |
|
return(0); |
219 |
|
if (rval < 0) |
220 |
|
return(-1); |
221 |
+ |
/* get node for returned ray */ |
222 |
|
p = (PNODE *)thisray.rno; |
223 |
|
} |
224 |
|
|
227 |
|
|
228 |
|
recolor(p); /* paint it */ |
229 |
|
|
230 |
< |
if (ambounce <= 0) /* shall we check for input? */ |
231 |
< |
flushintvl = ray_pnprocs*WFLUSH; |
232 |
< |
else if (niflush < WFLUSH) |
233 |
< |
flushintvl = ray_pnprocs*niflush/(ambounce+1); |
234 |
< |
else |
235 |
< |
flushintvl = ray_pnprocs*WFLUSH/(ambounce+1); |
230 |
> |
if (dev->flush != NULL) { /* shall we check for input? */ |
231 |
> |
static RNUMBER lastflush = 0; |
232 |
> |
RNUMBER counter = raynum; |
233 |
> |
int flushintvl; |
234 |
> |
if (!ray_pnprocs) { |
235 |
> |
counter = nrays; |
236 |
> |
flushintvl = WFLUSH1; |
237 |
> |
} else if (ambounce == 0) |
238 |
> |
flushintvl = ray_pnprocs*WFLUSH; |
239 |
> |
else if (niflush < WFLUSH) |
240 |
> |
flushintvl = ray_pnprocs*niflush/(ambounce*(ambounce>0)+1); |
241 |
> |
else |
242 |
> |
flushintvl = ray_pnprocs*WFLUSH/(ambounce*(ambounce>0)+1); |
243 |
> |
if (lastflush > counter) |
244 |
> |
lastflush = 0; /* counter wrapped */ |
245 |
|
|
246 |
< |
if (dev->flush != NULL && raynum - lastflush >= flushintvl) { |
247 |
< |
lastflush = raynum; |
248 |
< |
(*dev->flush)(); |
249 |
< |
niflush++; |
246 |
> |
if (counter - lastflush >= flushintvl) { |
247 |
> |
lastflush = counter; |
248 |
> |
(*dev->flush)(); |
249 |
> |
niflush++; |
250 |
> |
} |
251 |
|
} |
252 |
|
return(1); |
253 |
|
} |
259 |
|
int nwaited = 0; |
260 |
|
int rval; |
261 |
|
RAY raydone; |
262 |
< |
|
262 |
> |
|
263 |
> |
if (!ray_pnprocs) /* immediate mode? */ |
264 |
> |
return(0); |
265 |
|
while ((rval = ray_presult(&raydone, 0)) > 0) { |
266 |
|
PNODE *p = (PNODE *)raydone.rno; |
267 |
|
copycolor(p->v, raydone.rcol); |
280 |
|
char *s |
281 |
|
) |
282 |
|
{ |
283 |
< |
int newnp; |
284 |
< |
/* change in nproc? */ |
285 |
< |
if (s != NULL && sscanf(s, "%d", &newnp) == 1 && newnp > 0) { |
286 |
< |
if (!newparam) { |
256 |
< |
if (newnp < nproc) |
257 |
< |
ray_pclose(nproc - newnp); |
258 |
< |
else |
259 |
< |
ray_popen(newnp - nproc); |
260 |
< |
} |
261 |
< |
nproc = newnp; |
262 |
< |
} |
283 |
> |
int newnp = 0; |
284 |
> |
/* # rendering procs arg? */ |
285 |
> |
if (s != NULL) |
286 |
> |
sscanf(s, "%d", &newnp); |
287 |
|
/* free old image */ |
288 |
|
freepkids(&ptrunk); |
289 |
|
/* compute resolution */ |
298 |
|
(*dev->clear)(hresolu, vresolu); |
299 |
|
|
300 |
|
if (newparam) { /* (re)start rendering procs */ |
301 |
< |
ray_pclose(0); |
302 |
< |
ray_popen(nproc); |
301 |
> |
if (ray_pnprocs) |
302 |
> |
ray_pclose(0); /* should already be closed */ |
303 |
> |
if (newnp > 0) |
304 |
> |
nproc = newnp; |
305 |
> |
if (nproc > 1) |
306 |
> |
ray_popen(nproc); |
307 |
|
newparam = 0; |
308 |
+ |
} else if ((newnp > 0) & (newnp != nproc)) { |
309 |
+ |
if (newnp == 1) /* change # rendering procs */ |
310 |
+ |
ray_pclose(0); |
311 |
+ |
else if (newnp < ray_pnprocs) |
312 |
+ |
ray_pclose(ray_pnprocs - newnp); |
313 |
+ |
else |
314 |
+ |
ray_popen(newnp - ray_pnprocs); |
315 |
+ |
nproc = newnp; |
316 |
|
} |
317 |
|
niflush = 0; /* get first value */ |
318 |
|
paint(&ptrunk); |
417 |
|
PNODE *p |
418 |
|
) |
419 |
|
{ |
420 |
+ |
int i, navg; |
421 |
+ |
|
422 |
|
if (p->kid == NULL) |
423 |
|
return; |
424 |
< |
compavg(p->kid+DL); |
387 |
< |
compavg(p->kid+DR); |
388 |
< |
compavg(p->kid+UL); |
389 |
< |
compavg(p->kid+UR); |
424 |
> |
|
425 |
|
setcolor(p->v, .0, .0, .0); |
426 |
< |
addcolor(p->v, p->kid[DL].v); |
427 |
< |
addcolor(p->v, p->kid[DR].v); |
428 |
< |
addcolor(p->v, p->kid[UL].v); |
429 |
< |
addcolor(p->v, p->kid[UR].v); |
430 |
< |
scalecolor(p->v, 0.25); |
426 |
> |
navg = 0; |
427 |
> |
for (i = 0; i < 4; i++) { |
428 |
> |
if (p->kid[i].xmin >= p->kid[i].xmax) continue; |
429 |
> |
if (p->kid[i].ymin >= p->kid[i].ymax) continue; |
430 |
> |
compavg(p->kid+i); |
431 |
> |
addcolor(p->v, p->kid[i].v); |
432 |
> |
navg++; |
433 |
> |
} |
434 |
> |
if (navg > 1) |
435 |
> |
scalecolor(p->v, 1./navg); |
436 |
|
} |
437 |
|
|
438 |
|
|
530 |
|
) |
531 |
|
{ |
532 |
|
double d; |
493 |
– |
FVECT v1; |
533 |
|
VIEW nv = ourview; |
534 |
|
int i; |
535 |
|
|
536 |
|
spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.)); |
537 |
< |
if (elev != 0.0) { |
538 |
< |
fcross(v1, ourview.vup, nv.vdir); |
539 |
< |
normalize(v1); |
501 |
< |
spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.)); |
502 |
< |
} |
537 |
> |
if (elev != 0.0) |
538 |
> |
geodesic(nv.vdir, nv.vdir, nv.vup, elev*(-PI/180.), GEOD_RAD); |
539 |
> |
|
540 |
|
if (nv.type == VT_PAR) { |
541 |
|
nv.horiz /= mag; |
542 |
|
nv.vert /= mag; |