ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/m_mirror.c
Revision: 2.5
Committed: Sat Aug 26 15:15:51 1995 UTC (28 years, 8 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.4: +13 -4 lines
Log Message:
changed behind test to allow for source sampling

File Contents

# User Rev Content
1 greg 2.5 /* Copyright (c) 1995 Regents of the University of California */
2 greg 1.1
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ LBL";
5     #endif
6    
7     /*
8     * Routines for mirror material supporting virtual light sources
9     */
10    
11     #include "ray.h"
12    
13     #include "otypes.h"
14    
15     #include "source.h"
16    
17     /*
18     * The real arguments for MAT_MIRROR are simply:
19     *
20     * 3 rrefl grefl brefl
21     *
22     * Additionally, the user may specify a single string argument
23     * which is interpreted as the name of the material to use
24     * instead of the mirror if the ray being considered is not
25     * part of the direct calculation.
26     */
27    
28    
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;
36     {
37     COLOR mcolor;
38     RAY nr;
39     register int i;
40     /* check arguments */
41     if (m->oargs.nfargs != 3 || m->oargs.nsargs > 1)
42     objerror(m, USER, "bad number of arguments");
43 greg 1.3 /* check for substitute material */
44     if (m->oargs.nsargs > 0 &&
45     (r->rsrc < 0 || source[r->rsrc].so != r->ro)) {
46 greg 2.4 if (!strcmp(m->oargs.sarg[0], VOIDID)) {
47     raytrans(r);
48     return(1);
49     }
50     return(rayshade(r, modifier(m->oargs.sarg[0])));
51 greg 1.1 }
52 greg 1.3 /* check for bad source ray */
53     if (r->rsrc >= 0 && source[r->rsrc].so != r->ro)
54 greg 2.3 return(1);
55 greg 1.3
56 greg 1.1 if (r->rod < 0.) /* back is black */
57 greg 2.3 return(1);
58 greg 1.1 /* get modifiers */
59     raytexture(r, m->omod);
60     /* assign material color */
61     setcolor(mcolor, m->oargs.farg[0],
62     m->oargs.farg[1],
63     m->oargs.farg[2]);
64     multcolor(mcolor, r->pcol);
65     /* compute reflected ray */
66     if (r->rsrc >= 0) { /* relayed light source */
67     rayorigin(&nr, r, REFLECTED, 1.);
68     /* ignore textures */
69     for (i = 0; i < 3; i++)
70     nr.rdir[i] = r->rdir[i] + 2.*r->rod*r->ron[i];
71     /* source we're aiming for next */
72 greg 1.2 nr.rsrc = source[r->rsrc].sa.sv.sn;
73 greg 1.1 } else { /* ordinary reflection */
74     FVECT pnorm;
75     double pdot;
76    
77     if (rayorigin(&nr, r, REFLECTED, bright(mcolor)) < 0)
78 greg 2.3 return(1);
79 greg 1.1 pdot = raynormal(pnorm, r); /* use textures */
80     for (i = 0; i < 3; i++)
81     nr.rdir[i] = r->rdir[i] + 2.*pdot*pnorm[i];
82 greg 2.2 /* check for penetration */
83     if (DOT(nr.rdir, r->ron) <= FTINY)
84     for (i = 0; i < 3; i++)
85     nr.rdir[i] = r->rdir[i] + 2.*r->rod*r->ron[i];
86 greg 1.1 }
87     rayvalue(&nr);
88     multcolor(nr.rcol, mcolor);
89     addcolor(r->rcol, nr.rcol);
90 greg 2.3 return(1);
91 greg 1.1 }
92    
93    
94     mir_proj(pm, o, s, n) /* compute a mirror's projection */
95     MAT4 pm;
96     register OBJREC *o;
97 greg 1.2 SRCREC *s;
98 greg 1.1 int n;
99     {
100 greg 2.5 FVECT nv, sc;
101 greg 1.1 double od;
102 greg 2.5 register int i, j;
103 greg 1.1 /* get surface normal and offset */
104 greg 1.2 od = getplaneq(nv, o);
105 greg 2.5 /* check for extreme point for behind */
106     VCOPY(sc, s->sloc);
107     for (i = s->sflags & SFLAT ? SV : SW; i >= 0; i--)
108     if (DOT(nv, s->ss[i]) > 0.)
109     for (j = 0; j < 3; j++)
110     sc[j] += s->ss[i][j];
111     else
112     for (j = 0; j < 3; j++)
113     sc[j] -= s->ss[i][j];
114     if (DOT(sc, nv) <= (s->sflags & SDISTANT ? FTINY : od+FTINY))
115 greg 1.1 return(0);
116     /* everything OK -- compute projection */
117     mirrorproj(pm, nv, od);
118     return(1);
119     }
120    
121    
122     mirrorproj(m, nv, offs) /* get mirror projection for surface */
123     register MAT4 m;
124     FVECT nv;
125     double offs;
126     {
127     register int i, j;
128     /* assign matrix */
129     setident4(m);
130 greg 1.2 for (j = 0; j < 3; j++) {
131     for (i = 0; i < 3; i++)
132 greg 1.1 m[i][j] -= 2.*nv[i]*nv[j];
133     m[3][j] = 2.*offs*nv[j];
134 greg 1.2 }
135 greg 1.1 }