1 |
– |
/* Copyright (c) 1994 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Convert Radiance scene description to MGF |
6 |
|
*/ |
7 |
|
|
8 |
< |
#include <stdio.h> |
8 |
> |
#include "platform.h" |
9 |
> |
#include "standard.h" |
10 |
> |
#include <ctype.h> |
11 |
|
#include <string.h> |
12 |
< |
#include "fvect.h" |
12 |
> |
#include <stdio.h> |
13 |
> |
|
14 |
|
#include "object.h" |
15 |
|
#include "color.h" |
16 |
|
#include "lookup.h" |
17 |
|
|
18 |
+ |
#define C_1SIDEDTHICK 0.005 |
19 |
+ |
|
20 |
|
int o_face(), o_cone(), o_sphere(), o_ring(), o_cylinder(); |
21 |
< |
int o_instance(), o_source(), o_illum(); |
22 |
< |
int o_plastic(), o_metal(), o_glass(), o_mirror(), o_trans(), o_light(); |
21 |
> |
int o_instance(), o_illum(); |
22 |
> |
int o_plastic(), o_metal(), o_glass(), o_dielectric(), |
23 |
> |
o_mirror(), o_trans(), o_light(); |
24 |
|
|
22 |
– |
extern void free(); |
23 |
– |
extern char *malloc(); |
24 |
– |
|
25 |
|
LUTAB rmats = LU_SINIT(free,NULL); /* defined material table */ |
26 |
|
|
27 |
|
LUTAB rdispatch = LU_SINIT(NULL,NULL); /* function dispatch table */ |
28 |
|
|
29 |
< |
char curmat[80]; /* current material */ |
29 |
> |
char curmat[80]; /* current material */ |
30 |
> |
char curobj[128] = "Untitled"; /* current object name */ |
31 |
|
|
32 |
< |
double unit_mult = 1.; /* units multiplier */ |
32 |
> |
double unit_mult = 1.; /* units multiplier */ |
33 |
|
|
34 |
+ |
#define hasmult (unit_mult < .999 || unit_mult > 1.001) |
35 |
|
|
36 |
+ |
/* |
37 |
+ |
* Stuff for tracking and reusing vertices: |
38 |
+ |
*/ |
39 |
+ |
|
40 |
+ |
char VKFMT[] = "%+16.9e %+16.9e %+16.9e"; |
41 |
+ |
#define VKLEN 64 |
42 |
+ |
|
43 |
+ |
#define mkvkey(k,v) sprintf(k, VKFMT, (v)[0], (v)[1], (v)[2]) |
44 |
+ |
|
45 |
+ |
#define NVERTS 256 |
46 |
+ |
|
47 |
+ |
long vclock; /* incremented at each vertex request */ |
48 |
+ |
|
49 |
+ |
struct vert { |
50 |
+ |
long lused; /* when last used (0 if unassigned) */ |
51 |
+ |
FVECT p; /* track point position only */ |
52 |
+ |
} vert[NVERTS]; /* our vertex cache */ |
53 |
+ |
|
54 |
+ |
LUTAB vertab = LU_SINIT(free,NULL); /* our vertex lookup table */ |
55 |
+ |
|
56 |
+ |
|
57 |
|
main(argc, argv) |
58 |
|
int argc; |
59 |
|
char **argv; |
80 |
|
goto unkopt; |
81 |
|
} |
82 |
|
break; |
83 |
+ |
default: |
84 |
+ |
goto unkopt; |
85 |
|
} |
86 |
|
init(); |
87 |
|
if (i >= argc) |
110 |
|
register int c; |
111 |
|
|
112 |
|
if (inp == NULL) { |
113 |
< |
inp = "the standard input"; |
113 |
> |
inp = "standard input"; |
114 |
|
fp = stdin; |
115 |
|
} else if (inp[0] == '!') { |
116 |
|
if ((fp = popen(inp+1, "r")) == NULL) { |
188 |
|
fprintf(stderr, "%s: bad %s \"%s\"\n", typ, id); |
189 |
|
exit(1); |
190 |
|
} |
191 |
< |
} else if (lu_find(&rmats, mod)->data != NULL) /* make alias */ |
192 |
< |
newmat(id, mod); |
191 |
> |
} else { /* unsupported */ |
192 |
> |
o_unsupported(mod, typ, id, fa); |
193 |
> |
if (lu_find(&rmats, mod)->data != NULL) /* make alias */ |
194 |
> |
newmat(id, mod); |
195 |
> |
} |
196 |
|
} |
197 |
|
|
198 |
|
|
237 |
|
{ |
238 |
|
if (!strcmp(id, curmat)) /* already set? */ |
239 |
|
return; |
240 |
+ |
if (!strcmp(id, VOIDID)) /* cannot set */ |
241 |
+ |
return; |
242 |
|
printf("m %s\n", id); |
243 |
|
strcpy(curmat, id); |
244 |
|
} |
245 |
|
|
246 |
|
|
247 |
+ |
setobj(id) /* set object name to this one */ |
248 |
+ |
char *id; |
249 |
+ |
{ |
250 |
+ |
register char *cp, *cp2; |
251 |
+ |
char *end = NULL; |
252 |
+ |
int diff = 0; |
253 |
+ |
/* use all but final suffix */ |
254 |
+ |
for (cp = id; *cp; cp++) |
255 |
+ |
if (*cp == '.') |
256 |
+ |
end = cp; |
257 |
+ |
if (end == NULL) |
258 |
+ |
end = cp; |
259 |
+ |
/* copy to current object */ |
260 |
+ |
cp2 = curobj; |
261 |
+ |
if (!isalpha(*id)) { /* start with letter */ |
262 |
+ |
diff = *cp2 != 'O'; |
263 |
+ |
*cp2++ = 'O'; |
264 |
+ |
} |
265 |
+ |
for (cp = id; cp < end; *cp2++ = *cp++) { |
266 |
+ |
if ((*cp < '!') | (*cp > '~')) /* limit to visible chars */ |
267 |
+ |
*cp = '?'; |
268 |
+ |
diff += *cp != *cp2; |
269 |
+ |
} |
270 |
+ |
if (!diff && !*cp2) |
271 |
+ |
return; |
272 |
+ |
*cp2 = '\0'; |
273 |
+ |
fputs("o\no ", stdout); |
274 |
+ |
puts(curobj); |
275 |
+ |
} |
276 |
+ |
|
277 |
+ |
|
278 |
|
init() /* initialize dispatch table and output */ |
279 |
|
{ |
280 |
+ |
lu_init(&vertab, NVERTS); |
281 |
|
lu_init(&rdispatch, 22); |
282 |
|
add2dispatch("polygon", o_face); |
283 |
|
add2dispatch("cone", o_cone); |
288 |
|
add2dispatch("tube", o_cylinder); |
289 |
|
add2dispatch("ring", o_ring); |
290 |
|
add2dispatch("instance", o_instance); |
291 |
+ |
add2dispatch("mesh", o_instance); |
292 |
|
add2dispatch("plastic", o_plastic); |
293 |
|
add2dispatch("plastic2", o_plastic); |
294 |
|
add2dispatch("metal", o_metal); |
295 |
|
add2dispatch("metal2", o_metal); |
296 |
|
add2dispatch("glass", o_glass); |
297 |
+ |
add2dispatch("dielectric", o_dielectric); |
298 |
|
add2dispatch("trans", o_trans); |
299 |
|
add2dispatch("trans2", o_trans); |
300 |
|
add2dispatch("mirror", o_mirror); |
302 |
|
add2dispatch("spotlight", o_light); |
303 |
|
add2dispatch("glow", o_light); |
304 |
|
add2dispatch("illum", o_illum); |
305 |
< |
puts("# The following was converted from Radiance scene input"); |
306 |
< |
if (unit_mult < .999 || unit_mult > 1.001) |
305 |
> |
puts("# The following was converted from RADIANCE scene input"); |
306 |
> |
if (hasmult) |
307 |
|
printf("xf -s %.4e\n", unit_mult); |
308 |
+ |
printf("o %s\n", curobj); |
309 |
|
} |
310 |
|
|
311 |
|
|
312 |
|
uninit() /* mark end of MGF file */ |
313 |
|
{ |
314 |
< |
if (unit_mult < .999 || unit_mult > 1.001) |
314 |
> |
puts("o"); |
315 |
> |
if (hasmult) |
316 |
|
puts("xf"); |
317 |
< |
puts("# End of data converted from Radiance scene input"); |
317 |
> |
puts("# End of data converted from RADIANCE scene input"); |
318 |
|
lu_done(&rdispatch); |
319 |
|
lu_done(&rmats); |
320 |
+ |
lu_done(&vertab); |
321 |
|
} |
322 |
|
|
323 |
|
|
324 |
+ |
clrverts() /* clear vertex table */ |
325 |
+ |
{ |
326 |
+ |
register int i; |
327 |
+ |
|
328 |
+ |
lu_done(&vertab); |
329 |
+ |
for (i = 0; i < NVERTS; i++) |
330 |
+ |
vert[i].lused = 0; |
331 |
+ |
lu_init(&vertab, NVERTS); |
332 |
+ |
} |
333 |
+ |
|
334 |
+ |
|
335 |
|
add2dispatch(name, func) /* add function to dispatch table */ |
336 |
|
char *name; |
337 |
|
int (*func)(); |
349 |
|
} |
350 |
|
|
351 |
|
|
274 |
– |
char VKFMT[] = "%+1.9e %+1.9e %+1.9e"; |
275 |
– |
#define VKLEN 64 |
276 |
– |
|
277 |
– |
#define mkvkey(k,v) sprintf(k, VKFMT, (v)[0], (v)[1], (v)[2]) |
278 |
– |
|
279 |
– |
#define NVERTS 256 |
280 |
– |
|
281 |
– |
long clock; /* incremented at each vertex request */ |
282 |
– |
|
283 |
– |
struct vert { |
284 |
– |
long lused; /* when last used (0 if unassigned) */ |
285 |
– |
FVECT p; /* track point position only */ |
286 |
– |
} vert[NVERTS]; |
287 |
– |
|
288 |
– |
LUTAB vertab = LU_SINIT(free,NULL); /* our vertex lookup table */ |
289 |
– |
|
290 |
– |
|
352 |
|
char * |
353 |
< |
getvertid(vp) /* get/set vertex ID for this point */ |
353 |
> |
getvertid(vname, vp) /* get/set vertex ID for this point */ |
354 |
> |
char *vname; |
355 |
|
FVECT vp; |
356 |
|
{ |
357 |
< |
static char vname[6]; |
296 |
< |
char vkey[VKLEN]; |
357 |
> |
static char vkey[VKLEN]; |
358 |
|
register LUENT *lp; |
359 |
|
register int i, vndx; |
360 |
|
|
361 |
< |
if (!vertab.tsiz && !lu_init(&vertab, NVERTS)) |
301 |
< |
goto memerr; |
302 |
< |
clock++; /* increment counter */ |
361 |
> |
vclock++; /* increment counter */ |
362 |
|
mkvkey(vkey, vp); |
363 |
|
if ((lp = lu_find(&vertab, vkey)) == NULL) |
364 |
|
goto memerr; |
378 |
|
mkvkey(vkey, vert[vndx].p); |
379 |
|
lu_delete(&vertab, vkey); |
380 |
|
} |
381 |
< |
vert[vndx].lused = clock; /* assign it */ |
382 |
< |
VCOPY(vert[vndx].p, vp); |
324 |
< |
printf("v v%d =\np %.15g %.15g %.15g\n", /* print it */ |
381 |
> |
VCOPY(vert[vndx].p, vp); /* assign it */ |
382 |
> |
printf("v v%d =\n\tp %.15g %.15g %.15g\n", /* print it */ |
383 |
|
vndx, vp[0], vp[1], vp[2]); |
384 |
|
lp->data = (char *)&vert[vndx]; /* set it */ |
385 |
|
} else |
386 |
|
vndx = (struct vert *)lp->data - vert; |
387 |
+ |
vert[vndx].lused = vclock; /* record this use */ |
388 |
|
sprintf(vname, "v%d", vndx); |
389 |
|
return(vname); |
390 |
|
memerr: |
394 |
|
|
395 |
|
|
396 |
|
int |
397 |
+ |
o_unsupported(mod, typ, id, fa) /* mark unsupported primitive */ |
398 |
+ |
char *mod, *typ, *id; |
399 |
+ |
FUNARGS *fa; |
400 |
+ |
{ |
401 |
+ |
register int i; |
402 |
+ |
|
403 |
+ |
fputs("\n# Unsupported RADIANCE primitive:\n", stdout); |
404 |
+ |
printf("# %s %s %s", mod, typ, id); |
405 |
+ |
printf("\n# %d", fa->nsargs); |
406 |
+ |
for (i = 0; i < fa->nsargs; i++) |
407 |
+ |
printf(" %s", fa->sarg[i]); |
408 |
+ |
#ifdef IARGS |
409 |
+ |
printf("\n# %d", fa->niargs); |
410 |
+ |
for (i = 0; i < fa->niargs; i++) |
411 |
+ |
printf(" %ld", fa->iarg[i]); |
412 |
+ |
#else |
413 |
+ |
fputs("\n# 0", stdout); |
414 |
+ |
#endif |
415 |
+ |
printf("\n# %d", fa->nfargs); |
416 |
+ |
for (i = 0; i < fa->nfargs; i++) |
417 |
+ |
printf(" %g", fa->farg[i]); |
418 |
+ |
fputs("\n\n", stdout); |
419 |
+ |
return(0); |
420 |
+ |
} |
421 |
+ |
|
422 |
+ |
|
423 |
+ |
int |
424 |
|
o_face(mod, typ, id, fa) /* print out a polygon */ |
425 |
|
char *mod, *typ, *id; |
426 |
|
FUNARGS *fa; |
427 |
|
{ |
428 |
< |
char entbuf[512]; |
429 |
< |
register char *cp1, *cp2; |
428 |
> |
char entbuf[2048], *linestart; |
429 |
> |
register char *cp; |
430 |
|
register int i; |
431 |
|
|
432 |
< |
if (fa->nfargs < 9 | fa->nfargs % 3) |
432 |
> |
if ((fa->nfargs < 9) | (fa->nfargs % 3)) |
433 |
|
return(-1); |
434 |
|
setmat(mod); |
435 |
< |
printf("o %s\n", id); |
436 |
< |
cp1 = entbuf; |
437 |
< |
*cp1++ = 'f'; |
435 |
> |
setobj(id); |
436 |
> |
cp = linestart = entbuf; |
437 |
> |
*cp++ = 'f'; |
438 |
|
for (i = 0; i < fa->nfargs; i += 3) { |
439 |
< |
cp2 = getvertid(fa->farg + i); |
440 |
< |
*cp1++ = ' '; |
441 |
< |
while ((*cp1 = *cp2++)) |
442 |
< |
cp1++; |
439 |
> |
*cp++ = ' '; |
440 |
> |
if (cp - linestart > 72) { |
441 |
> |
*cp++ = '\\'; *cp++ = '\n'; |
442 |
> |
linestart = cp; |
443 |
> |
*cp++ = ' '; *cp++ = ' '; |
444 |
> |
} |
445 |
> |
getvertid(cp, fa->farg + i); |
446 |
> |
while (*cp) |
447 |
> |
cp++; |
448 |
|
} |
449 |
|
puts(entbuf); |
359 |
– |
puts("o"); |
450 |
|
return(0); |
451 |
|
} |
452 |
|
|
456 |
|
char *mod, *typ, *id; |
457 |
|
register FUNARGS *fa; |
458 |
|
{ |
459 |
+ |
char v1[6], v2[6]; |
460 |
+ |
|
461 |
|
if (fa->nfargs != 8) |
462 |
|
return(-1); |
463 |
|
setmat(mod); |
464 |
< |
printf("o %s\n", id); |
465 |
< |
printf("v cv1 =\np %.12g %.12g %.12g\n", |
466 |
< |
fa->farg[0], fa->farg[1], fa->farg[2]); |
375 |
< |
printf("v cv2 =\np %.12g %.12g %.12g\n", |
376 |
< |
fa->farg[3], fa->farg[4], fa->farg[5]); |
464 |
> |
setobj(id); |
465 |
> |
getvertid(v1, fa->farg); |
466 |
> |
getvertid(v2, fa->farg + 3); |
467 |
|
if (typ[1] == 'u') /* cup -> inverted cone */ |
468 |
< |
printf("cone cv1 %.12g cv2 %.12g\n", |
469 |
< |
-fa->farg[6], -fa->farg[7]); |
468 |
> |
printf("cone %s %.12g %s %.12g\n", |
469 |
> |
v1, -fa->farg[6], v2, -fa->farg[7]); |
470 |
|
else |
471 |
< |
printf("cone cv1 %.12g cv2 %.12g\n", |
472 |
< |
fa->farg[6], fa->farg[7]); |
383 |
< |
puts("o"); |
471 |
> |
printf("cone %s %.12g %s %.12g\n", |
472 |
> |
v1, fa->farg[6], v2, fa->farg[7]); |
473 |
|
return(0); |
474 |
|
} |
475 |
|
|
479 |
|
char *mod, *typ, *id; |
480 |
|
register FUNARGS *fa; |
481 |
|
{ |
482 |
+ |
char cent[6]; |
483 |
+ |
|
484 |
|
if (fa->nfargs != 4) |
485 |
|
return(-1); |
486 |
|
setmat(mod); |
487 |
< |
printf("o %s\n", id); |
488 |
< |
printf("v cent =\np %.12g %.12g %.12g\n", |
489 |
< |
fa->farg[0], fa->farg[1], fa->farg[2]); |
399 |
< |
printf("sph cent %.12g\n", typ[0]=='b' ? -fa->farg[3] : fa->farg[3]); |
400 |
< |
puts("o"); |
487 |
> |
setobj(id); |
488 |
> |
printf("sph %s %.12g\n", getvertid(cent, fa->farg), |
489 |
> |
typ[0]=='b' ? -fa->farg[3] : fa->farg[3]); |
490 |
|
return(0); |
491 |
|
} |
492 |
|
|
496 |
|
char *mod, *typ, *id; |
497 |
|
register FUNARGS *fa; |
498 |
|
{ |
499 |
+ |
char v1[6], v2[6]; |
500 |
+ |
|
501 |
|
if (fa->nfargs != 7) |
502 |
|
return(-1); |
503 |
|
setmat(mod); |
504 |
< |
printf("o %s\n", id); |
505 |
< |
printf("v cv1 =\np %.12g %.12g %.12g\n", |
506 |
< |
fa->farg[0], fa->farg[1], fa->farg[2]); |
507 |
< |
printf("v cv2 =\np %.12g %.12g %.12g\n", |
508 |
< |
fa->farg[3], fa->farg[4], fa->farg[5]); |
418 |
< |
printf("cyl cv1 %.12g cv2\n", |
419 |
< |
typ[0]=='t' ? -fa->farg[6] : fa->farg[6]); |
420 |
< |
puts("o"); |
504 |
> |
setobj(id); |
505 |
> |
getvertid(v1, fa->farg); |
506 |
> |
getvertid(v2, fa->farg + 3); |
507 |
> |
printf("cyl %s %.12g %s\n", v1, |
508 |
> |
typ[0]=='t' ? -fa->farg[6] : fa->farg[6], v2); |
509 |
|
return(0); |
510 |
|
} |
511 |
|
|
518 |
|
if (fa->nfargs != 8) |
519 |
|
return(-1); |
520 |
|
setmat(mod); |
521 |
< |
printf("o %s\n", id); |
522 |
< |
printf("v cent =\np %.12g %.12g %.12g\n", |
521 |
> |
setobj(id); |
522 |
> |
printf("v cent =\n\tp %.12g %.12g %.12g\n", |
523 |
|
fa->farg[0], fa->farg[1], fa->farg[2]); |
524 |
< |
printf("n %.12g %.12g %.12g\n", |
524 |
> |
printf("\tn %.12g %.12g %.12g\n", |
525 |
|
fa->farg[3], fa->farg[4], fa->farg[5]); |
526 |
|
if (fa->farg[6] < fa->farg[7]) |
527 |
|
printf("ring cent %.12g %.12g\n", |
529 |
|
else |
530 |
|
printf("ring cent %.12g %.12g\n", |
531 |
|
fa->farg[7], fa->farg[6]); |
444 |
– |
puts("o"); |
532 |
|
return(0); |
533 |
|
} |
534 |
|
|
535 |
|
|
536 |
|
int |
537 |
< |
o_instance(mod, typ, id, fa) /* convert an instance */ |
537 |
> |
o_instance(mod, typ, id, fa) /* convert an instance (or mesh) */ |
538 |
|
char *mod, *typ, *id; |
539 |
|
FUNARGS *fa; |
540 |
|
{ |
541 |
< |
return(0); /* this is too damned difficult! */ |
541 |
> |
register int i; |
542 |
> |
register char *cp; |
543 |
> |
char *start = NULL, *end = NULL; |
544 |
> |
/* |
545 |
> |
* We don't really know how to do this, so we just create |
546 |
> |
* a reference to an undefined MGF file and it's the user's |
547 |
> |
* responsibility to create this file and put the appropriate |
548 |
> |
* stuff into it. |
549 |
> |
*/ |
550 |
> |
if (fa->nsargs < 1) |
551 |
> |
return(-1); |
552 |
> |
setmat(mod); /* only works if surfaces are void */ |
553 |
> |
setobj(id); |
554 |
> |
for (cp = fa->sarg[0]; *cp; cp++) /* construct MGF file name */ |
555 |
> |
if (*cp == '/') |
556 |
> |
start = cp+1; |
557 |
> |
else if (*cp == '.') |
558 |
> |
end = cp; |
559 |
> |
if (start == NULL) |
560 |
> |
start = fa->sarg[0]; |
561 |
> |
if (end == NULL || start >= end) |
562 |
> |
end = cp; |
563 |
> |
fputs("i ", stdout); /* print include entity */ |
564 |
> |
for (cp = start; cp < end; cp++) |
565 |
> |
putchar(*cp); |
566 |
> |
fputs(".mgf", stdout); /* add MGF suffix */ |
567 |
> |
for (i = 1; i < fa->nsargs; i++) { /* add transform */ |
568 |
> |
putchar(' '); |
569 |
> |
fputs(fa->sarg[i], stdout); |
570 |
> |
} |
571 |
> |
putchar('\n'); |
572 |
> |
clrverts(); /* vertex id's no longer reliable */ |
573 |
> |
return(0); |
574 |
|
} |
575 |
|
|
576 |
|
|
577 |
|
int |
459 |
– |
o_source(mod, typ, id, fa) /* convert a source */ |
460 |
– |
char *mod, *typ, *id; |
461 |
– |
FUNARGS *fa; |
462 |
– |
{ |
463 |
– |
return(0); /* there is no MGF equivalent! */ |
464 |
– |
} |
465 |
– |
|
466 |
– |
|
467 |
– |
int |
578 |
|
o_illum(mod, typ, id, fa) /* convert an illum material */ |
579 |
|
char *mod, *typ, *id; |
580 |
|
FUNARGS *fa; |
585 |
|
} |
586 |
|
/* else create invisible material */ |
587 |
|
newmat(id, NULL); |
588 |
< |
puts("ts 1 0"); |
588 |
> |
puts("\tts 1 0"); |
589 |
|
return(0); |
590 |
|
} |
591 |
|
|
603 |
|
newmat(id, NULL); |
604 |
|
rrgb[0] = fa->farg[0]; rrgb[1] = fa->farg[1]; rrgb[2] = fa->farg[2]; |
605 |
|
rgb_cie(cxyz, rrgb); |
606 |
< |
puts("c"); /* put diffuse component */ |
606 |
> |
puts("\tc"); /* put diffuse component */ |
607 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |
608 |
|
if (d > FTINY) |
609 |
< |
printf("cxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
610 |
< |
printf("rd %.4f\n", cxyz[1]*(1. - fa->farg[3])); |
611 |
< |
puts("c"); /* put specular component */ |
612 |
< |
printf("rs %.4f %.4f\n", fa->farg[3], |
613 |
< |
typ[7]=='2' ? .5*(fa->farg[4] + fa->farg[5]) : |
614 |
< |
fa->farg[4]); |
609 |
> |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
610 |
> |
printf("\trd %.4f\n", cxyz[1]*(1. - fa->farg[3])); |
611 |
> |
if (fa->farg[3] > FTINY) { /* put specular component */ |
612 |
> |
puts("\tc"); |
613 |
> |
printf("\trs %.4f %.4f\n", fa->farg[3], |
614 |
> |
typ[7]=='2' ? .5*(fa->farg[4] + fa->farg[5]) : |
615 |
> |
fa->farg[4]); |
616 |
> |
} |
617 |
|
return(0); |
618 |
|
} |
619 |
|
|
631 |
|
newmat(id, NULL); |
632 |
|
rrgb[0] = fa->farg[0]; rrgb[1] = fa->farg[1]; rrgb[2] = fa->farg[2]; |
633 |
|
rgb_cie(cxyz, rrgb); |
634 |
< |
puts("c"); /* put diffuse component */ |
634 |
> |
puts("\tc"); /* put diffuse component */ |
635 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |
636 |
|
if (d > FTINY) |
637 |
< |
printf("cxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
638 |
< |
printf("rd %.4f\n", cxyz[1]*(1. - fa->farg[3])); |
637 |
> |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
638 |
> |
printf("\trd %.4f\n", cxyz[1]*(1. - fa->farg[3])); |
639 |
|
/* put specular component */ |
640 |
< |
printf("rs %.4f %.4f\n", cxyz[1]*fa->farg[3], |
640 |
> |
printf("\trs %.4f %.4f\n", cxyz[1]*fa->farg[3], |
641 |
|
typ[5]=='2' ? .5*(fa->farg[4] + fa->farg[5]) : |
642 |
|
fa->farg[4]); |
643 |
|
return(0); |
658 |
|
newmat(id, NULL); |
659 |
|
if (fa->nfargs == 4) |
660 |
|
nrfr = fa->farg[3]; |
661 |
+ |
printf("\tir %f 0\n", nrfr); |
662 |
|
F = (1. - nrfr)/(1. + nrfr); /* use normal incidence */ |
663 |
|
F *= F; |
664 |
|
for (i = 0; i < 3; i++) { |
665 |
< |
rrgb[i] = (1. - F)*(1. - F)/(1. - F*F*fa->farg[i]*fa->farg[i]); |
553 |
< |
trgb[i] = F * (1. + (1. - 2.*F)*fa->farg[i]) / |
665 |
> |
trgb[i] = fa->farg[i] * (1. - F)*(1. - F) / |
666 |
|
(1. - F*F*fa->farg[i]*fa->farg[i]); |
667 |
+ |
rrgb[i] = F * (1. + (1. - 2.*F)*fa->farg[i]) / |
668 |
+ |
(1. - F*F*fa->farg[i]*fa->farg[i]); |
669 |
|
} |
670 |
|
rgb_cie(cxyz, rrgb); /* put reflected component */ |
671 |
< |
puts("c"); |
671 |
> |
puts("\tc"); |
672 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |
673 |
|
if (d > FTINY) |
674 |
< |
printf("cxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
675 |
< |
printf("rs %.4f 0\n", cxyz[1]); |
674 |
> |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
675 |
> |
printf("\trs %.4f 0\n", cxyz[1]); |
676 |
|
rgb_cie(cxyz, trgb); /* put transmitted component */ |
677 |
< |
puts("c"); |
677 |
> |
puts("\tc"); |
678 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |
679 |
|
if (d > FTINY) |
680 |
< |
printf("cxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
681 |
< |
printf("ts %.4f 0\n", cxyz[1]); |
680 |
> |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
681 |
> |
printf("\tts %.4f 0\n", cxyz[1]); |
682 |
|
return(0); |
683 |
|
} |
684 |
|
|
685 |
|
|
686 |
|
int |
687 |
+ |
o_dielectric(mod, typ, id, fa) /* convert a dielectric material */ |
688 |
+ |
char *mod, *typ, *id; |
689 |
+ |
register FUNARGS *fa; |
690 |
+ |
{ |
691 |
+ |
COLOR cxyz, trgb; |
692 |
+ |
double F, d; |
693 |
+ |
register int i; |
694 |
+ |
|
695 |
+ |
if (fa->nfargs != 5) |
696 |
+ |
return(-1); |
697 |
+ |
newmat(id, NULL); |
698 |
+ |
F = (1. - fa->farg[3])/(1. + fa->farg[3]); /* normal incidence */ |
699 |
+ |
F *= F; |
700 |
+ |
for (i = 0; i < 3; i++) |
701 |
+ |
trgb[i] = (1. - F)*pow(fa->farg[i], C_1SIDEDTHICK/unit_mult); |
702 |
+ |
printf("\tir %f 0\n", fa->farg[3]); /* put index of refraction */ |
703 |
+ |
printf("\tsides 1\n"); |
704 |
+ |
puts("\tc"); /* put reflected component */ |
705 |
+ |
printf("\trs %.4f 0\n", F); |
706 |
+ |
rgb_cie(cxyz, trgb); /* put transmitted component */ |
707 |
+ |
puts("\tc"); |
708 |
+ |
d = cxyz[0] + cxyz[1] + cxyz[2]; |
709 |
+ |
if (d > FTINY) |
710 |
+ |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
711 |
+ |
printf("\tts %.4f 0\n", cxyz[1]); |
712 |
+ |
return(0); |
713 |
+ |
} |
714 |
+ |
|
715 |
+ |
|
716 |
+ |
int |
717 |
|
o_mirror(mod, typ, id, fa) /* convert a mirror material */ |
718 |
|
char *mod, *typ, *id; |
719 |
|
register FUNARGS *fa; |
730 |
|
newmat(id, NULL); |
731 |
|
rrgb[0] = fa->farg[0]; rrgb[1] = fa->farg[1]; rrgb[2] = fa->farg[2]; |
732 |
|
rgb_cie(cxyz, rrgb); |
733 |
< |
puts("c"); /* put specular component */ |
733 |
> |
puts("\tc"); /* put specular component */ |
734 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |
735 |
|
if (d > FTINY) |
736 |
< |
printf("cxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
737 |
< |
printf("rs %.4f 0\n", cxyz[1]); |
736 |
> |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
737 |
> |
printf("\trs %.4f 0\n", cxyz[1]); |
738 |
|
return(0); |
739 |
|
} |
740 |
|
|
763 |
|
newmat(id, NULL); |
764 |
|
rrgb[0] = fa->farg[0]; rrgb[1] = fa->farg[1]; rrgb[2] = fa->farg[2]; |
765 |
|
rgb_cie(cxyz, rrgb); |
766 |
< |
puts("c"); /* put transmitted diffuse */ |
766 |
> |
puts("\tc"); /* put transmitted diffuse */ |
767 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |
768 |
|
if (d > FTINY) |
769 |
< |
printf("cxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
770 |
< |
printf("td %.4f\n", cxyz[1]*trans*(1. - fa->farg[3])*(1. - tspec)); |
769 |
> |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
770 |
> |
printf("\ttd %.4f\n", cxyz[1]*trans*(1. - fa->farg[3])*(1. - tspec)); |
771 |
|
/* put transmitted specular */ |
772 |
< |
printf("ts %.4f %.4f\n", cxyz[1]*trans*tspec*(1. - fa->farg[3]), rough); |
772 |
> |
printf("\tts %.4f %.4f\n", cxyz[1]*trans*tspec*(1. - fa->farg[3]), rough); |
773 |
|
/* put reflected diffuse */ |
774 |
< |
printf("rd %.4f\n", cxyz[1]*(1. - fa->farg[3])*(1. - trans)); |
775 |
< |
puts("c"); /* put reflected specular */ |
776 |
< |
printf("rs %.4f %.4f\n", fa->farg[3], rough); |
774 |
> |
printf("\trd %.4f\n", cxyz[1]*(1. - fa->farg[3])*(1. - trans)); |
775 |
> |
puts("\tc"); /* put reflected specular */ |
776 |
> |
printf("\trs %.4f %.4f\n", fa->farg[3], rough); |
777 |
|
return(0); |
778 |
|
} |
779 |
|
|
792 |
|
rrgb[0] = fa->farg[0]; rrgb[1] = fa->farg[1]; rrgb[2] = fa->farg[2]; |
793 |
|
rgb_cie(cxyz, rrgb); |
794 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |
795 |
< |
puts("c"); |
795 |
> |
puts("\tc"); |
796 |
|
if (d > FTINY) |
797 |
< |
printf("cxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
798 |
< |
printf("ed %.4g\n", cxyz[1]); |
797 |
> |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
798 |
> |
printf("\ted %.4g\n", cxyz[1]*(PI*WHTEFFICACY)); |
799 |
|
return(0); |
800 |
|
} |