ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/mgf2rad.c
(Generate patch)

Comparing ray/src/cv/mgf2rad.c (file contents):
Revision 2.1 by greg, Wed Jun 22 15:33:03 1994 UTC vs.
Revision 2.17 by greg, Mon May 1 17:05:22 1995 UTC

# Line 17 | Line 17 | static char SCCSid[] = "$SunId$ LBL";
17  
18   #define putv(v)         printf("%18.12g %18.12g %18.12g\n",(v)[0],(v)[1],(v)[2])
19  
20 < #define isgrey(cxy)     ((cxy)->cx > .31 && (cxy)->cx < .35 && \
21 <                        (cxy)->cy > .31 && (cxy)->cy < .35)
20 > #define invert          (xf_context != NULL && xf_context->rev)
21  
22 < #define is0vect(v)      ((v)[0] == 0. && (v)[1] == 0. && (v)[2] == 0.)
22 > double  glowdist = FHUGE;               /* glow test distance */
23  
24 < #define BIGFLT          1e8
24 > double  emult = 1.;                     /* emitter multiplier */
25  
26 < double  glowdist = 1.5*BIGFLT;          /* glow test distance */
26 > FILE    *matfp = stdout;                /* material output file */
27  
29 double  emult = 1.;                     /* emmitter multiplier */
30
28   int     r_comment(), r_cone(), r_cyl(), r_face(), r_ies(), r_ring(), r_sph();
29   char    *material(), *object(), *addarg();
30  
# Line 38 | Line 35 | char   *argv[];
35   {
36          int     i, rv;
37                                  /* initialize dispatch table */
38 <        mg_ehand[MG_E_COMMENT] = r_comment;
39 <        mg_ehand[MG_E_COLOR] = c_hcolor;
40 <        mg_ehand[MG_E_CONE] = r_cone;
41 <        mg_ehand[MG_E_CXY] = c_hcolor;
42 <        mg_ehand[MG_E_CYL] = r_cyl;
43 <        mg_ehand[MG_E_ED] = c_hmaterial;
44 <        mg_ehand[MG_E_FACE] = r_face;
45 <        mg_ehand[MG_E_IES] = r_ies;
46 <        mg_ehand[MG_E_MATERIAL] = c_hmaterial;
47 <        mg_ehand[MG_E_NORMAL] = c_hvertex;
48 <        mg_ehand[MG_E_OBJECT] = obj_handler;
49 <        mg_ehand[MG_E_POINT] = c_hvertex;
50 <        mg_ehand[MG_E_RD] = c_hmaterial;
51 <        mg_ehand[MG_E_RING] = r_ring;
52 <        mg_ehand[MG_E_RS] = c_hmaterial;
53 <        mg_ehand[MG_E_SPH] = r_sph;
54 <        mg_ehand[MG_E_TD] = c_hmaterial;
55 <        mg_ehand[MG_E_TS] = c_hmaterial;
56 <        mg_ehand[MG_E_VERTEX] = c_hvertex;
57 <        mg_ehand[MG_E_XF] = xf_handler;
38 >        mg_ehand[MG_E_COMMENT] = r_comment;     /* we pass comments */
39 >        mg_ehand[MG_E_COLOR] = c_hcolor;        /* they get color */
40 >        mg_ehand[MG_E_CONE] = r_cone;           /* we do cones */
41 >        mg_ehand[MG_E_CMIX] = c_hcolor;         /* they mix colors */
42 >        mg_ehand[MG_E_CSPEC] = c_hcolor;        /* they get spectra */
43 >        mg_ehand[MG_E_CXY] = c_hcolor;          /* they get chromaticities */
44 >        mg_ehand[MG_E_CCT] = c_hcolor;          /* they get color temp's */
45 >        mg_ehand[MG_E_CYL] = r_cyl;             /* we do cylinders */
46 >        mg_ehand[MG_E_ED] = c_hmaterial;        /* they get emission */
47 >        mg_ehand[MG_E_FACE] = r_face;           /* we do faces */
48 >        mg_ehand[MG_E_IES] = r_ies;             /* we do IES files */
49 >        mg_ehand[MG_E_IR] = c_hmaterial;        /* they get refractive index */
50 >        mg_ehand[MG_E_MATERIAL] = c_hmaterial;  /* they get materials */
51 >        mg_ehand[MG_E_NORMAL] = c_hvertex;      /* they get normals */
52 >        mg_ehand[MG_E_OBJECT] = obj_handler;    /* they track object names */
53 >        mg_ehand[MG_E_POINT] = c_hvertex;       /* they get points */
54 >        mg_ehand[MG_E_RD] = c_hmaterial;        /* they get diffuse refl. */
55 >        mg_ehand[MG_E_RING] = r_ring;           /* we do rings */
56 >        mg_ehand[MG_E_RS] = c_hmaterial;        /* they get specular refl. */
57 >        mg_ehand[MG_E_SIDES] = c_hmaterial;     /* they get # sides */
58 >        mg_ehand[MG_E_SPH] = r_sph;             /* we do spheres */
59 >        mg_ehand[MG_E_TD] = c_hmaterial;        /* they get diffuse trans. */
60 >        mg_ehand[MG_E_TS] = c_hmaterial;        /* they get specular trans. */
61 >        mg_ehand[MG_E_VERTEX] = c_hvertex;      /* they get vertices */
62 >        mg_ehand[MG_E_XF] = xf_handler;         /* they track transforms */
63          mg_init();              /* initialize the parser */
64 <                                        /* get options & print header */
64 >                                        /* get our options & print header */
65          printf("## %s", argv[0]);
66          for (i = 1; i < argc && argv[i][0] == '-'; i++) {
67                  printf(" %s", argv[i]);
68                  switch (argv[i][1]) {
69                  case 'g':                       /* glow distance (meters) */
70 <                        if (argv[i][2] || badarg(argc-i, argv+i, "f"))
70 >                        if (argv[i][2] || badarg(argc-i-1, argv+i+1, "f"))
71                                  goto userr;
72                          glowdist = atof(argv[++i]);
73                          printf(" %s", argv[i]);
74                          break;
75                  case 'e':                       /* emitter multiplier */
76 <                        if (argv[i][2] || badarg(argc-i, argv+i, "f"))
76 >                        if (argv[i][2] || badarg(argc-i-1, argv+i+1, "f"))
77                                  goto userr;
78                          emult = atof(argv[++i]);
79                          printf(" %s", argv[i]);
80                          break;
81 +                case 'm':                       /* materials file */
82 +                        matfp = fopen(argv[++i], "a");
83 +                        if (matfp == NULL) {
84 +                                fprintf(stderr, "%s: cannot append\n", argv[i]);
85 +                                exit(1);
86 +                        }
87 +                        printf(" %s", argv[i]);
88 +                        break;
89                  default:
90                          goto userr;
91                  }
# Line 93 | Line 103 | char   *argv[];
103                  }
104          exit(0);
105   userr:
106 <        fprintf(stderr, "Usage: %s [-g dist][-m mult] [file.mgf] ..\n",
106 >        fprintf(stderr, "Usage: %s [-g dist][-e mult][-m matf] [file.mgf] ..\n",
107                          argv[0]);
108          exit(1);
109   }
# Line 104 | Line 114 | r_comment(ac, av)              /* repeat a comment verbatim */
114   register int    ac;
115   register char   **av;
116   {
117 <        fputs("\n#", stdout);   /* use Radiance comment character */
118 <        while (--ac) {
117 >        putchar('#');           /* use Radiance comment character */
118 >        while (--ac) {                  /* pass through verbatim */
119                  putchar(' ');
120                  fputs(*++av, stdout);
121          }
# Line 125 | Line 135 | char   **av;
135          C_VERTEX        *cv1, *cv2;
136          FVECT   p1, p2;
137          int     inv;
138 <
138 >                                        /* check argument count and type */
139          if (ac != 5)
140                  return(MG_EARGC);
141          if (!isflt(av[2]) || !isflt(av[4]))
142                  return(MG_ETYPE);
143 +                                        /* get the endpoint vertices */
144          if ((cv1 = c_getvert(av[1])) == NULL ||
145                          (cv2 = c_getvert(av[3])) == NULL)
146                  return(MG_EUNDEF);
147 <        xf_xfmpoint(p1, cv1->p);
147 >        xf_xfmpoint(p1, cv1->p);        /* transform endpoints */
148          xf_xfmpoint(p2, cv2->p);
149 <        r1 = xf_scale(atof(av[2]));
149 >        r1 = xf_scale(atof(av[2]));     /* scale radii */
150          r2 = xf_scale(atof(av[4]));
151 <        inv = r1 < 0.;
152 <        if (r1 == 0.) {
151 >        inv = r1 < 0.;                  /* check for inverted cone */
152 >        if (r1 == 0.) {                 /* check for illegal radii */
153                  if (r2 == 0.)
154                          return(MG_EILL);
155                  inv = r2 < 0.;
# Line 148 | Line 159 | char   **av;
159                  r1 = -r1;
160                  r2 = -r2;
161          }
162 <        if ((mat = material()) == NULL)
162 >        if ((mat = material()) == NULL) /* get material */
163                  return(MG_EBADMAT);
164 +                                        /* spit the sucker out */
165          printf("\n%s %s %sc%d\n", mat, inv ? "cup" : "cone",
166                          object(), ++ncones);
167          printf("0\n0\n8\n");
# Line 171 | Line 183 | char   **av;
183          C_VERTEX        *cv1, *cv2;
184          FVECT   p1, p2;
185          int     inv;
186 <
186 >                                        /* check argument count and type */
187          if (ac != 4)
188                  return(MG_EARGC);
189          if (!isflt(av[2]))
190                  return(MG_ETYPE);
191 +                                        /* get the endpoint vertices */
192          if ((cv1 = c_getvert(av[1])) == NULL ||
193                          (cv2 = c_getvert(av[3])) == NULL)
194                  return(MG_EUNDEF);
195 <        xf_xfmpoint(p1, cv1->p);
195 >        xf_xfmpoint(p1, cv1->p);        /* transform endpoints */
196          xf_xfmpoint(p2, cv2->p);
197 <        rad = xf_scale(atof(av[2]));
198 <        if ((inv = rad < 0.))
197 >        rad = xf_scale(atof(av[2]));    /* scale radius */
198 >        if ((inv = rad < 0.))           /* check for inverted cylinder */
199                  rad = -rad;
200 <        if ((mat = material()) == NULL)
200 >        if ((mat = material()) == NULL) /* get material */
201                  return(MG_EBADMAT);
202 +                                        /* spit out the primitive */
203          printf("\n%s %s %scy%d\n", mat, inv ? "tube" : "cylinder",
204                          object(), ++ncyls);
205          printf("0\n0\n7\n");
# Line 207 | Line 221 | char   **av;
221          C_VERTEX        *cv;
222          FVECT   cent;
223          int     inv;
224 <
224 >                                        /* check argument count and type */
225          if (ac != 3)
226                  return(MG_EARGC);
227          if (!isflt(av[2]))
228                  return(MG_ETYPE);
229 <        if ((cv = c_getvert(av[1])) == NULL)
229 >        if ((cv = c_getvert(av[1])) == NULL)    /* get center vertex */
230                  return(MG_EUNDEF);
231 <        xf_xfmpoint(cent, cv->p);
232 <        rad = xf_scale(atof(av[2]));
233 <        if ((inv = rad < 0.))
231 >        xf_xfmpoint(cent, cv->p);               /* transform center */
232 >        rad = xf_scale(atof(av[2]));            /* scale radius */
233 >        if ((inv = rad < 0.))                   /* check for inversion */
234                  rad = -rad;
235 <        if ((mat = material()) == NULL)
235 >        if ((mat = material()) == NULL)         /* get material */
236                  return(MG_EBADMAT);
237 +                                                /* spit out primitive */
238          printf("\n%s %s %ss%d\n", mat, inv ? "bubble" : "sphere",
239                          object(), ++nsphs);
240          printf("0\n0\n4 %18.12g %18.12g %18.12g %18.12g\n",
# Line 238 | Line 253 | char   **av;
253          double  r1, r2;
254          C_VERTEX        *cv;
255          FVECT   cent, norm;
256 <
256 >                                        /* check argument count and type */
257          if (ac != 4)
258                  return(MG_EARGC);
259          if (!isflt(av[2]) || !isflt(av[3]))
260                  return(MG_ETYPE);
261 <        if ((cv = c_getvert(av[1])) == NULL)
261 >        if ((cv = c_getvert(av[1])) == NULL)    /* get center vertex */
262                  return(MG_EUNDEF);
263 <        if (is0vect(cv->n))
263 >        if (is0vect(cv->n))                     /* make sure we have normal */
264                  return(MG_EILL);
265 <        xf_xfmpoint(cent, cv->p);
266 <        xf_rotvect(norm, cv->n);
267 <        r1 = xf_scale(atof(av[2]));
265 >        xf_xfmpoint(cent, cv->p);               /* transform center */
266 >        xf_rotvect(norm, cv->n);                /* rotate normal */
267 >        r1 = xf_scale(atof(av[2]));             /* scale radii */
268          r2 = xf_scale(atof(av[3]));
269          if (r1 < 0. | r2 <= r1)
270                  return(MG_EILL);
271 <        if ((mat = material()) == NULL)
271 >        if ((mat = material()) == NULL)         /* get material */
272                  return(MG_EBADMAT);
273 +                                                /* spit out primitive */
274          printf("\n%s ring %sr%d\n", mat, object(), ++nrings);
275          printf("0\n0\n8\n");
276          putv(cent);
# Line 275 | Line 291 | char   **av;
291          register C_VERTEX       *cv;
292          FVECT   v;
293          int     rv;
294 <
294 >                                        /* check argument count and type */
295          if (ac < 4)
296                  return(MG_EARGC);
297 <        if ((mat = material()) == NULL)
297 >        if ((mat = material()) == NULL) /* get material */
298                  return(MG_EBADMAT);
299 <        if (ac < 5) {                           /* check for surface normals */
299 >        if (ac <= 5) {                          /* check for smoothing */
300                  for (i = 1; i < ac; i++) {
301                          if ((cv = c_getvert(av[i])) == NULL)
302                                  return(MG_EUNDEF);
# Line 294 | Line 310 | char   **av;
310                          return(MG_OK);
311                  }
312          }
313 +                                        /* spit out unsmoothed primitive */
314          printf("\n%s polygon %sf%d\n", mat, object(), ++nfaces);
315          printf("0\n0\n%d\n", 3*(ac-1));
316 <        for (i = 1; i < ac; i++) {
317 <                if ((cv = c_getvert(av[i])) == NULL)
316 >        for (i = 1; i < ac; i++) {      /* get, transform, print each vertex */
317 >                if ((cv = c_getvert(av[invert ? ac-i : i])) == NULL)
318                          return(MG_EUNDEF);
319                  xf_xfmpoint(v, cv->p);
320                  putv(v);
# Line 306 | Line 323 | char   **av;
323   }
324  
325  
326 + int
327   r_ies(ac, av)                           /* convert an IES luminaire file */
328   int     ac;
329   char    **av;
330   {
331          int     xa0 = 2;
332 <        char    combuf[72];
332 >        char    combuf[128];
333          char    fname[48];
334          char    *oname;
335          register char   *op;
336          register int    i;
337 <
337 >                                        /* check argument count */
338          if (ac < 2)
339                  return(MG_EARGC);
340 <        (void)strcpy(combuf, "ies2rad");
323 <        op = combuf + 7;
324 <        if (ac-xa0 >= 2 && !strcmp(av[xa0], "-m")) {
325 <                if (!isflt(av[xa0+1]))
326 <                        return(MG_ETYPE);
327 <                op = addarg(addarg(op, "-m"), av[xa0+1]);
328 <                xa0 += 2;
329 <        }
330 <        if (access(av[1], 0) == -1)
331 <                return(MG_ENOFILE);
332 <        *op++ = ' ';                    /* IES filename goes last */
333 <        (void)strcpy(op, av[1]);
334 <        system(combuf);                 /* run ies2rad */
335 <                                        /* now let's find the output file */
340 >                                        /* construct output file name */
341          if ((op = strrchr(av[1], '/')) == NULL)
342                  op = av[1];
343          (void)strcpy(fname, op);
344          if ((op = strrchr(fname, '.')) == NULL)
345                  op = fname + strlen(fname);
346          (void)strcpy(op, ".rad");
347 <        if (access(fname, 0) == -1)
348 <                return(MG_EINCL);
349 <                                        /* put out xform command */
350 <        printf("\n!xform");
347 >                                        /* see if we need to run ies2rad */
348 >        if (access(fname, 0) == -1) {
349 >                (void)strcpy(combuf, "ies2rad");/* build ies2rad command */
350 >                op = combuf + 7;                /* get -m option (first) */
351 >                if (ac-xa0 >= 2 && !strcmp(av[xa0], "-m")) {
352 >                        if (!isflt(av[xa0+1]))
353 >                                return(MG_ETYPE);
354 >                        op = addarg(addarg(op, "-m"), av[xa0+1]);
355 >                        xa0 += 2;
356 >                }
357 >                *op++ = ' ';                    /* build IES filename */
358 >                i = 0;
359 >                if (mg_file != NULL &&
360 >                                (oname = strrchr(mg_file->fname,'/')) != NULL) {
361 >                        i = oname - mg_file->fname + 1;
362 >                        (void)strcpy(op, mg_file->fname);
363 >                }
364 >                (void)strcpy(op+i, av[1]);
365 >                if (access(op, 0) == -1)        /* check for file existence */
366 >                        return(MG_ENOFILE);
367 >                system(combuf);                 /* run ies2rad */
368 >                if (access(fname, 0) == -1)     /* check success */
369 >                        return(MG_EINCL);
370 >        }
371 >        printf("\n!xform");                     /* put out xform command */
372          oname = object();
373 <        if (*oname)
374 <                printf(" -n %s", oname);
373 >        if (*oname) {
374 >                printf(" -n ");
375 >                for (op = oname; op[1]; op++)   /* remove trailing separator */
376 >                        putchar(*op);
377 >        }
378          for (i = xa0; i < ac; i++)
379                  printf(" %s", av[i]);
380          if (ac > xa0 && xf_argc > 0)
# Line 361 | Line 390 | do_tri(mat, vn1, vn2, vn3)             /* put out smoothed triang
390   char    *mat, *vn1, *vn2, *vn3;
391   {
392          static int      ntris;
364        char    *mod = mat;
393          BARYCCM bvecs;
394          FLOAT   bcoor[3][3];
395          C_VERTEX        *cv1, *cv2, *cv3;
# Line 369 | Line 397 | char   *mat, *vn1, *vn2, *vn3;
397          FVECT   n1, n2, n3;
398          register int    i;
399                          /* the following is repeat code, so assume it's OK */
372        cv1 = c_getvert(vn1);
400          cv2 = c_getvert(vn2);
401 <        cv3 = c_getvert(vn3);
401 >        if (invert) {
402 >                cv3 = c_getvert(vn1);
403 >                cv1 = c_getvert(vn3);
404 >        } else {
405 >                cv1 = c_getvert(vn1);
406 >                cv3 = c_getvert(vn3);
407 >        }
408          xf_xfmpoint(v1, cv1->p);
409          xf_xfmpoint(v2, cv2->p);
410          xf_xfmpoint(v3, cv3->p);
411 <        if (comp_baryc(&bvecs, v1, v2, v3) == 0) {
412 <                printf("\n%s texfunc T-nor\n", mod);
413 <                mod = "T-nor";
414 <                printf("4 dx dy dz %s\n0\n", TCALNAME);
415 <                xf_rotvect(n1, cv1->n);
416 <                xf_rotvect(n2, cv2->n);
417 <                xf_rotvect(n3, cv3->n);
418 <                for (i = 0; i < 3; i++) {
419 <                        bcoor[i][0] = n1[i];
420 <                        bcoor[i][1] = n2[i];
421 <                        bcoor[i][2] = n3[i];
422 <                }
390 <                put_baryc(&bvecs, bcoor, 3);
411 >                                        /* compute barycentric coords. */
412 >        if (comp_baryc(&bvecs, v1, v2, v3) < 0)
413 >                return;                         /* degenerate triangle! */
414 >        printf("\n%s texfunc T-nor\n", mat);    /* put out texture */
415 >        printf("4 dx dy dz %s\n0\n", TCALNAME);
416 >        xf_rotvect(n1, cv1->n);
417 >        xf_rotvect(n2, cv2->n);
418 >        xf_rotvect(n3, cv3->n);
419 >        for (i = 0; i < 3; i++) {
420 >                bcoor[i][0] = n1[i];
421 >                bcoor[i][1] = n2[i];
422 >                bcoor[i][2] = n3[i];
423          }
424 <        printf("\n%s polygon %st%d\n", mod, object(), ++ntris);
424 >        put_baryc(&bvecs, bcoor, 3);
425 >                                                /* put out triangle */
426 >        printf("\nT-nor polygon %st%d\n", object(), ++ntris);
427          printf("0\n0\n9\n");
428          putv(v1);
429          putv(v2);
# Line 405 | Line 439 | material()                     /* get (and print) current material */
439          double  d;
440          register int    i;
441  
442 <        if (c_cmaterial->name != NULL)
443 <                mname = c_cmaterial->name;
442 >        if (c_cmname != NULL)
443 >                mname = c_cmname;
444          if (!c_cmaterial->clock)
445                  return(mname);          /* already current */
446                                  /* else update output */
447          c_cmaterial->clock = 0;
448          if (c_cmaterial->ed > .1) {     /* emitter */
449                  cvtcolor(radrgb, &c_cmaterial->ed_c,
450 <                                emult*c_cmaterial->ed/WHTEFFICACY);
451 <                if (glowdist < BIGFLT) {        /* do a glow */
452 <                        printf("\nvoid glow %s\n0\n0\n", mname);
453 <                        printf("4 %f %f %f %f\n", colval(radrgb,RED),
450 >                                emult*c_cmaterial->ed/(PI*WHTEFFICACY));
451 >                if (glowdist < FHUGE) {         /* do a glow */
452 >                        fprintf(matfp, "\nvoid glow %s\n0\n0\n", mname);
453 >                        fprintf(matfp, "4 %f %f %f %f\n", colval(radrgb,RED),
454                                          colval(radrgb,GRN),
455                                          colval(radrgb,BLU), glowdist);
456                  } else {
457 <                        printf("\nvoid light %s\n0\n0\n", mname);
458 <                        printf("3 %f %f %f\n", colval(radrgb,RED),
457 >                        fprintf(matfp, "\nvoid light %s\n0\n0\n", mname);
458 >                        fprintf(matfp, "3 %f %f %f\n", colval(radrgb,RED),
459                                          colval(radrgb,GRN),
460                                          colval(radrgb,BLU));
461                  }
# Line 429 | Line 463 | material()                     /* get (and print) current material */
463          }
464          d = c_cmaterial->rd + c_cmaterial->td +
465                          c_cmaterial->rs + c_cmaterial->ts;
466 <        if (d <= 0. | d >= 1.)
466 >        if (d < 0. | d > 1.)
467                  return(NULL);
468 <        if (c_cmaterial->td > .01 || c_cmaterial->ts > .01) {   /* trans */
468 >                                        /* check for glass/dielectric */
469 >        if (c_cmaterial->nr > 1.1 &&
470 >                        c_cmaterial->ts > .25 && c_cmaterial->rs <= .125 &&
471 >                        c_cmaterial->td <= .01 && c_cmaterial->rd <= .01 &&
472 >                        c_cmaterial->rs_a <= .01 && c_cmaterial->ts_a <= .01) {
473 >                cvtcolor(radrgb, &c_cmaterial->ts_c,
474 >                                c_cmaterial->ts + c_cmaterial->rs);
475 >                if (c_cmaterial->sided) {               /* dielectric */
476 >                        colval(radrgb,RED) = pow(colval(radrgb,RED),
477 >                                                        1./C_1SIDEDTHICK);
478 >                        colval(radrgb,GRN) = pow(colval(radrgb,GRN),
479 >                                                        1./C_1SIDEDTHICK);
480 >                        colval(radrgb,BLU) = pow(colval(radrgb,BLU),
481 >                                                        1./C_1SIDEDTHICK);
482 >                        fprintf(matfp, "\nvoid dielectric %s\n0\n0\n", mname);
483 >                        fprintf(matfp, "5 %g %g %g %f 0\n", colval(radrgb,RED),
484 >                                        colval(radrgb,GRN), colval(radrgb,BLU),
485 >                                        c_cmaterial->nr);
486 >                        return(mname);
487 >                }
488 >                                                        /* glass */
489 >                fprintf(matfp, "\nvoid glass %s\n0\n0\n", mname);
490 >                fprintf(matfp, "4 %f %f %f %f\n", colval(radrgb,RED),
491 >                                colval(radrgb,GRN), colval(radrgb,BLU),
492 >                                c_cmaterial->nr);
493 >                return(mname);
494 >                }
495 >                                        /* check for trans */
496 >        if (c_cmaterial->td > .01 || c_cmaterial->ts > .01) {
497                  double  ts, a5, a6;
498  
499 <                ts = sqrt(c_cmaterial->ts);     /* because we use 2 sides */
499 >                if (c_cmaterial->sided) {
500 >                        ts = sqrt(c_cmaterial->ts);     /* approximate */
501 >                        a5 = .5;
502 >                } else {
503 >                        ts = c_cmaterial->ts;
504 >                        a5 = 1.;
505 >                }
506                                                  /* average colors */
507                  d = c_cmaterial->rd + c_cmaterial->td + ts;
508                  cvtcolor(radrgb, &c_cmaterial->rd_c, c_cmaterial->rd/d);
# Line 444 | Line 512 | material()                     /* get (and print) current material */
512                  addcolor(radrgb, c2);
513                  if (c_cmaterial->rs + ts > .0001)
514                          a5 = (c_cmaterial->rs*c_cmaterial->rs_a +
515 <                                        ts*.5*c_cmaterial->ts_a) /
515 >                                        ts*a5*c_cmaterial->ts_a) /
516                                          (c_cmaterial->rs + ts);
517                  a6 = (c_cmaterial->td + ts) /
518                                  (c_cmaterial->rd + c_cmaterial->td + ts);
519 <                if (a6 < .999) {
519 >                if (a6 < .999)
520                          d = c_cmaterial->rd/(1. - c_cmaterial->rs)/(1. - a6);
521 <                        scalecolor(radrgb, d);
522 <                }
523 <                printf("\nvoid trans %s\n0\n0\n", mname);
524 <                printf("7 %f %f %f\n", colval(radrgb,RED),
521 >                else
522 >                        d = c_cmaterial->td + ts;
523 >                scalecolor(radrgb, d);
524 >                fprintf(matfp, "\nvoid trans %s\n0\n0\n", mname);
525 >                fprintf(matfp, "7 %f %f %f\n", colval(radrgb,RED),
526                                  colval(radrgb,GRN), colval(radrgb,BLU));
527 <                printf("\t%f %f %f %f\n", c_cmaterial->rs, a5, a6,
527 >                fprintf(matfp, "\t%f %f %f %f\n", c_cmaterial->rs, a5, a6,
528                                  ts/(ts + c_cmaterial->td));
529                  return(mname);
530          }
531 <        if (c_cmaterial->rs < .01 || isgrey(&c_cmaterial->rs_c)) { /* plastic */
532 <                if (c_cmaterial->rs > .999)
533 <                        cvtcolor(radrgb, &c_cmaterial->rd_c, 1.);
534 <                else
466 <                        cvtcolor(radrgb, &c_cmaterial->rd_c,
531 >                                        /* check for plastic */
532 >        if (c_cmaterial->rs < .1 && (c_cmaterial->rs < .01 ||
533 >                                        c_isgrey(&c_cmaterial->rs_c))) {
534 >                cvtcolor(radrgb, &c_cmaterial->rd_c,
535                                          c_cmaterial->rd/(1.-c_cmaterial->rs));
536 <                printf("\nvoid plastic %s\n0\n0\n", mname);
537 <                printf("5 %f %f %f %f %f\n", colval(radrgb,RED),
536 >                fprintf(matfp, "\nvoid plastic %s\n0\n0\n", mname);
537 >                fprintf(matfp, "5 %f %f %f %f %f\n", colval(radrgb,RED),
538                                  colval(radrgb,GRN), colval(radrgb,BLU),
539                                  c_cmaterial->rs, c_cmaterial->rs_a);
540                  return(mname);
541          }
542                                          /* else it's metal */
543 <        d = c_cmaterial->rd + c_cmaterial->rs;  /* average colors */
544 <        cvtcolor(radrgb, &c_cmaterial->rd_c, c_cmaterial->rd/d);
545 <        cvtcolor(c2, &c_cmaterial->rs_c, c_cmaterial->rs/d);
543 >                                                /* average colors */
544 >        cvtcolor(radrgb, &c_cmaterial->rd_c, c_cmaterial->rd);
545 >        cvtcolor(c2, &c_cmaterial->rs_c, c_cmaterial->rs);
546          addcolor(radrgb, c2);
547 <        if (c_cmaterial->rs < .999) {
548 <                d = c_cmaterial->rd/(1. - c_cmaterial->rs);
481 <                scalecolor(radrgb, d);
482 <        }
483 <        printf("\nvoid metal %s\n0\n0\n", mname);
484 <        printf("5 %f %f %f %f %f\n", colval(radrgb,RED),
547 >        fprintf(matfp, "\nvoid metal %s\n0\n0\n", mname);
548 >        fprintf(matfp, "5 %f %f %f %f %f\n", colval(radrgb,RED),
549                          colval(radrgb,GRN), colval(radrgb,BLU),
550 <                        c_cmaterial->rs, c_cmaterial->rs_a);
550 >                        c_cmaterial->rs/(c_cmaterial->rd + c_cmaterial->rs),
551 >                        c_cmaterial->rs_a);
552          return(mname);
553   }
554  
555  
556 < cvtcolor(radrgb, ciec, intensity)       /* convert a CIE color to Radiance */
556 > cvtcolor(radrgb, ciec, intensity)       /* convert a CIE XYZ color to RGB */
557   COLOR   radrgb;
558   register C_COLOR        *ciec;
559   double  intensity;
560   {
561          static COLOR    ciexyz;
562  
563 +        c_ccvt(ciec, C_CSXY);           /* get xy representation */
564          ciexyz[1] = intensity;
565          ciexyz[0] = ciec->cx/ciec->cy*ciexyz[1];
566          ciexyz[2] = ciexyz[1]*(1./ciec->cy - 1.) - ciexyz[0];
# Line 509 | Line 575 | object()                       /* return current object name */
575          register int    i;
576          register char   *cp;
577          int     len;
578 <
578 >                                                /* tracked by obj_handler */
579          i = obj_nnames - sizeof(objbuf)/16;
580          if (i < 0)
581                  i = 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines