ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/ray.h
Revision: 2.59
Committed: Fri Jun 20 03:43:17 2025 UTC (3 days, 17 hours ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.58: +4 -2 lines
Log Message:
fix(rvu): Issue with live reset of -u boolean and consistency improvements

File Contents

# User Rev Content
1 greg 2.59 /* RCSid $Id: ray.h,v 2.58 2025/01/18 03:49:00 greg Exp $ */
2 greg 1.1 /*
3     * ray.h - header file for routines using rays.
4 greg 2.12 */
5 schorsch 2.17 #ifndef _RAD_RAY_H_
6     #define _RAD_RAY_H_
7 greg 1.1
8     #include "standard.h"
9 greg 2.12 #include "octree.h"
10 greg 1.1 #include "object.h"
11 schorsch 2.20 #include "color.h"
12 greg 2.38 #include "pmapparm.h"
13 greg 1.1
14 schorsch 2.20 #ifdef __cplusplus
15     extern "C" {
16     #endif
17 greg 1.1
18 greg 2.30 #ifndef RNUMBER
19 greg 2.48 #define RNUMBER size_t /* ray counter (>= sizeof pointer) */
20 greg 2.30 #endif
21    
22 greg 2.51 #define MAXDIM 32 /* maximum number of sampling dimensions */
23 greg 2.6
24 greg 1.1 /* ray type flags */
25     #define PRIMARY 01 /* original ray */
26 greg 2.52 #define RSHADOW 02 /* reflected ray to light source */
27 greg 1.1 #define REFLECTED 04 /* reflected ray */
28     #define REFRACTED 010 /* refracted (bent) ray */
29     #define TRANS 020 /* transmitted/transferred ray */
30 greg 2.52 #define RAMBIENT 040 /* reflected diffuse interreflection */
31     #define RSPECULAR 0100 /* reflected specular */
32     #define TSHADOW 0200 /* transmitted shadow */
33     #define TAMBIENT 0400 /* transmitted ambient */
34     #define TSPECULAR 01000 /* transmitted specular */
35     #define SHADOW (RSHADOW|TSHADOW)
36     #define AMBIENT (RAMBIENT|TAMBIENT)
37     #define SPECULAR (RSPECULAR|TSPECULAR)
38 greg 1.1
39     /* reflected ray types */
40 greg 2.52 #define RAYREFL (RSHADOW|REFLECTED|RAMBIENT|RSPECULAR)
41 greg 1.1
42 greg 2.29 /* Arrange so double's come first for optimal alignment */
43     /* Pointers and long's come second for 64-bit mode */
44     /* Int's next (unknown length), then floats, followed by short's & char's */
45 greg 1.1 typedef struct ray {
46 greg 2.12 FVECT rorg; /* origin of ray */
47     FVECT rdir; /* normalized direction of ray */
48 greg 2.29 RREAL rmax; /* maximum distance (aft clipping plane) */
49     RREAL rot; /* distance to object */
50     FVECT rop; /* intersection point */
51     FVECT ron; /* intersection surface normal */
52     RREAL rod; /* -DOT(rdir, ron) */
53     RREAL uv[2]; /* local coordinates */
54     FVECT pert; /* surface normal perturbation */
55 greg 2.39 RREAL rmt; /* returned mirrored ray length */
56     RREAL rxt; /* returned unmirrored ray length */
57 greg 2.29 const struct ray *parent; /* ray this originated from */
58 greg 2.12 OBJECT *clipset; /* set of objects currently clipped */
59     OBJECT *newcset; /* next clipset, used for transmission */
60 greg 2.26 void (*revf)(struct ray *); /* ray evaluation function */
61 greg 2.21 void (*hitf)(OBJECT *, struct ray *); /* custom hit test */
62 greg 2.12 OBJREC *ro; /* intersected object (one with material) */
63     FULLXF *rox; /* object transformation */
64 greg 2.29 int *slights; /* list of lights to test for scattering */
65 greg 2.30 RNUMBER rno; /* unique ray number */
66 greg 2.42 OBJECT robj; /* intersected object number */
67 greg 2.57 int rsrc; /* source we're aiming for (or ones to skip) */
68 greg 2.29 float rweight; /* cumulative weight (for termination) */
69 greg 2.42 float gecc; /* scattering eccentricity coefficient */
70 greg 2.51 SCOLOR rcoef; /* contribution coefficient w.r.t. parent */
71     SCOLOR pcol; /* pattern color */
72     SCOLOR mcol; /* mirrored color contribution */
73     SCOLOR rcol; /* returned radiance value */
74 greg 2.12 COLOR cext; /* medium extinction coefficient */
75     COLOR albedo; /* medium scattering albedo */
76 greg 2.42 short rflips; /* surface orientation has been reversed */
77     short rlvl; /* number of reflections for this ray */
78 greg 2.29 short rtype; /* ray type */
79     short crtype; /* cumulative ray type */
80 greg 1.1 } RAY;
81    
82 greg 2.26 #define rayvalue(r) (*(r)->revf)(r)
83    
84 greg 2.52 #define thrudir(r,v) ((r)->rod > 0 ^ DOT((r)->ron,v) > 0)
85    
86 greg 2.51 #define raydistance(r) (pbright((r)->mcol) > 0.5*pbright((r)->rcol) ? \
87 greg 2.39 (r)->rmt : (r)->rxt)
88    
89 greg 2.41 #define rayreorient(r) if ((r)->rflips & 1) flipsurface(r); else
90    
91 greg 2.47 extern char VersionID[]; /* Radiance version ID string */
92     extern char RFeatureList[]; /* newline-separated feature list */
93 greg 1.6
94 greg 2.12 extern CUBE thescene; /* our scene */
95     extern OBJECT nsceneobjs; /* number of objects in our scene */
96 greg 2.5
97 greg 2.35 extern RNUMBER raynum; /* next ray ID */
98     extern RNUMBER nrays; /* total rays traced so far */
99 greg 1.5
100 greg 2.12 extern OBJREC Lamb; /* a Lambertian surface */
101     extern OBJREC Aftplane; /* aft clipping object */
102    
103 greg 2.49 extern void (*trace)(RAY*); /* global trace reporting callback */
104 greg 2.12
105     extern int dimlist[]; /* dimension list for distribution */
106     extern int ndims; /* number of dimensions so far */
107 greg 2.59 extern unsigned long
108     samplendx; /* index for this sample */
109 greg 2.12
110     extern int do_irrad; /* compute irradiance? */
111    
112 greg 2.27 extern int rand_samp; /* pure Monte Carlo sampling? */
113    
114 greg 2.12 extern double dstrsrc; /* square source distribution */
115     extern double shadthresh; /* shadow threshold */
116     extern double shadcert; /* shadow testing certainty */
117     extern int directrelay; /* number of source relays */
118     extern int vspretest; /* virtual source pretest density */
119     extern int directvis; /* light sources visible to eye? */
120     extern double srcsizerat; /* maximum source size/dist. ratio */
121    
122     extern double specthresh; /* specular sampling threshold */
123     extern double specjitter; /* specular sampling jitter */
124    
125     extern COLOR cextinction; /* global extinction coefficient */
126     extern COLOR salbedo; /* global scattering albedo */
127     extern double seccg; /* global scattering eccentricity */
128     extern double ssampdist; /* scatter sampling distance */
129    
130     extern int backvis; /* back face visibility */
131    
132     extern int maxdepth; /* maximum recursion depth */
133     extern double minweight; /* minimum ray weight */
134    
135     extern char *ambfile; /* ambient file name */
136     extern COLOR ambval; /* ambient value */
137     extern int ambvwt; /* initial weight for ambient value */
138     extern double ambacc; /* ambient accuracy */
139     extern int ambres; /* ambient resolution */
140     extern int ambdiv; /* ambient divisions */
141     extern int ambssamp; /* ambient super-samples */
142     extern int ambounce; /* ambient bounces */
143     extern char *amblist[]; /* ambient include/exclude list */
144     extern int ambincl; /* include == 1, exclude == 0 */
145    
146     extern int ray_pnprocs; /* number of child processes */
147     extern int ray_pnidle; /* number of idle processes */
148    
149 greg 2.23 #ifndef AMBLLEN
150     #define AMBLLEN 512 /* max. ambient list length */
151     #endif
152     #define AMBWORD 12 /* average word length */
153 greg 2.12
154     typedef struct { /* rendering parameter holder */
155     int do_irrad;
156 greg 2.27 int rand_samp;
157 greg 2.12 double dstrsrc;
158     double shadthresh;
159     double shadcert;
160     int directrelay;
161     int vspretest;
162     int directvis;
163     double srcsizerat;
164     COLOR cextinction;
165     COLOR salbedo;
166     double seccg;
167     double ssampdist;
168     double specthresh;
169     double specjitter;
170     int backvis;
171     int maxdepth;
172     double minweight;
173     char ambfile[512];
174     COLOR ambval;
175     int ambvwt;
176     double ambacc;
177     int ambres;
178     int ambdiv;
179     int ambssamp;
180     int ambounce;
181     int ambincl;
182     short amblndx[AMBLLEN+1];
183     char amblval[AMBLLEN*AMBWORD];
184 greg 2.38
185     /* PMAP: photon mapping parameters */
186     PhotonMapParams pmapParams [NUM_PMAP_TYPES];
187 greg 2.12 } RAYPARAMS;
188    
189     #define rpambmod(p,i) ( (i)>=AMBLLEN||(p)->amblndx[i]<0 ? \
190     (char *)NULL : (p)->amblval+(p)->amblndx[i] )
191    
192     /* defined in duphead.c */
193     extern void headclean(void);
194     extern void openheader(void);
195     extern void dupheader(void);
196 schorsch 2.22 /* defined in persist.c */
197 greg 2.46 extern void persistfile(char *pfn);
198 greg 2.12 extern void pfdetach(void);
199     extern void pfclean(void);
200     extern void pflock(int lf);
201     extern void pfhold(void);
202     extern void io_process(void);
203     /* defined in freeobjmem.c */
204     extern int free_objs(OBJECT on, OBJECT no);
205     extern void free_objmem(void);
206     /* defined in preload.c */
207     extern int load_os(OBJREC *op);
208     extern void preload_objs(void);
209 greg 2.56 extern char *shm_boundary;
210     extern void cow_memshare(void);
211     extern void cow_doneshare(void);
212 greg 2.12 /* defined in raycalls.c */
213     extern void ray_init(char *otnm);
214     extern void ray_trace(RAY *r);
215     extern void ray_done(int freall);
216     extern void ray_save(RAYPARAMS *rp);
217     extern void ray_restore(RAYPARAMS *rp);
218     extern void ray_defaults(RAYPARAMS *rp);
219 greg 2.59 extern void reset_random(void);
220 greg 2.12 /* defined in raypcalls.c */
221     extern void ray_pinit(char *otnm, int nproc);
222 greg 2.33 extern int ray_psend(RAY *r);
223 greg 2.12 extern int ray_pqueue(RAY *r);
224     extern int ray_presult(RAY *r, int poll);
225     extern void ray_pdone(int freall);
226     extern void ray_popen(int nadd);
227     extern void ray_pclose(int nsub);
228 greg 2.31 /* defined in ray_fifo.c */
229     extern int (*ray_fifo_out)(RAY *r);
230     extern int ray_fifo_in(RAY *r);
231     extern int ray_fifo_flush(void);
232 greg 2.12 /* defined in raytrace.c */
233 greg 2.51 extern int rayorigin(RAY *r, int rt, const RAY *ro, const SCOLOR rc);
234 greg 2.12 extern void rayclear(RAY *r);
235 greg 2.26 extern void raytrace(RAY *r);
236 greg 2.50 extern int rayreject(OBJREC *o, RAY *r, double t, double rod);
237 greg 2.14 extern void rayhit(OBJECT *oset, RAY *r);
238 greg 2.12 extern void raycont(RAY *r);
239     extern void raytrans(RAY *r);
240 greg 2.40 extern int raytirrad(OBJREC *m, RAY *r);
241 greg 2.12 extern int rayshade(RAY *r, int mod);
242     extern void rayparticipate(RAY *r);
243 greg 2.16 extern void raytexture(RAY *r, OBJECT mod);
244 greg 2.12 extern int raymixture(RAY *r, OBJECT fore, OBJECT back, double coef);
245 greg 2.51 extern void raycontrib(SCOLOR rc, const RAY *r, int flags);
246 greg 2.25 extern double raydist(const RAY *r, int flags);
247 greg 2.12 extern double raynormal(FVECT norm, RAY *r);
248     extern void newrayxf(RAY *r);
249     extern void flipsurface(RAY *r);
250     extern int localhit(RAY *r, CUBE *scene);
251     /* defined in renderopts.c */
252 greg 2.47 extern int feature_status(int ac, char *av[]);
253 greg 2.12 extern int getrenderopt(int ac, char *av[]);
254     extern void print_rdefaults(void);
255     /* defined in srcdraw.c */
256 greg 2.55 extern void init_drawsources(int rad);
257     extern void drawsources(COLORV *pic[], RGBPRIMP primp, float *zbf[],
258 greg 2.12 int x0, int xsiz, int y0, int ysiz);
259 schorsch 2.22 /* defined in rt/initotypes.c */
260 greg 2.46 extern void initotypes(void);
261 greg 2.12 /* module main procedures */
262 greg 2.32 extern void rtrace(char *fname, int nproc);
263 greg 2.49 extern const char *formstr(int f);
264 greg 2.12 extern void rview(void);
265     extern void rpict(int seq, char *pout, char *zout, char *prvr);
266 greg 1.6
267 greg 2.34 #ifdef __FAST_MATH__
268 greg 2.37 #define checknorm(vn) (void)normalize(vn)
269 greg 2.34 #else
270 greg 2.37 #define checknorm(vn)
271 greg 2.34 #endif
272 schorsch 2.17
273     #ifdef __cplusplus
274     }
275 greg 2.12 #endif
276 schorsch 2.17 #endif /* _RAD_RAY_H_ */
277