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.8 by greg, Tue Jul 19 15:54:44 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 isgrey(cxy)     ((cxy)->cx > .31 && (cxy)->cx < .35 && \
21 <                        (cxy)->cy > .31 && (cxy)->cy < .35)
20 > double  glowdist = FHUGE;               /* glow test distance */
21  
22 < #define is0vect(v)      ((v)[0] == 0. && (v)[1] == 0. && (v)[2] == 0.)
22 > double  emult = 1.;                     /* emitter multiplier */
23  
25 #define BIGFLT          1e8
26
27 double  glowdist = 1.5*BIGFLT;          /* glow test distance */
28
29 double  emult = 1.;                     /* emmitter multiplier */
30
24   int     r_comment(), r_cone(), r_cyl(), r_face(), r_ies(), r_ring(), r_sph();
25   char    *material(), *object(), *addarg();
26  
# Line 41 | Line 34 | char   *argv[];
34          mg_ehand[MG_E_COMMENT] = r_comment;
35          mg_ehand[MG_E_COLOR] = c_hcolor;
36          mg_ehand[MG_E_CONE] = r_cone;
37 +        mg_ehand[MG_E_CMIX] = c_hcolor;
38 +        mg_ehand[MG_E_CSPEC] = c_hcolor;
39          mg_ehand[MG_E_CXY] = c_hcolor;
40          mg_ehand[MG_E_CYL] = r_cyl;
41          mg_ehand[MG_E_ED] = c_hmaterial;
# Line 53 | Line 48 | char   *argv[];
48          mg_ehand[MG_E_RD] = c_hmaterial;
49          mg_ehand[MG_E_RING] = r_ring;
50          mg_ehand[MG_E_RS] = c_hmaterial;
51 +        mg_ehand[MG_E_SIDES] = c_hmaterial;
52          mg_ehand[MG_E_SPH] = r_sph;
53          mg_ehand[MG_E_TD] = c_hmaterial;
54          mg_ehand[MG_E_TS] = c_hmaterial;
# Line 104 | Line 100 | r_comment(ac, av)              /* repeat a comment verbatim */
100   register int    ac;
101   register char   **av;
102   {
103 <        fputs("\n#", stdout);   /* use Radiance comment character */
103 >        putchar('#');           /* use Radiance comment character */
104          while (--ac) {
105                  putchar(' ');
106                  fputs(*++av, stdout);
# Line 280 | Line 276 | char   **av;
276                  return(MG_EARGC);
277          if ((mat = material()) == NULL)
278                  return(MG_EBADMAT);
279 <        if (ac < 5) {                           /* check for surface normals */
279 >        if (ac <= 5) {                          /* check for surface normals */
280                  for (i = 1; i < ac; i++) {
281                          if ((cv = c_getvert(av[i])) == NULL)
282                                  return(MG_EUNDEF);
# Line 344 | Line 340 | char   **av;
340                                          /* put out xform command */
341          printf("\n!xform");
342          oname = object();
343 <        if (*oname)
344 <                printf(" -n %s", oname);
343 >        if (*oname) {
344 >                printf(" -n ");
345 >                for (op = oname; op[1]; op++)   /* remove trailing separator */
346 >                        putchar(*op);
347 >        }
348          for (i = xa0; i < ac; i++)
349                  printf(" %s", av[i]);
350          if (ac > xa0 && xf_argc > 0)
# Line 361 | Line 360 | do_tri(mat, vn1, vn2, vn3)             /* put out smoothed triang
360   char    *mat, *vn1, *vn2, *vn3;
361   {
362          static int      ntris;
364        char    *mod = mat;
363          BARYCCM bvecs;
364          FLOAT   bcoor[3][3];
365          C_VERTEX        *cv1, *cv2, *cv3;
# Line 375 | Line 373 | char   *mat, *vn1, *vn2, *vn3;
373          xf_xfmpoint(v1, cv1->p);
374          xf_xfmpoint(v2, cv2->p);
375          xf_xfmpoint(v3, cv3->p);
376 <        if (comp_baryc(&bvecs, v1, v2, v3) == 0) {
377 <                printf("\n%s texfunc T-nor\n", mod);
378 <                mod = "T-nor";
379 <                printf("4 dx dy dz %s\n0\n", TCALNAME);
380 <                xf_rotvect(n1, cv1->n);
381 <                xf_rotvect(n2, cv2->n);
382 <                xf_rotvect(n3, cv3->n);
383 <                for (i = 0; i < 3; i++) {
384 <                        bcoor[i][0] = n1[i];
385 <                        bcoor[i][1] = n2[i];
386 <                        bcoor[i][2] = n3[i];
389 <                }
390 <                put_baryc(&bvecs, bcoor, 3);
376 >        if (comp_baryc(&bvecs, v1, v2, v3) < 0)
377 >                return;                         /* degenerate triangle! */
378 >        printf("\n%s texfunc T-nor\n", mat);
379 >        printf("4 dx dy dz %s\n0\n", TCALNAME);
380 >        xf_rotvect(n1, cv1->n);
381 >        xf_rotvect(n2, cv2->n);
382 >        xf_rotvect(n3, cv3->n);
383 >        for (i = 0; i < 3; i++) {
384 >                bcoor[i][0] = n1[i];
385 >                bcoor[i][1] = n2[i];
386 >                bcoor[i][2] = n3[i];
387          }
388 <        printf("\n%s polygon %st%d\n", mod, object(), ++ntris);
388 >        put_baryc(&bvecs, bcoor, 3);
389 >        printf("\nT-nor polygon %st%d\n", object(), ++ntris);
390          printf("0\n0\n9\n");
391          putv(v1);
392          putv(v2);
# Line 405 | Line 402 | material()                     /* get (and print) current material */
402          double  d;
403          register int    i;
404  
405 <        if (c_cmaterial->name != NULL)
406 <                mname = c_cmaterial->name;
405 >        if (c_cmname != NULL)
406 >                mname = c_cmname;
407          if (!c_cmaterial->clock)
408                  return(mname);          /* already current */
409                                  /* else update output */
# Line 414 | Line 411 | material()                     /* get (and print) current material */
411          if (c_cmaterial->ed > .1) {     /* emitter */
412                  cvtcolor(radrgb, &c_cmaterial->ed_c,
413                                  emult*c_cmaterial->ed/WHTEFFICACY);
414 <                if (glowdist < BIGFLT) {        /* do a glow */
414 >                if (glowdist < FHUGE) {         /* do a glow */
415                          printf("\nvoid glow %s\n0\n0\n", mname);
416                          printf("4 %f %f %f %f\n", colval(radrgb,RED),
417                                          colval(radrgb,GRN),
# Line 429 | Line 426 | material()                     /* get (and print) current material */
426          }
427          d = c_cmaterial->rd + c_cmaterial->td +
428                          c_cmaterial->rs + c_cmaterial->ts;
429 <        if (d <= 0. | d >= 1.)
429 >        if (d < 0. | d > 1.)
430                  return(NULL);
431 <        if (c_cmaterial->td > .01 || c_cmaterial->ts > .01) {   /* trans */
431 >                                        /* check for trans */
432 >        if (c_cmaterial->td > .01 || c_cmaterial->ts > .01) {
433                  double  ts, a5, a6;
434  
435 <                ts = sqrt(c_cmaterial->ts);     /* because we use 2 sides */
435 >                if (c_cmaterial->sided) {
436 >                        ts = sqrt(c_cmaterial->ts);     /* approximate */
437 >                        a5 = .5;
438 >                } else {
439 >                        ts = c_cmaterial->ts;
440 >                        a5 = 1.;
441 >                }
442                                                  /* average colors */
443                  d = c_cmaterial->rd + c_cmaterial->td + ts;
444                  cvtcolor(radrgb, &c_cmaterial->rd_c, c_cmaterial->rd/d);
# Line 444 | Line 448 | material()                     /* get (and print) current material */
448                  addcolor(radrgb, c2);
449                  if (c_cmaterial->rs + ts > .0001)
450                          a5 = (c_cmaterial->rs*c_cmaterial->rs_a +
451 <                                        ts*.5*c_cmaterial->ts_a) /
451 >                                        ts*a5*c_cmaterial->ts_a) /
452                                          (c_cmaterial->rs + ts);
453                  a6 = (c_cmaterial->td + ts) /
454                                  (c_cmaterial->rd + c_cmaterial->td + ts);
455 <                if (a6 < .999) {
455 >                if (a6 < .999)
456                          d = c_cmaterial->rd/(1. - c_cmaterial->rs)/(1. - a6);
457 <                        scalecolor(radrgb, d);
458 <                }
457 >                else
458 >                        d = c_cmaterial->td + ts;
459 >                scalecolor(radrgb, d);
460                  printf("\nvoid trans %s\n0\n0\n", mname);
461                  printf("7 %f %f %f\n", colval(radrgb,RED),
462                                  colval(radrgb,GRN), colval(radrgb,BLU));
# Line 459 | Line 464 | material()                     /* get (and print) current material */
464                                  ts/(ts + c_cmaterial->td));
465                  return(mname);
466          }
467 <        if (c_cmaterial->rs < .01 || isgrey(&c_cmaterial->rs_c)) { /* plastic */
468 <                if (c_cmaterial->rs > .999)
469 <                        cvtcolor(radrgb, &c_cmaterial->rd_c, 1.);
470 <                else
466 <                        cvtcolor(radrgb, &c_cmaterial->rd_c,
467 >                                        /* check for plastic */
468 >        if (c_cmaterial->rs < .1 && (c_cmaterial->rs < .01 ||
469 >                                        c_isgrey(&c_cmaterial->rs_c))) {
470 >                cvtcolor(radrgb, &c_cmaterial->rd_c,
471                                          c_cmaterial->rd/(1.-c_cmaterial->rs));
472                  printf("\nvoid plastic %s\n0\n0\n", mname);
473                  printf("5 %f %f %f %f %f\n", colval(radrgb,RED),
# Line 472 | Line 476 | material()                     /* get (and print) current material */
476                  return(mname);
477          }
478                                          /* else it's metal */
479 <        d = c_cmaterial->rd + c_cmaterial->rs;  /* average colors */
480 <        cvtcolor(radrgb, &c_cmaterial->rd_c, c_cmaterial->rd/d);
481 <        cvtcolor(c2, &c_cmaterial->rs_c, c_cmaterial->rs/d);
479 >                                                /* average colors */
480 >        cvtcolor(radrgb, &c_cmaterial->rd_c, c_cmaterial->rd);
481 >        cvtcolor(c2, &c_cmaterial->rs_c, c_cmaterial->rs);
482          addcolor(radrgb, c2);
479        if (c_cmaterial->rs < .999) {
480                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),
485                          colval(radrgb,GRN), colval(radrgb,BLU),
486 <                        c_cmaterial->rs, c_cmaterial->rs_a);
486 >                        c_cmaterial->rs/(c_cmaterial->rd + c_cmaterial->rs),
487 >                        c_cmaterial->rs_a);
488          return(mname);
489   }
490  
# Line 495 | Line 496 | double intensity;
496   {
497          static COLOR    ciexyz;
498  
499 +        c_ccvt(ciec, C_CSXY);           /* get xy representation */
500          ciexyz[1] = intensity;
501          ciexyz[0] = ciec->cx/ciec->cy*ciexyz[1];
502          ciexyz[2] = ciexyz[1]*(1./ciec->cy - 1.) - ciexyz[0];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines