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.9 by greg, Thu Jul 21 15:04:23 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 > #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  
27 double  glowdist = 1.5*BIGFLT;          /* glow test distance */
28
29 double  emult = 1.;                     /* emmitter multiplier */
30
26   int     r_comment(), r_cone(), r_cyl(), r_face(), r_ies(), r_ring(), r_sph();
27   char    *material(), *object(), *addarg();
28  
# Line 41 | Line 36 | char   *argv[];
36          mg_ehand[MG_E_COMMENT] = r_comment;
37          mg_ehand[MG_E_COLOR] = c_hcolor;
38          mg_ehand[MG_E_CONE] = r_cone;
39 +        mg_ehand[MG_E_CMIX] = c_hcolor;
40 +        mg_ehand[MG_E_CSPEC] = c_hcolor;
41          mg_ehand[MG_E_CXY] = c_hcolor;
42          mg_ehand[MG_E_CYL] = r_cyl;
43          mg_ehand[MG_E_ED] = c_hmaterial;
# Line 53 | 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 104 | 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 280 | Line 278 | char   **av;
278                  return(MG_EARGC);
279          if ((mat = material()) == NULL)
280                  return(MG_EBADMAT);
281 <        if (ac < 5) {                           /* check for surface normals */
281 >        if (ac <= 5) {                          /* check for surface normals */
282                  for (i = 1; i < ac; i++) {
283                          if ((cv = c_getvert(av[i])) == NULL)
284                                  return(MG_EUNDEF);
# Line 297 | 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 344 | Line 342 | char   **av;
342                                          /* put out xform command */
343          printf("\n!xform");
344          oname = object();
345 <        if (*oname)
346 <                printf(" -n %s", oname);
345 >        if (*oname) {
346 >                printf(" -n ");
347 >                for (op = oname; op[1]; op++)   /* remove trailing separator */
348 >                        putchar(*op);
349 >        }
350          for (i = xa0; i < ac; i++)
351                  printf(" %s", av[i]);
352          if (ac > xa0 && xf_argc > 0)
# Line 361 | Line 362 | do_tri(mat, vn1, vn2, vn3)             /* put out smoothed triang
362   char    *mat, *vn1, *vn2, *vn3;
363   {
364          static int      ntris;
364        char    *mod = mat;
365          BARYCCM bvecs;
366          FLOAT   bcoor[3][3];
367          C_VERTEX        *cv1, *cv2, *cv3;
# Line 369 | 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 */
372        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);
383 <        if (comp_baryc(&bvecs, v1, v2, v3) == 0) {
384 <                printf("\n%s texfunc T-nor\n", mod);
385 <                mod = "T-nor";
386 <                printf("4 dx dy dz %s\n0\n", TCALNAME);
387 <                xf_rotvect(n1, cv1->n);
388 <                xf_rotvect(n2, cv2->n);
389 <                xf_rotvect(n3, cv3->n);
390 <                for (i = 0; i < 3; i++) {
391 <                        bcoor[i][0] = n1[i];
392 <                        bcoor[i][1] = n2[i];
393 <                        bcoor[i][2] = n3[i];
389 <                }
390 <                put_baryc(&bvecs, bcoor, 3);
383 >        if (comp_baryc(&bvecs, v1, v2, v3) < 0)
384 >                return;                         /* degenerate triangle! */
385 >        printf("\n%s texfunc T-nor\n", mat);
386 >        printf("4 dx dy dz %s\n0\n", TCALNAME);
387 >        xf_rotvect(n1, cv1->n);
388 >        xf_rotvect(n2, cv2->n);
389 >        xf_rotvect(n3, cv3->n);
390 >        for (i = 0; i < 3; i++) {
391 >                bcoor[i][0] = n1[i];
392 >                bcoor[i][1] = n2[i];
393 >                bcoor[i][2] = n3[i];
394          }
395 <        printf("\n%s polygon %st%d\n", mod, object(), ++ntris);
395 >        put_baryc(&bvecs, bcoor, 3);
396 >        printf("\nT-nor polygon %st%d\n", object(), ++ntris);
397          printf("0\n0\n9\n");
398          putv(v1);
399          putv(v2);
# Line 405 | Line 409 | material()                     /* get (and print) current material */
409          double  d;
410          register int    i;
411  
412 <        if (c_cmaterial->name != NULL)
413 <                mname = c_cmaterial->name;
412 >        if (c_cmname != NULL)
413 >                mname = c_cmname;
414          if (!c_cmaterial->clock)
415                  return(mname);          /* already current */
416                                  /* else update output */
# Line 414 | Line 418 | material()                     /* get (and print) current material */
418          if (c_cmaterial->ed > .1) {     /* emitter */
419                  cvtcolor(radrgb, &c_cmaterial->ed_c,
420                                  emult*c_cmaterial->ed/WHTEFFICACY);
421 <                if (glowdist < BIGFLT) {        /* do a glow */
421 >                if (glowdist < FHUGE) {         /* do a glow */
422                          printf("\nvoid glow %s\n0\n0\n", mname);
423                          printf("4 %f %f %f %f\n", colval(radrgb,RED),
424                                          colval(radrgb,GRN),
# Line 429 | 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 <        if (c_cmaterial->td > .01 || c_cmaterial->ts > .01) {   /* trans */
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 444 | 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 459 | Line 471 | material()                     /* get (and print) current material */
471                                  ts/(ts + c_cmaterial->td));
472                  return(mname);
473          }
474 <        if (c_cmaterial->rs < .01 || isgrey(&c_cmaterial->rs_c)) { /* plastic */
475 <                if (c_cmaterial->rs > .999)
476 <                        cvtcolor(radrgb, &c_cmaterial->rd_c, 1.);
477 <                else
466 <                        cvtcolor(radrgb, &c_cmaterial->rd_c,
474 >                                        /* check for plastic */
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 472 | 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);
479        if (c_cmaterial->rs < .999) {
480                d = c_cmaterial->rd/(1. - c_cmaterial->rs);
481                scalecolor(radrgb, d);
482        }
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  
# Line 495 | Line 503 | double intensity;
503   {
504          static COLOR    ciexyz;
505  
506 +        c_ccvt(ciec, C_CSXY);           /* get xy representation */
507          ciexyz[1] = intensity;
508          ciexyz[0] = ciec->cx/ciec->cy*ciexyz[1];
509          ciexyz[2] = ciexyz[1]*(1./ciec->cy - 1.) - ciexyz[0];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines