7 |
|
* External symbols declared in ray.h |
8 |
|
*/ |
9 |
|
|
10 |
< |
/* ==================================================================== |
11 |
< |
* The Radiance Software License, Version 1.0 |
12 |
< |
* |
13 |
< |
* Copyright (c) 1990 - 2002 The Regents of the University of California, |
14 |
< |
* through Lawrence Berkeley National Laboratory. All rights reserved. |
15 |
< |
* |
16 |
< |
* Redistribution and use in source and binary forms, with or without |
17 |
< |
* modification, are permitted provided that the following conditions |
18 |
< |
* are met: |
19 |
< |
* |
20 |
< |
* 1. Redistributions of source code must retain the above copyright |
21 |
< |
* notice, this list of conditions and the following disclaimer. |
22 |
< |
* |
23 |
< |
* 2. Redistributions in binary form must reproduce the above copyright |
24 |
< |
* notice, this list of conditions and the following disclaimer in |
25 |
< |
* the documentation and/or other materials provided with the |
26 |
< |
* distribution. |
27 |
< |
* |
28 |
< |
* 3. The end-user documentation included with the redistribution, |
29 |
< |
* if any, must include the following acknowledgment: |
30 |
< |
* "This product includes Radiance software |
31 |
< |
* (http://radsite.lbl.gov/) |
32 |
< |
* developed by the Lawrence Berkeley National Laboratory |
33 |
< |
* (http://www.lbl.gov/)." |
34 |
< |
* Alternately, this acknowledgment may appear in the software itself, |
35 |
< |
* if and wherever such third-party acknowledgments normally appear. |
36 |
< |
* |
37 |
< |
* 4. The names "Radiance," "Lawrence Berkeley National Laboratory" |
38 |
< |
* and "The Regents of the University of California" must |
39 |
< |
* not be used to endorse or promote products derived from this |
40 |
< |
* software without prior written permission. For written |
41 |
< |
* permission, please contact [email protected]. |
42 |
< |
* |
43 |
< |
* 5. Products derived from this software may not be called "Radiance", |
44 |
< |
* nor may "Radiance" appear in their name, without prior written |
45 |
< |
* permission of Lawrence Berkeley National Laboratory. |
46 |
< |
* |
47 |
< |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED |
48 |
< |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
49 |
< |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
50 |
< |
* DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR |
51 |
< |
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
52 |
< |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
53 |
< |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
54 |
< |
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
55 |
< |
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
56 |
< |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
57 |
< |
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
58 |
< |
* SUCH DAMAGE. |
59 |
< |
* ==================================================================== |
60 |
< |
* |
61 |
< |
* This software consists of voluntary contributions made by many |
62 |
< |
* individuals on behalf of Lawrence Berkeley National Laboratory. For more |
63 |
< |
* information on Lawrence Berkeley National Laboratory, please see |
64 |
< |
* <http://www.lbl.gov/>. |
65 |
< |
*/ |
10 |
> |
#include "copyright.h" |
11 |
|
|
12 |
|
#include "ray.h" |
68 |
– |
|
13 |
|
#include "view.h" |
14 |
< |
|
14 |
> |
#include "otypes.h" |
15 |
> |
#include "otspecial.h" |
16 |
|
#include "source.h" |
17 |
|
|
18 |
|
|
27 |
|
struct splist *next; /* next source in list */ |
28 |
|
int sn; /* source number */ |
29 |
|
short nv; /* number of vertices */ |
30 |
< |
FLOAT vl[3][2]; /* vertex array (last) */ |
30 |
> |
RREAL vl[3][2]; /* vertex array (last) */ |
31 |
|
} SPLIST; /* source polygon list */ |
32 |
|
|
33 |
|
extern VIEW ourview; /* our view parameters */ |
34 |
|
extern int hres, vres; /* our image resolution */ |
35 |
|
static SPLIST *sphead = NULL; /* our list of source polys */ |
36 |
|
|
37 |
+ |
static int inregion(RREAL p[2], double cv, int crit); |
38 |
+ |
static void clipregion(RREAL a[2], RREAL b[2], double cv, int crit, RREAL r[2]); |
39 |
+ |
static int hp_clip_poly(RREAL vl[][2], int nv, double cv, int crit, |
40 |
+ |
RREAL vlo[][2]); |
41 |
+ |
static int box_clip_poly(RREAL vl[MAXVERT][2], int nv, |
42 |
+ |
double xl, double xr, double yb, double ya, RREAL vlo[MAXVERT][2]); |
43 |
+ |
static double minw2(RREAL vl[][2], int nv, double ar2); |
44 |
+ |
static void convex_center(RREAL vl[][2], int nv, RREAL cv[2]); |
45 |
+ |
static double poly_area(RREAL vl[][2], int nv); |
46 |
+ |
static int convex_hull(RREAL vl[][2], int nv, RREAL vlo[][2]); |
47 |
+ |
static void spinsert(int sn, RREAL vl[][2], int nv); |
48 |
+ |
static int sourcepoly(int sn, RREAL sp[MAXVERT][2]); |
49 |
|
|
50 |
+ |
|
51 |
|
static int |
52 |
< |
inregion(p, cv, crit) /* check if vertex is in region */ |
53 |
< |
FLOAT p[2]; |
54 |
< |
double cv; |
55 |
< |
int crit; |
52 |
> |
inregion( /* check if vertex is in region */ |
53 |
> |
RREAL p[2], |
54 |
> |
double cv, |
55 |
> |
int crit |
56 |
> |
) |
57 |
|
{ |
58 |
|
switch (crit) { |
59 |
|
case CLIP_ABOVE: |
69 |
|
} |
70 |
|
|
71 |
|
|
72 |
< |
static |
73 |
< |
clipregion(a, b, cv, crit, r) /* find intersection with boundary */ |
74 |
< |
register FLOAT a[2], b[2]; |
75 |
< |
double cv; |
76 |
< |
int crit; |
77 |
< |
FLOAT r[2]; /* return value */ |
72 |
> |
static void |
73 |
> |
clipregion( /* find intersection with boundary */ |
74 |
> |
RREAL a[2], |
75 |
> |
RREAL b[2], |
76 |
> |
double cv, |
77 |
> |
int crit, |
78 |
> |
RREAL r[2] /* return value */ |
79 |
> |
) |
80 |
|
{ |
81 |
|
switch (crit) { |
82 |
|
case CLIP_ABOVE: |
94 |
|
|
95 |
|
|
96 |
|
static int |
97 |
< |
hp_clip_poly(vl, nv, cv, crit, vlo) /* clip polygon to half-plane */ |
98 |
< |
FLOAT vl[][2]; |
99 |
< |
int nv; |
100 |
< |
double cv; |
101 |
< |
int crit; |
102 |
< |
FLOAT vlo[][2]; /* return value */ |
97 |
> |
hp_clip_poly( /* clip polygon to half-plane */ |
98 |
> |
RREAL vl[][2], |
99 |
> |
int nv, |
100 |
> |
double cv, |
101 |
> |
int crit, |
102 |
> |
RREAL vlo[][2] /* return value */ |
103 |
> |
) |
104 |
|
{ |
105 |
< |
FLOAT *s, *p; |
106 |
< |
register int j, nvo; |
105 |
> |
RREAL *s, *p; |
106 |
> |
int j, nvo; |
107 |
|
|
108 |
|
s = vl[nv-1]; |
109 |
|
nvo = 0; |
122 |
|
|
123 |
|
|
124 |
|
static int |
125 |
< |
box_clip_poly(vl, nv, xl, xr, yb, ya, vlo) /* clip polygon to box */ |
126 |
< |
FLOAT vl[MAXVERT][2]; |
127 |
< |
int nv; |
128 |
< |
double xl, xr, yb, ya; |
129 |
< |
FLOAT vlo[MAXVERT][2]; /* return value */ |
125 |
> |
box_clip_poly( /* clip polygon to box */ |
126 |
> |
RREAL vl[MAXVERT][2], |
127 |
> |
int nv, |
128 |
> |
double xl, |
129 |
> |
double xr, |
130 |
> |
double yb, |
131 |
> |
double ya, |
132 |
> |
RREAL vlo[MAXVERT][2] /* return value */ |
133 |
> |
) |
134 |
|
{ |
135 |
< |
FLOAT vlt[MAXVERT][2]; |
135 |
> |
RREAL vlt[MAXVERT][2]; |
136 |
|
int nvt, nvo; |
137 |
|
|
138 |
|
nvt = hp_clip_poly(vl, nv, yb, CLIP_BELOW, vlt); |
145 |
|
|
146 |
|
|
147 |
|
static double |
148 |
< |
minw2(vl, nv, ar2) /* compute square of minimum width */ |
149 |
< |
FLOAT vl[][2]; |
150 |
< |
int nv; |
151 |
< |
double ar2; |
148 |
> |
minw2( /* compute square of minimum width */ |
149 |
> |
RREAL vl[][2], |
150 |
> |
int nv, |
151 |
> |
double ar2 |
152 |
> |
) |
153 |
|
{ |
154 |
|
double d2, w2, w2min, w2max; |
155 |
< |
register FLOAT *p0, *p1, *p2; |
155 |
> |
RREAL *p0, *p1, *p2; |
156 |
|
int i, j; |
157 |
|
/* find minimum for all widths */ |
158 |
|
w2min = FHUGE; |
178 |
|
} |
179 |
|
|
180 |
|
|
181 |
< |
static |
182 |
< |
convex_center(vl, nv, cv) /* compute center of convex polygon */ |
183 |
< |
register FLOAT vl[][2]; |
184 |
< |
int nv; |
185 |
< |
FLOAT cv[2]; /* return value */ |
181 |
> |
static void |
182 |
> |
convex_center( /* compute center of convex polygon */ |
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++) { |
198 |
|
|
199 |
|
|
200 |
|
static double |
201 |
< |
poly_area(vl, nv) /* compute area of polygon */ |
202 |
< |
register FLOAT vl[][2]; |
203 |
< |
int nv; |
201 |
> |
poly_area( /* compute area of polygon */ |
202 |
> |
RREAL vl[][2], |
203 |
> |
int nv |
204 |
> |
) |
205 |
|
{ |
206 |
|
double a; |
207 |
< |
FLOAT v0[2], v1[2]; |
208 |
< |
register int i; |
207 |
> |
RREAL v0[2], v1[2]; |
208 |
> |
int i; |
209 |
|
|
210 |
|
a = 0.; |
211 |
|
v0[0] = vl[1][0] - vl[0][0]; |
221 |
|
|
222 |
|
|
223 |
|
static int |
224 |
< |
convex_hull(vl, nv, vlo) /* compute polygon's convex hull */ |
225 |
< |
FLOAT vl[][2]; |
226 |
< |
int nv; |
227 |
< |
FLOAT vlo[][2]; /* return value */ |
224 |
> |
convex_hull( /* compute polygon's convex hull */ |
225 |
> |
RREAL vl[][2], |
226 |
> |
int nv, |
227 |
> |
RREAL vlo[][2] /* return value */ |
228 |
> |
) |
229 |
|
{ |
230 |
|
int nvo, nvt; |
231 |
< |
FLOAT vlt[MAXVERT][2]; |
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]; |
257 |
|
} |
258 |
|
|
259 |
|
|
260 |
< |
static |
261 |
< |
spinsert(sn, vl, nv) /* insert new source polygon */ |
262 |
< |
int sn; |
263 |
< |
FLOAT vl[][2]; |
264 |
< |
int nv; |
260 |
> |
static void |
261 |
> |
spinsert( /* insert new source polygon */ |
262 |
> |
int sn, |
263 |
> |
RREAL vl[][2], |
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; |
272 |
|
if (nv > 3) |
273 |
< |
spn = (SPLIST *)malloc(sizeof(SPLIST)+sizeof(FLOAT)*2*(nv-3)); |
273 |
> |
spn = (SPLIST *)malloc(sizeof(SPLIST)+sizeof(RREAL)*2*(nv-3)); |
274 |
|
else |
275 |
|
spn = (SPLIST *)malloc(sizeof(SPLIST)); |
276 |
|
if (spn == NULL) |
284 |
|
} |
285 |
|
|
286 |
|
|
287 |
< |
int |
288 |
< |
sourcepoly(sn, sp) /* compute image polygon for source */ |
289 |
< |
int sn; |
290 |
< |
FLOAT sp[MAXVERT][2]; |
287 |
> |
static int |
288 |
> |
sourcepoly( /* compute image polygon for source */ |
289 |
> |
int sn, |
290 |
> |
RREAL sp[MAXVERT][2] |
291 |
> |
) |
292 |
|
{ |
293 |
< |
static char cubeord[8][6] = {{1,3,2,6,4,5},{0,4,5,7,3,2}, |
293 |
> |
static short cubeord[8][6] = {{1,3,2,6,4,5},{0,4,5,7,3,2}, |
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 |
< |
FLOAT pt[6][2]; |
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 && ourview.type == VT_PAR) |
305 |
< |
return(0); /* all or nothing case */ |
304 |
> |
if (s->sflags & SDISTANT) { |
305 |
> |
if (ourview.type == VT_PAR) |
306 |
> |
return(0); /* all or nothing case */ |
307 |
> |
if (s->srad >= 0.05) |
308 |
> |
return(0); /* should never be a problem */ |
309 |
> |
} |
310 |
|
if (s->sflags & SFLAT) { |
311 |
|
for (i = 0; i < 3; i++) |
312 |
|
ap[i] = s->sloc[i] - ourview.vp[i]; |
316 |
|
for (j = 0; j < 4; j++) { /* four corners */ |
317 |
|
for (i = 0; i < 3; i++) { |
318 |
|
ap[i] = s->sloc[i]; |
319 |
< |
if (j==1|j==2) ap[i] += s->ss[SU][i]; |
319 |
> |
if ((j==1)|(j==2)) ap[i] += s->ss[SU][i]; |
320 |
|
else ap[i] -= s->ss[SU][i]; |
321 |
< |
if (j==2|j==3) ap[i] += s->ss[SV][i]; |
321 |
> |
if ((j==2)|(j==3)) ap[i] += s->ss[SV][i]; |
322 |
|
else ap[i] -= s->ss[SV][i]; |
323 |
|
if (s->sflags & SDISTANT) { |
324 |
|
ap[i] *= 1. + ourview.vfore; |
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 |
< |
init_drawsources(rad) |
363 |
< |
int rad; /* source sample size */ |
362 |
> |
void |
363 |
> |
init_drawsources( |
364 |
> |
int rad /* source sample size */ |
365 |
> |
) |
366 |
|
{ |
367 |
< |
FLOAT spoly[MAXVERT][2]; |
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 |
< |
void /* add sources smaller than rad to computed subimage */ |
397 |
< |
drawsources(pic, zbf, x0, xsiz, y0, ysiz) |
398 |
< |
COLOR *pic[]; /* subimage pixel value array */ |
399 |
< |
float *zbf[]; /* subimage distance array (opt.) */ |
400 |
< |
int x0, xsiz, y0, ysiz; /* origin and size of subimage */ |
396 |
> |
void /* add sources smaller than rad to computed subimage */ |
397 |
> |
drawsources( |
398 |
> |
COLOR *pic[], /* subimage pixel value array */ |
399 |
> |
float *zbf[], /* subimage distance array (opt.) */ |
400 |
> |
int x0, /* origin and size of subimage */ |
401 |
> |
int xsiz, |
402 |
> |
int y0, |
403 |
> |
int ysiz |
404 |
> |
) |
405 |
|
{ |
406 |
< |
FLOAT spoly[MAXVERT][2], ppoly[MAXVERT][2]; |
406 |
> |
RREAL spoly[MAXVERT][2], ppoly[MAXVERT][2]; |
407 |
|
int nsv, npv; |
408 |
|
int xmin, xmax, ymin, ymax, x, y; |
409 |
< |
FLOAT cxy[2]; |
409 |
> |
RREAL cxy[2]; |
410 |
> |
COLOR rcol; |
411 |
|
double w; |
412 |
|
RAY sr; |
413 |
< |
register SPLIST *sp; |
414 |
< |
register int i; |
413 |
> |
SPLIST *sp; |
414 |
> |
int i; |
415 |
|
/* check each source in our list */ |
416 |
|
for (sp = sphead; sp != NULL; sp = sp->next) { |
417 |
|
/* clip source poly to subimage */ |
450 |
|
if (source[sp->sn].sflags & SSPOT && |
451 |
|
spotout(&sr, source[sp->sn].sl.s)) |
452 |
|
continue; /* outside spot */ |
453 |
< |
rayorigin(&sr, NULL, SHADOW, 1.0); |
453 |
> |
rayorigin(&sr, SHADOW, NULL, NULL); |
454 |
|
sr.rsrc = sp->sn; |
455 |
|
rayvalue(&sr); /* compute value */ |
456 |
< |
if (bright(sr.rcol) <= FTINY) |
456 |
> |
if (sintens(sr.rcol) <= FTINY) |
457 |
|
continue; /* missed/blocked */ |
458 |
+ |
scolor_rgb(rcol, sr.rcol); |
459 |
|
/* modify pixel */ |
473 |
– |
if (zbf[y-y0] != NULL && |
474 |
– |
sr.rt < 0.999*zbf[y-y0][x-x0]) |
475 |
– |
zbf[y-y0][x-x0] = sr.rt; |
476 |
– |
else if (!bigdiff(sr.rcol, pic[y-y0][x-x0], |
477 |
– |
0.001)) /* source sample */ |
478 |
– |
setcolor(pic[y-y0][x-x0], 0., 0., 0.); |
460 |
|
w = poly_area(ppoly, npv) * hres * vres; |
461 |
< |
scalecolor(sr.rcol, w); |
461 |
> |
if (zbf[y-y0] != NULL && |
462 |
> |
sr.rxt < 0.99*zbf[y-y0][x-x0]) { |
463 |
> |
zbf[y-y0][x-x0] = sr.rxt; |
464 |
> |
} else if (!bigdiff(rcol, pic[y-y0][x-x0], |
465 |
> |
0.01)) { /* source sample */ |
466 |
> |
scalecolor(pic[y-y0][x-x0], w); |
467 |
> |
continue; |
468 |
> |
} |
469 |
> |
scalecolor(rcol, w); |
470 |
|
scalecolor(pic[y-y0][x-x0], 1.-w); |
471 |
< |
addcolor(pic[y-y0][x-x0], sr.rcol); |
471 |
> |
addcolor(pic[y-y0][x-x0], rcol); |
472 |
|
} |
473 |
|
} |
474 |
|
} |