11 |
|
|
12 |
|
#include "ray.h" |
13 |
|
#include "view.h" |
14 |
+ |
#include "otypes.h" |
15 |
+ |
#include "otspecial.h" |
16 |
|
#include "source.h" |
17 |
|
|
18 |
|
|
71 |
|
|
72 |
|
static void |
73 |
|
clipregion( /* find intersection with boundary */ |
74 |
< |
register RREAL a[2], |
75 |
< |
register RREAL b[2], |
74 |
> |
RREAL a[2], |
75 |
> |
RREAL b[2], |
76 |
|
double cv, |
77 |
|
int crit, |
78 |
|
RREAL r[2] /* return value */ |
103 |
|
) |
104 |
|
{ |
105 |
|
RREAL *s, *p; |
106 |
< |
register int j, nvo; |
106 |
> |
int j, nvo; |
107 |
|
|
108 |
|
s = vl[nv-1]; |
109 |
|
nvo = 0; |
152 |
|
) |
153 |
|
{ |
154 |
|
double d2, w2, w2min, w2max; |
155 |
< |
register RREAL *p0, *p1, *p2; |
155 |
> |
RREAL *p0, *p1, *p2; |
156 |
|
int i, j; |
157 |
|
/* find minimum for all widths */ |
158 |
|
w2min = FHUGE; |
180 |
|
|
181 |
|
static void |
182 |
|
convex_center( /* compute center of convex polygon */ |
183 |
< |
register RREAL vl[][2], |
183 |
> |
RREAL vl[][2], |
184 |
|
int nv, |
185 |
|
RREAL cv[2] /* return value */ |
186 |
|
) |
187 |
|
{ |
188 |
< |
register int i; |
188 |
> |
int i; |
189 |
|
/* simple average (suboptimal) */ |
190 |
|
cv[0] = cv[1] = 0.; |
191 |
|
for (i = 0; i < nv; i++) { |
199 |
|
|
200 |
|
static double |
201 |
|
poly_area( /* compute area of polygon */ |
202 |
< |
register RREAL vl[][2], |
202 |
> |
RREAL vl[][2], |
203 |
|
int nv |
204 |
|
) |
205 |
|
{ |
206 |
|
double a; |
207 |
|
RREAL v0[2], v1[2]; |
208 |
< |
register int i; |
208 |
> |
int i; |
209 |
|
|
210 |
|
a = 0.; |
211 |
|
v0[0] = vl[1][0] - vl[0][0]; |
230 |
|
int nvo, nvt; |
231 |
|
RREAL vlt[MAXVERT][2]; |
232 |
|
double voa, vta; |
233 |
< |
register int i, j; |
233 |
> |
int i, j; |
234 |
|
/* start with original polygon */ |
235 |
|
for (i = nvo = nv; i--; ) { |
236 |
|
vlo[i][0] = vl[i][0]; vlo[i][1] = vl[i][1]; |
264 |
|
int nv |
265 |
|
) |
266 |
|
{ |
267 |
< |
register SPLIST *spn; |
268 |
< |
register int i; |
267 |
> |
SPLIST *spn; |
268 |
> |
int i; |
269 |
|
|
270 |
|
if (nv < 3) |
271 |
|
return; |
294 |
|
{0,1,3,7,6,4},{0,1,5,7,6,2}, |
295 |
|
{0,2,6,7,5,1},{0,4,6,7,3,1}, |
296 |
|
{0,2,3,7,5,4},{1,5,4,6,2,3}}; |
297 |
< |
register SRCREC *s = source + sn; |
297 |
> |
SRCREC *s = source + sn; |
298 |
|
FVECT ap, ip; |
299 |
|
RREAL pt[6][2]; |
300 |
|
int dir; |
301 |
< |
register int i, j; |
301 |
> |
int i, j; |
302 |
|
|
303 |
|
if (s->sflags & (SDISTANT|SFLAT)) { |
304 |
|
if (s->sflags & SDISTANT) { |
325 |
|
ap[i] += ourview.vp[i]; |
326 |
|
} |
327 |
|
} |
328 |
< |
viewloc(ip, &ourview, ap); /* find image point */ |
329 |
< |
if (ip[2] <= 0.) |
328 |
> |
/* find image point */ |
329 |
> |
if (viewloc(ip, &ourview, ap) != VL_GOOD) |
330 |
|
return(0); /* in front of view */ |
331 |
|
sp[j][0] = ip[0]; sp[j][1] = ip[1]; |
332 |
|
} |
349 |
|
if (cubeord[dir][j] & 4) ap[i] += s->ss[SW][i]; |
350 |
|
else ap[i] -= s->ss[SW][i]; |
351 |
|
} |
352 |
< |
viewloc(ip, &ourview, ap); /* find image point */ |
353 |
< |
if (ip[2] <= 0.) |
352 |
> |
/* find image point */ |
353 |
> |
if (viewloc(ip, &ourview, ap) != VL_GOOD) |
354 |
|
return(0); /* in front of view */ |
355 |
|
pt[j][0] = ip[0]; pt[j][1] = ip[1]; |
356 |
|
} |
359 |
|
|
360 |
|
|
361 |
|
/* initialize by finding sources smaller than rad */ |
362 |
< |
extern void |
362 |
> |
void |
363 |
|
init_drawsources( |
364 |
|
int rad /* source sample size */ |
365 |
|
) |
366 |
|
{ |
367 |
|
RREAL spoly[MAXVERT][2]; |
368 |
|
int nsv; |
369 |
< |
register SPLIST *sp; |
370 |
< |
register int i; |
369 |
> |
SPLIST *sp; |
370 |
> |
int i; |
371 |
|
/* free old source list if one */ |
372 |
|
for (sp = sphead; sp != NULL; sp = sphead) { |
373 |
|
sphead = sp->next; |
375 |
|
} |
376 |
|
/* loop through all sources */ |
377 |
|
for (i = nsources; i--; ) { |
378 |
+ |
/* skip illum's */ |
379 |
+ |
if (findmaterial(source[i].so)->otype == MAT_ILLUM) |
380 |
+ |
continue; |
381 |
|
/* compute image polygon for source */ |
382 |
|
if (!(nsv = sourcepoly(i, spoly))) |
383 |
|
continue; |
393 |
|
} |
394 |
|
} |
395 |
|
|
396 |
< |
extern void /* add sources smaller than rad to computed subimage */ |
396 |
> |
void /* add sources smaller than rad to computed subimage */ |
397 |
|
drawsources( |
398 |
< |
COLOR *pic[], /* subimage pixel value array */ |
398 |
> |
COLORV *pic[], /* subimage pixel value array */ |
399 |
> |
int nc, /* number of target components */ |
400 |
|
float *zbf[], /* subimage distance array (opt.) */ |
401 |
|
int x0, /* origin and size of subimage */ |
402 |
|
int xsiz, |
408 |
|
int nsv, npv; |
409 |
|
int xmin, xmax, ymin, ymax, x, y; |
410 |
|
RREAL cxy[2]; |
411 |
+ |
COLOR rcol; |
412 |
|
double w; |
413 |
|
RAY sr; |
414 |
< |
register SPLIST *sp; |
415 |
< |
register int i; |
414 |
> |
SPLIST *sp; |
415 |
> |
int i; |
416 |
> |
/* check #components */ |
417 |
> |
if ((nc != 3) & (nc != NCSAMP)) |
418 |
> |
error(INTERNAL, "unsupported #components in drawsources()"); |
419 |
|
/* check each source in our list */ |
420 |
|
for (sp = sphead; sp != NULL; sp = sp->next) { |
421 |
|
/* clip source poly to subimage */ |
438 |
|
ymax = spoly[i][1]*vres - FTINY; |
439 |
|
} |
440 |
|
/* evaluate each pixel in BBox */ |
441 |
< |
for (y = ymin; y <= ymax; y++) |
442 |
< |
for (x = xmin; x <= xmax; x++) { |
441 |
> |
for (y = ymin; y <= ymax; y++) { |
442 |
> |
COLORV *pp = pic[y-y0] + (xmin-x0)*nc; |
443 |
> |
for (x = xmin; x <= xmax; x++, pp += nc) { |
444 |
|
/* subarea for pixel */ |
445 |
|
npv = box_clip_poly(spoly, nsv, |
446 |
|
(double)x/hres, (x+1.)/hres, |
455 |
|
if (source[sp->sn].sflags & SSPOT && |
456 |
|
spotout(&sr, source[sp->sn].sl.s)) |
457 |
|
continue; /* outside spot */ |
458 |
< |
w = poly_area(ppoly, npv) * hres * vres; |
459 |
< |
if (w < .95) { /* subpixel source */ |
449 |
< |
rayorigin(&sr, NULL, SHADOW, 1.0); |
450 |
< |
sr.rsrc = sp->sn; |
451 |
< |
} else |
452 |
< |
rayorigin(&sr, NULL, PRIMARY, 1.0); |
458 |
> |
rayorigin(&sr, SHADOW, NULL, NULL); |
459 |
> |
sr.rsrc = sp->sn; |
460 |
|
rayvalue(&sr); /* compute value */ |
461 |
< |
if (bright(sr.rcol) <= FTINY) |
461 |
> |
if (sintens(sr.rcol) <= FTINY) |
462 |
|
continue; /* missed/blocked */ |
463 |
+ |
if (nc == 3) |
464 |
+ |
scolor_rgb(rcol, sr.rcol); |
465 |
|
/* modify pixel */ |
466 |
+ |
w = poly_area(ppoly, npv) * hres * vres; |
467 |
|
if (zbf[y-y0] != NULL && |
468 |
< |
sr.rt < 0.99*zbf[y-y0][x-x0]) { |
469 |
< |
zbf[y-y0][x-x0] = sr.rt; |
470 |
< |
} else if (!bigdiff(sr.rcol, pic[y-y0][x-x0], |
471 |
< |
0.01)) { /* source sample */ |
472 |
< |
scalecolor(pic[y-y0][x-x0], w); |
468 |
> |
sr.rxt < 0.99*zbf[y-y0][x-x0]) { |
469 |
> |
zbf[y-y0][x-x0] = sr.rxt; |
470 |
> |
} else if (nc == 3) { |
471 |
> |
if (!bigdiff(rcol, pp, 0.07)) { |
472 |
> |
scalecolor(pp, w); |
473 |
> |
continue; |
474 |
> |
} |
475 |
> |
} else if (!sbigsdiff(sr.rcol, pp, 0.07)) { |
476 |
> |
scalescolor(pp, w); |
477 |
|
continue; |
478 |
|
} |
479 |
< |
scalecolor(sr.rcol, w); |
480 |
< |
scalecolor(pic[y-y0][x-x0], 1.-w); |
481 |
< |
addcolor(pic[y-y0][x-x0], sr.rcol); |
479 |
> |
if (nc == 3) { |
480 |
> |
scalecolor(rcol, w); |
481 |
> |
scalecolor(pp, 1.-w); |
482 |
> |
addcolor(pp, rcol); |
483 |
> |
} else { |
484 |
> |
scalescolor(sr.rcol, w); |
485 |
> |
scalescolor(pp, 1.-w); |
486 |
> |
saddscolor(pp, sr.rcol); |
487 |
> |
} |
488 |
|
} |
489 |
+ |
} |
490 |
|
} |
491 |
|
} |