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.5 by greg, Fri Jul 1 10:20:19 1994 UTC vs.
Revision 2.10 by greg, Thu Jul 21 17:23:43 1994 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 invert          (xf_context != NULL && xf_context->rev)
21 +
22   double  glowdist = FHUGE;               /* glow test distance */
23  
24 < double  emult = 1.;                     /* emmitter multiplier */
24 > double  emult = 1.;                     /* emitter multiplier */
25  
26   int     r_comment(), r_cone(), r_cyl(), r_face(), r_ies(), r_ring(), r_sph();
27   char    *material(), *object(), *addarg();
# Line 48 | Line 50 | char   *argv[];
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_SIDES] = c_hmaterial;
54          mg_ehand[MG_E_SPH] = r_sph;
55          mg_ehand[MG_E_TD] = c_hmaterial;
56          mg_ehand[MG_E_TS] = c_hmaterial;
# Line 60 | Line 63 | char   *argv[];
63                  printf(" %s", argv[i]);
64                  switch (argv[i][1]) {
65                  case 'g':                       /* glow distance (meters) */
66 <                        if (argv[i][2] || badarg(argc-i, argv+i, "f"))
66 >                        if (argv[i][2] || badarg(argc-i-1, argv+i+1, "f"))
67                                  goto userr;
68                          glowdist = atof(argv[++i]);
69                          printf(" %s", argv[i]);
70                          break;
71                  case 'e':                       /* emitter multiplier */
72 <                        if (argv[i][2] || badarg(argc-i, argv+i, "f"))
72 >                        if (argv[i][2] || badarg(argc-i-1, argv+i+1, "f"))
73                                  goto userr;
74                          emult = atof(argv[++i]);
75                          printf(" %s", argv[i]);
# Line 99 | Line 102 | r_comment(ac, av)              /* repeat a comment verbatim */
102   register int    ac;
103   register char   **av;
104   {
105 <        fputs("\n#", stdout);   /* use Radiance comment character */
105 >        putchar('#');           /* use Radiance comment character */
106          while (--ac) {
107                  putchar(' ');
108                  fputs(*++av, stdout);
# Line 292 | Line 295 | char   **av;
295          printf("\n%s polygon %sf%d\n", mat, object(), ++nfaces);
296          printf("0\n0\n%d\n", 3*(ac-1));
297          for (i = 1; i < ac; i++) {
298 <                if ((cv = c_getvert(av[i])) == NULL)
298 >                if ((cv = c_getvert(av[invert ? ac-i : i])) == NULL)
299                          return(MG_EUNDEF);
300                  xf_xfmpoint(v, cv->p);
301                  putv(v);
# Line 366 | Line 369 | char   *mat, *vn1, *vn2, *vn3;
369          FVECT   n1, n2, n3;
370          register int    i;
371                          /* the following is repeat code, so assume it's OK */
369        cv1 = c_getvert(vn1);
372          cv2 = c_getvert(vn2);
373 <        cv3 = c_getvert(vn3);
373 >        if (invert) {
374 >                cv3 = c_getvert(vn1);
375 >                cv1 = c_getvert(vn3);
376 >        } else {
377 >                cv1 = c_getvert(vn1);
378 >                cv3 = c_getvert(vn3);
379 >        }
380          xf_xfmpoint(v1, cv1->p);
381          xf_xfmpoint(v2, cv2->p);
382          xf_xfmpoint(v3, cv3->p);
# Line 425 | Line 433 | material()                     /* get (and print) current material */
433          }
434          d = c_cmaterial->rd + c_cmaterial->td +
435                          c_cmaterial->rs + c_cmaterial->ts;
436 <        if (d <= 0. | d >= 1.)
436 >        if (d < 0. | d > 1.)
437                  return(NULL);
438                                          /* check for trans */
439          if (c_cmaterial->td > .01 || c_cmaterial->ts > .01) {
440                  double  ts, a5, a6;
441  
442 <                ts = sqrt(c_cmaterial->ts);     /* because we use 2 sides */
442 >                if (c_cmaterial->sided) {
443 >                        ts = sqrt(c_cmaterial->ts);     /* approximate */
444 >                        a5 = .5;
445 >                } else {
446 >                        ts = c_cmaterial->ts;
447 >                        a5 = 1.;
448 >                }
449                                                  /* average colors */
450                  d = c_cmaterial->rd + c_cmaterial->td + ts;
451                  cvtcolor(radrgb, &c_cmaterial->rd_c, c_cmaterial->rd/d);
# Line 441 | Line 455 | material()                     /* get (and print) current material */
455                  addcolor(radrgb, c2);
456                  if (c_cmaterial->rs + ts > .0001)
457                          a5 = (c_cmaterial->rs*c_cmaterial->rs_a +
458 <                                        ts*.5*c_cmaterial->ts_a) /
458 >                                        ts*a5*c_cmaterial->ts_a) /
459                                          (c_cmaterial->rs + ts);
460                  a6 = (c_cmaterial->td + ts) /
461                                  (c_cmaterial->rd + c_cmaterial->td + ts);
462 <                if (a6 < .999) {
462 >                if (a6 < .999)
463                          d = c_cmaterial->rd/(1. - c_cmaterial->rs)/(1. - a6);
464 <                        scalecolor(radrgb, d);
465 <                }
464 >                else
465 >                        d = c_cmaterial->td + ts;
466 >                scalecolor(radrgb, d);
467                  printf("\nvoid trans %s\n0\n0\n", mname);
468                  printf("7 %f %f %f\n", colval(radrgb,RED),
469                                  colval(radrgb,GRN), colval(radrgb,BLU));
# Line 457 | Line 472 | material()                     /* get (and print) current material */
472                  return(mname);
473          }
474                                          /* check for plastic */
475 <        if (c_cmaterial->rs < .01 || c_isgrey(&c_cmaterial->rs_c)) {
476 <                if (c_cmaterial->rs > .999)
477 <                        cvtcolor(radrgb, &c_cmaterial->rd_c, 1.);
463 <                else
464 <                        cvtcolor(radrgb, &c_cmaterial->rd_c,
475 >        if (c_cmaterial->rs < .1 && (c_cmaterial->rs < .01 ||
476 >                                        c_isgrey(&c_cmaterial->rs_c))) {
477 >                cvtcolor(radrgb, &c_cmaterial->rd_c,
478                                          c_cmaterial->rd/(1.-c_cmaterial->rs));
479                  printf("\nvoid plastic %s\n0\n0\n", mname);
480                  printf("5 %f %f %f %f %f\n", colval(radrgb,RED),
# Line 470 | Line 483 | material()                     /* get (and print) current material */
483                  return(mname);
484          }
485                                          /* else it's metal */
486 <        d = c_cmaterial->rd + c_cmaterial->rs;  /* average colors */
487 <        cvtcolor(radrgb, &c_cmaterial->rd_c, c_cmaterial->rd/d);
488 <        cvtcolor(c2, &c_cmaterial->rs_c, c_cmaterial->rs/d);
486 >                                                /* average colors */
487 >        cvtcolor(radrgb, &c_cmaterial->rd_c, c_cmaterial->rd);
488 >        cvtcolor(c2, &c_cmaterial->rs_c, c_cmaterial->rs);
489          addcolor(radrgb, c2);
477        if (c_cmaterial->rs < .999) {
478                d = c_cmaterial->rd/(1. - c_cmaterial->rs);
479                scalecolor(radrgb, d);
480        }
490          printf("\nvoid metal %s\n0\n0\n", mname);
491          printf("5 %f %f %f %f %f\n", colval(radrgb,RED),
492                          colval(radrgb,GRN), colval(radrgb,BLU),
493 <                        c_cmaterial->rs, c_cmaterial->rs_a);
493 >                        c_cmaterial->rs/(c_cmaterial->rd + c_cmaterial->rs),
494 >                        c_cmaterial->rs_a);
495          return(mname);
496   }
497  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines