--- ray/src/cv/mgf2rad.c 1994/06/22 17:16:03 2.2 +++ ray/src/cv/mgf2rad.c 1994/07/19 15:54:44 2.8 @@ -19,7 +19,7 @@ static char SCCSid[] = "$SunId$ LBL"; double glowdist = FHUGE; /* glow test distance */ -double emult = 1.; /* emmitter multiplier */ +double emult = 1.; /* emitter multiplier */ int r_comment(), r_cone(), r_cyl(), r_face(), r_ies(), r_ring(), r_sph(); char *material(), *object(), *addarg(); @@ -34,6 +34,8 @@ char *argv[]; mg_ehand[MG_E_COMMENT] = r_comment; mg_ehand[MG_E_COLOR] = c_hcolor; mg_ehand[MG_E_CONE] = r_cone; + mg_ehand[MG_E_CMIX] = c_hcolor; + mg_ehand[MG_E_CSPEC] = c_hcolor; mg_ehand[MG_E_CXY] = c_hcolor; mg_ehand[MG_E_CYL] = r_cyl; mg_ehand[MG_E_ED] = c_hmaterial; @@ -46,6 +48,7 @@ char *argv[]; mg_ehand[MG_E_RD] = c_hmaterial; mg_ehand[MG_E_RING] = r_ring; mg_ehand[MG_E_RS] = c_hmaterial; + mg_ehand[MG_E_SIDES] = c_hmaterial; mg_ehand[MG_E_SPH] = r_sph; mg_ehand[MG_E_TD] = c_hmaterial; mg_ehand[MG_E_TS] = c_hmaterial; @@ -97,7 +100,7 @@ r_comment(ac, av) /* repeat a comment verbatim */ register int ac; register char **av; { - fputs("\n#", stdout); /* use Radiance comment character */ + putchar('#'); /* use Radiance comment character */ while (--ac) { putchar(' '); fputs(*++av, stdout); @@ -337,8 +340,11 @@ char **av; /* put out xform command */ printf("\n!xform"); oname = object(); - if (*oname) - printf(" -n %s", oname); + if (*oname) { + printf(" -n "); + for (op = oname; op[1]; op++) /* remove trailing separator */ + putchar(*op); + } for (i = xa0; i < ac; i++) printf(" %s", av[i]); if (ac > xa0 && xf_argc > 0) @@ -396,8 +402,8 @@ material() /* get (and print) current material */ double d; register int i; - if (c_cmaterial->name != NULL) - mname = c_cmaterial->name; + if (c_cmname != NULL) + mname = c_cmname; if (!c_cmaterial->clock) return(mname); /* already current */ /* else update output */ @@ -420,12 +426,19 @@ material() /* get (and print) current material */ } d = c_cmaterial->rd + c_cmaterial->td + c_cmaterial->rs + c_cmaterial->ts; - if (d <= 0. | d >= 1.) + if (d < 0. | d > 1.) return(NULL); - if (c_cmaterial->td > .01 || c_cmaterial->ts > .01) { /* trans */ + /* check for trans */ + if (c_cmaterial->td > .01 || c_cmaterial->ts > .01) { double ts, a5, a6; - ts = sqrt(c_cmaterial->ts); /* because we use 2 sides */ + if (c_cmaterial->sided) { + ts = sqrt(c_cmaterial->ts); /* approximate */ + a5 = .5; + } else { + ts = c_cmaterial->ts; + a5 = 1.; + } /* average colors */ d = c_cmaterial->rd + c_cmaterial->td + ts; cvtcolor(radrgb, &c_cmaterial->rd_c, c_cmaterial->rd/d); @@ -435,14 +448,15 @@ material() /* get (and print) current material */ addcolor(radrgb, c2); if (c_cmaterial->rs + ts > .0001) a5 = (c_cmaterial->rs*c_cmaterial->rs_a + - ts*.5*c_cmaterial->ts_a) / + ts*a5*c_cmaterial->ts_a) / (c_cmaterial->rs + ts); a6 = (c_cmaterial->td + ts) / (c_cmaterial->rd + c_cmaterial->td + ts); - if (a6 < .999) { + if (a6 < .999) d = c_cmaterial->rd/(1. - c_cmaterial->rs)/(1. - a6); - scalecolor(radrgb, d); - } + else + d = c_cmaterial->td + ts; + scalecolor(radrgb, d); printf("\nvoid trans %s\n0\n0\n", mname); printf("7 %f %f %f\n", colval(radrgb,RED), colval(radrgb,GRN), colval(radrgb,BLU)); @@ -450,11 +464,10 @@ material() /* get (and print) current material */ ts/(ts + c_cmaterial->td)); return(mname); } - if (c_cmaterial->rs < .01 || isgrey(&c_cmaterial->rs_c)) { /* plastic */ - if (c_cmaterial->rs > .999) - cvtcolor(radrgb, &c_cmaterial->rd_c, 1.); - else - cvtcolor(radrgb, &c_cmaterial->rd_c, + /* check for plastic */ + if (c_cmaterial->rs < .1 && (c_cmaterial->rs < .01 || + c_isgrey(&c_cmaterial->rs_c))) { + cvtcolor(radrgb, &c_cmaterial->rd_c, c_cmaterial->rd/(1.-c_cmaterial->rs)); printf("\nvoid plastic %s\n0\n0\n", mname); printf("5 %f %f %f %f %f\n", colval(radrgb,RED), @@ -463,18 +476,15 @@ material() /* get (and print) current material */ return(mname); } /* else it's metal */ - d = c_cmaterial->rd + c_cmaterial->rs; /* average colors */ - cvtcolor(radrgb, &c_cmaterial->rd_c, c_cmaterial->rd/d); - cvtcolor(c2, &c_cmaterial->rs_c, c_cmaterial->rs/d); + /* average colors */ + cvtcolor(radrgb, &c_cmaterial->rd_c, c_cmaterial->rd); + cvtcolor(c2, &c_cmaterial->rs_c, c_cmaterial->rs); addcolor(radrgb, c2); - if (c_cmaterial->rs < .999) { - d = c_cmaterial->rd/(1. - c_cmaterial->rs); - scalecolor(radrgb, d); - } printf("\nvoid metal %s\n0\n0\n", mname); printf("5 %f %f %f %f %f\n", colval(radrgb,RED), colval(radrgb,GRN), colval(radrgb,BLU), - c_cmaterial->rs, c_cmaterial->rs_a); + c_cmaterial->rs/(c_cmaterial->rd + c_cmaterial->rs), + c_cmaterial->rs_a); return(mname); } @@ -486,6 +496,7 @@ double intensity; { static COLOR ciexyz; + c_ccvt(ciec, C_CSXY); /* get xy representation */ ciexyz[1] = intensity; ciexyz[0] = ciec->cx/ciec->cy*ciexyz[1]; ciexyz[2] = ciexyz[1]*(1./ciec->cy - 1.) - ciexyz[0];