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

Comparing ray/src/rt/m_mirror.c (file contents):
Revision 1.2 by greg, Tue Jul 16 15:56:46 1991 UTC vs.
Revision 2.24 by greg, Thu May 29 16:42:28 2025 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1991 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Routines for mirror material supporting virtual light sources
6   */
7  
8 < #include  "ray.h"
8 > #include "copyright.h"
9  
10 + #include  "ray.h"
11   #include  "otypes.h"
12 <
12 > #include  "otspecial.h"
13 > #include  "rtotypes.h"
14   #include  "source.h"
15  
16   /*
# Line 25 | Line 24 | static char SCCSid[] = "$SunId$ LBL";
24   * part of the direct calculation.
25   */
26  
27 + static int mir_proj(MAT4  pm, OBJREC  *o, SRCREC  *s, int  n);
28 + static void mirrorproj(MAT4  m, FVECT  nv, double  offs);
29  
29 int  mir_proj();
30   VSMATERIAL  mirror_vs = {mir_proj, 1};
31  
32  
33 < m_mirror(m, r)                  /* shade mirrored ray */
34 < register OBJREC  *m;
35 < register RAY  *r;
33 > int
34 > m_mirror(                       /* shade mirrored ray */
35 >        OBJREC  *m,
36 >        RAY  *r
37 > )
38   {
39 <        COLOR  mcolor;
39 >        SCOLOR  mcolor;
40          RAY  nr;
41 <        register int  i;
41 >        int  rpure = 1;
42 >        int  i;
43                                          /* check arguments */
44          if (m->oargs.nfargs != 3 || m->oargs.nsargs > 1)
45                  objerror(m, USER, "bad number of arguments");
46 <                                        /* check if source ray */
47 <        if (r->rsrc >= 0) {                     /* aiming for somebody */
48 <                if (source[r->rsrc].so != r->ro)
49 <                        return;                         /* but not us */
50 <        } else if (m->oargs.nsargs > 0) {       /* else call substitute? */
51 <                rayshade(r, modifier(m->oargs.sarg[0]));
52 <                return;
46 >                                        /* check for substitute material */
47 >                                        /* but avoid double-counting */
48 >        if (m->oargs.nsargs > 0 &&
49 >                        (r->rsrc < 0 || source[r->rsrc].so != r->ro)) {
50 >                int     passOK = (r->rod < 0.) |
51 >                                        !(r->crtype & (AMBIENT|SPECULAR));
52 >                if (strcmp(m->oargs.sarg[0], VOIDID)) {
53 >                        OBJECT  altmod = lastmod(objndx(m), m->oargs.sarg[0]);
54 >                        OBJREC  *altmat;
55 >                        if (passOK)             /* no double-count hazard? */
56 >                                return(rayshade(r, altmod));
57 >                        if (altmod == OVOID ||  /* else check alternate type */
58 >                                        (altmat = findmaterial(objptr(altmod))) == NULL)
59 >                                return(0);
60 >                        if (istransp(altmat))   /* pass "transparent" materials */
61 >                                return(rayshade(r, altmod));
62 >                } else if (passOK) {
63 >                        raytrans(r);            /* "safe" void passage */
64 >                        return(1);
65 >                }
66          }
67 <        if (r->rod < 0.)                /* back is black */
68 <                return;
67 >                                        /* check for bad source ray */
68 >        if (r->rsrc >= 0 && source[r->rsrc].so != r->ro)
69 >                return(1);
70 >
71 >        if (r->rod < 0.) {              /* back is black */
72 >                if (!backvis)
73 >                        raytrans(r);    /* unless back visibility is off */
74 >                return(1);
75 >        }
76                                          /* get modifiers */
77          raytexture(r, m->omod);
78                                          /* assign material color */
79 <        setcolor(mcolor, m->oargs.farg[0],
79 >        setscolor(mcolor, m->oargs.farg[0],
80                          m->oargs.farg[1],
81                          m->oargs.farg[2]);
82 <        multcolor(mcolor, r->pcol);
82 >        smultscolor(mcolor, r->pcol);
83                                          /* compute reflected ray */
84          if (r->rsrc >= 0) {                     /* relayed light source */
85 <                rayorigin(&nr, r, REFLECTED, 1.);
85 >                rayorigin(&nr, REFLECTED, r, mcolor);
86                                          /* ignore textures */
87                  for (i = 0; i < 3; i++)
88                          nr.rdir[i] = r->rdir[i] + 2.*r->rod*r->ron[i];
# Line 69 | Line 92 | register RAY  *r;
92                  FVECT  pnorm;
93                  double  pdot;
94  
95 <                if (rayorigin(&nr, r, REFLECTED, bright(mcolor)) < 0)
96 <                        return;
97 <                pdot = raynormal(pnorm, r);     /* use textures */
98 <                for (i = 0; i < 3; i++)
99 <                        nr.rdir[i] = r->rdir[i] + 2.*pdot*pnorm[i];
95 >                if (rayorigin(&nr, REFLECTED, r, mcolor) < 0)
96 >                        return(1);
97 >                if (!(r->crtype & AMBIENT) &&
98 >                                DOT(r->pert,r->pert) > FTINY*FTINY) {
99 >                        pdot = raynormal(pnorm, r);     /* use textures */
100 >                        for (i = 0; i < 3; i++)
101 >                                nr.rdir[i] = r->rdir[i] + 2.*pdot*pnorm[i];
102 >                        rpure = 0;
103 >                }
104 >                                                /* check for penetration */
105 >                if (rpure || DOT(nr.rdir, r->ron) <= FTINY)
106 >                        for (i = 0; i < 3; i++)
107 >                                nr.rdir[i] = r->rdir[i] + 2.*r->rod*r->ron[i];
108          }
109 +        checknorm(nr.rdir);
110          rayvalue(&nr);
111 <        multcolor(nr.rcol, mcolor);
112 <        addcolor(r->rcol, nr.rcol);
111 >        smultscolor(nr.rcol, nr.rcoef);
112 >        copyscolor(r->mcol, nr.rcol);
113 >        saddscolor(r->rcol, nr.rcol);
114 >        r->rmt = r->rot;
115 >        if (rpure && r->ro != NULL && isflat(r->ro->otype))
116 >                r->rmt += raydistance(&nr);
117 >        return(1);
118   }
119  
120  
121 < mir_proj(pm, o, s, n)           /* compute a mirror's projection */
122 < MAT4  pm;
123 < register OBJREC  *o;
124 < SRCREC  *s;
125 < int  n;
121 > static int
122 > mir_proj(               /* compute a mirror's projection */
123 >        MAT4  pm,
124 >        OBJREC  *o,
125 >        SRCREC  *s,
126 >        int  n
127 > )
128   {
129 <        FVECT  nv;
130 <        double  od;
129 >        double  corr = 1.;
130 >        FVECT  nv, sc;
131 >        double  od, offs;
132 >        int  i;
133                                  /* get surface normal and offset */
134 <        od = getplaneq(nv, o);
135 <                                /* check for behind */
136 <        if (DOT(s->sloc, nv) <= (s->sflags & SDISTANT ? FTINY : od+FTINY))
134 >        offs = od = getplaneq(nv, o);
135 >        if (s->sflags & SDISTANT)
136 >                offs = 0.;
137 >                                /* check for extreme point behind */
138 >        if (s->sflags & SCIR) {
139 >                if (s->sflags & (SFLAT|SDISTANT))
140 >                        corr = 1.12837917;      /* correct setflatss() */
141 >                else
142 >                        corr = 1.0/0.7236;      /* correct sphsetsrc() */
143 >        }
144 >        VCOPY(sc, s->sloc);
145 >        for (i = s->sflags & SFLAT ? SV : SW; i >= 0; i--)
146 >                if (DOT(nv, s->ss[i]) > offs)
147 >                        VSUM(sc, sc, s->ss[i], corr);
148 >                else
149 >                        VSUM(sc, sc, s->ss[i], -corr);
150 >        if (DOT(sc, nv) <= offs+FTINY)
151                  return(0);
152                                  /* everything OK -- compute projection */
153          mirrorproj(pm, nv, od);
# Line 100 | Line 155 | int  n;
155   }
156  
157  
158 < mirrorproj(m, nv, offs)         /* get mirror projection for surface */
159 < register MAT4  m;
160 < FVECT  nv;
161 < double  offs;
158 > static void
159 > mirrorproj(             /* get mirror projection for surface */
160 >        MAT4  m,
161 >        FVECT  nv,
162 >        double  offs
163 > )
164   {
165 <        register int  i, j;
165 >        int  i, j;
166                                          /* assign matrix */
167          setident4(m);
168          for (j = 0; j < 3; j++) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines