--- ray/src/cv/rad2mgf.c 1994/09/02 16:21:00 2.6 +++ ray/src/cv/rad2mgf.c 1995/04/13 14:43:30 2.10 @@ -9,15 +9,21 @@ static char SCCSid[] = "$SunId$ LBL"; */ #include +#include #include #include "fvect.h" #include "object.h" #include "color.h" #include "lookup.h" +#define PI 3.14159265358979323846 + +#define C_1SIDEDTHICK 0.005 + int o_face(), o_cone(), o_sphere(), o_ring(), o_cylinder(); int o_instance(), o_source(), o_illum(); -int o_plastic(), o_metal(), o_glass(), o_mirror(), o_trans(), o_light(); +int o_plastic(), o_metal(), o_glass(), o_dielectric(), + o_mirror(), o_trans(), o_light(); extern void free(); extern char *malloc(); @@ -37,14 +43,14 @@ double unit_mult = 1.; /* units multiplier */ * Stuff for tracking and reusing vertices: */ -char VKFMT[] = "%+1.9e %+1.9e %+1.9e"; +char VKFMT[] = "%+16.9e %+16.9e %+16.9e"; #define VKLEN 64 #define mkvkey(k,v) sprintf(k, VKFMT, (v)[0], (v)[1], (v)[2]) #define NVERTS 256 -long clock; /* incremented at each vertex request */ +long vclock; /* incremented at each vertex request */ struct vert { long lused; /* when last used (0 if unassigned) */ @@ -282,6 +288,7 @@ init() /* initialize dispatch table and output */ add2dispatch("metal", o_metal); add2dispatch("metal2", o_metal); add2dispatch("glass", o_glass); + add2dispatch("dielectric", o_dielectric); add2dispatch("trans", o_trans); add2dispatch("trans2", o_trans); add2dispatch("mirror", o_mirror); @@ -341,11 +348,11 @@ getvertid(vname, vp) /* get/set vertex ID for this po char *vname; FVECT vp; { - char vkey[VKLEN]; + static char vkey[VKLEN]; register LUENT *lp; register int i, vndx; - clock++; /* increment counter */ + vclock++; /* increment counter */ mkvkey(vkey, vp); if ((lp = lu_find(&vertab, vkey)) == NULL) goto memerr; @@ -371,7 +378,7 @@ FVECT vp; lp->data = (char *)&vert[vndx]; /* set it */ } else vndx = (struct vert *)lp->data - vert; - vert[vndx].lused = clock; /* record this use */ + vert[vndx].lused = vclock; /* record this use */ sprintf(vname, "v%d", vndx); return(vname); memerr: @@ -622,6 +629,7 @@ register FUNARGS *fa; newmat(id, NULL); if (fa->nfargs == 4) nrfr = fa->farg[3]; + printf("\tir %f 0\n", nrfr); F = (1. - nrfr)/(1. + nrfr); /* use normal incidence */ F *= F; for (i = 0; i < 3; i++) { @@ -647,6 +655,36 @@ register FUNARGS *fa; int +o_dielectric(mod, typ, id, fa) /* convert a dielectric material */ +char *mod, *typ, *id; +register FUNARGS *fa; +{ + COLOR cxyz, trgb; + double F, d; + register int i; + + if (fa->nfargs != 5) + return(-1); + newmat(id, NULL); + F = (1. - fa->farg[3])/(1. + fa->farg[3]); /* normal incidence */ + F *= F; + for (i = 0; i < 3; i++) + trgb[i] = (1. - F)*pow(fa->farg[i], C_1SIDEDTHICK/unit_mult); + printf("\tir %f 0\n", fa->farg[3]); /* put index of refraction */ + printf("\tsides 1\n"); + puts("\tc"); /* put reflected component */ + printf("\trs %.4f 0\n", F); + rgb_cie(cxyz, trgb); /* put transmitted component */ + puts("\tc"); + d = cxyz[0] + cxyz[1] + cxyz[2]; + if (d > FTINY) + printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); + printf("\tts %.4f 0\n", cxyz[1]); + return(0); +} + + +int o_mirror(mod, typ, id, fa) /* convert a mirror material */ char *mod, *typ, *id; register FUNARGS *fa; @@ -728,6 +766,6 @@ register FUNARGS *fa; puts("\tc"); if (d > FTINY) printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); - printf("\ted %.4g\n", cxyz[1]*WHTEFFICACY); + printf("\ted %.4g\n", cxyz[1]*(PI*WHTEFFICACY)); return(0); }