2 |
|
/* |
3 |
|
* ray.h - header file for routines using rays. |
4 |
|
*/ |
5 |
+ |
#ifndef _RAD_RAY_H_ |
6 |
+ |
#define _RAD_RAY_H_ |
7 |
|
|
6 |
– |
#include "copyright.h" |
7 |
– |
|
8 |
|
#include "standard.h" |
9 |
– |
|
9 |
|
#include "octree.h" |
11 |
– |
|
10 |
|
#include "object.h" |
13 |
– |
|
11 |
|
#include "color.h" |
12 |
+ |
#include "pmapparm.h" |
13 |
|
|
14 |
< |
#define MAXDIM 32 /* maximum number of dimensions */ |
14 |
> |
#ifdef __cplusplus |
15 |
> |
extern "C" { |
16 |
> |
#endif |
17 |
|
|
18 |
+ |
#ifndef RNUMBER |
19 |
+ |
#define RNUMBER size_t /* ray counter (>= sizeof pointer) */ |
20 |
+ |
#endif |
21 |
+ |
|
22 |
+ |
#define MAXDIM 32 /* maximum number of sampling dimensions */ |
23 |
+ |
|
24 |
|
/* ray type flags */ |
25 |
|
#define PRIMARY 01 /* original ray */ |
26 |
< |
#define SHADOW 02 /* ray to light source */ |
26 |
> |
#define RSHADOW 02 /* reflected ray to light source */ |
27 |
|
#define REFLECTED 04 /* reflected ray */ |
28 |
|
#define REFRACTED 010 /* refracted (bent) ray */ |
29 |
|
#define TRANS 020 /* transmitted/transferred ray */ |
30 |
< |
#define AMBIENT 040 /* ray scattered for interreflection */ |
31 |
< |
#define SPECULAR 0100 /* ray scattered for specular */ |
30 |
> |
#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 |
|
|
39 |
|
/* reflected ray types */ |
40 |
< |
#define RAYREFL (SHADOW|REFLECTED|AMBIENT|SPECULAR) |
40 |
> |
#define RAYREFL (RSHADOW|REFLECTED|RAMBIENT|RSPECULAR) |
41 |
|
|
42 |
+ |
/* 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 |
|
typedef struct ray { |
31 |
– |
unsigned long rno; /* unique ray number */ |
32 |
– |
int rlvl; /* number of reflections for this ray */ |
33 |
– |
float rweight; /* cumulative weight of this ray */ |
34 |
– |
short rtype; /* ray type */ |
35 |
– |
short crtype; /* cumulative ray type */ |
36 |
– |
struct ray *parent; /* ray this originated from */ |
46 |
|
FVECT rorg; /* origin of ray */ |
47 |
|
FVECT rdir; /* normalized direction of ray */ |
48 |
< |
double rmax; /* maximum distance (aft clipping plane) */ |
49 |
< |
int rsrc; /* source we're aiming for */ |
48 |
> |
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 |
> |
RREAL rmt; /* returned mirrored ray length */ |
56 |
> |
RREAL rxt; /* returned unmirrored ray length */ |
57 |
> |
const struct ray *parent; /* ray this originated from */ |
58 |
|
OBJECT *clipset; /* set of objects currently clipped */ |
59 |
|
OBJECT *newcset; /* next clipset, used for transmission */ |
60 |
< |
void (*revf)(); /* evaluation function for this ray */ |
61 |
< |
void (*hitf)(); /* custom hit test for this traversal */ |
45 |
< |
OBJECT robj; /* intersected object number */ |
60 |
> |
void (*revf)(struct ray *); /* ray evaluation function */ |
61 |
> |
void (*hitf)(OBJECT *, struct ray *); /* custom hit test */ |
62 |
|
OBJREC *ro; /* intersected object (one with material) */ |
47 |
– |
double rot; /* distance to object */ |
48 |
– |
FVECT rop; /* intersection point */ |
49 |
– |
FVECT ron; /* intersection surface normal */ |
50 |
– |
double rod; /* -DOT(rdir, ron) */ |
63 |
|
FULLXF *rox; /* object transformation */ |
64 |
< |
FLOAT uv[2]; /* local coordinates */ |
65 |
< |
FVECT pert; /* surface normal perturbation */ |
66 |
< |
COLOR pcol; /* pattern color */ |
67 |
< |
COLOR rcol; /* returned ray value */ |
68 |
< |
double rt; /* returned effective ray length */ |
64 |
> |
int *slights; /* list of lights to test for scattering */ |
65 |
> |
RNUMBER rno; /* unique ray number */ |
66 |
> |
OBJECT robj; /* intersected object number */ |
67 |
> |
int rsrc; /* source we're aiming for */ |
68 |
> |
float rweight; /* cumulative weight (for termination) */ |
69 |
> |
float gecc; /* scattering eccentricity coefficient */ |
70 |
> |
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 |
|
COLOR cext; /* medium extinction coefficient */ |
75 |
|
COLOR albedo; /* medium scattering albedo */ |
76 |
< |
float gecc; /* scattering eccentricity coefficient */ |
77 |
< |
int *slights; /* list of lights to test for scattering */ |
76 |
> |
short rflips; /* surface orientation has been reversed */ |
77 |
> |
short rlvl; /* number of reflections for this ray */ |
78 |
> |
short rtype; /* ray type */ |
79 |
> |
short crtype; /* cumulative ray type */ |
80 |
|
} RAY; |
81 |
|
|
82 |
|
#define rayvalue(r) (*(r)->revf)(r) |
83 |
|
|
84 |
< |
extern char VersionID[]; /* Radiance version ID string */ |
84 |
> |
#define thrudir(r,v) ((r)->rod > 0 ^ DOT((r)->ron,v) > 0) |
85 |
|
|
86 |
+ |
#define raydistance(r) (pbright((r)->mcol) > 0.5*pbright((r)->rcol) ? \ |
87 |
+ |
(r)->rmt : (r)->rxt) |
88 |
+ |
|
89 |
+ |
#define rayreorient(r) if ((r)->rflips & 1) flipsurface(r); else |
90 |
+ |
|
91 |
+ |
extern char VersionID[]; /* Radiance version ID string */ |
92 |
+ |
extern char RFeatureList[]; /* newline-separated feature list */ |
93 |
+ |
|
94 |
|
extern CUBE thescene; /* our scene */ |
95 |
|
extern OBJECT nsceneobjs; /* number of objects in our scene */ |
96 |
|
|
97 |
< |
extern unsigned long raynum; /* next ray ID */ |
98 |
< |
extern unsigned long nrays; /* total rays traced so far */ |
97 |
> |
extern RNUMBER raynum; /* next ray ID */ |
98 |
> |
extern RNUMBER nrays; /* total rays traced so far */ |
99 |
|
|
100 |
|
extern OBJREC Lamb; /* a Lambertian surface */ |
101 |
|
extern OBJREC Aftplane; /* aft clipping object */ |
102 |
|
|
103 |
< |
extern void (*trace)(); /* global trace reporting callback */ |
103 |
> |
extern void (*trace)(RAY*); /* global trace reporting callback */ |
104 |
|
|
105 |
|
extern int dimlist[]; /* dimension list for distribution */ |
106 |
|
extern int ndims; /* number of dimensions so far */ |
107 |
|
extern int samplendx; /* index for this sample */ |
108 |
|
|
82 |
– |
extern int ray_savesiz; /* size of parameter save buffer */ |
83 |
– |
|
109 |
|
extern int do_irrad; /* compute irradiance? */ |
110 |
|
|
111 |
+ |
extern int rand_samp; /* pure Monte Carlo sampling? */ |
112 |
+ |
|
113 |
|
extern double dstrsrc; /* square source distribution */ |
114 |
|
extern double shadthresh; /* shadow threshold */ |
115 |
|
extern double shadcert; /* shadow testing certainty */ |
145 |
|
extern int ray_pnprocs; /* number of child processes */ |
146 |
|
extern int ray_pnidle; /* number of idle processes */ |
147 |
|
|
148 |
< |
#define AMBLLEN 128 /* max. ambient list length */ |
149 |
< |
#define AMBWORD 8 /* average word length */ |
148 |
> |
#ifndef AMBLLEN |
149 |
> |
#define AMBLLEN 512 /* max. ambient list length */ |
150 |
> |
#endif |
151 |
> |
#define AMBWORD 12 /* average word length */ |
152 |
|
|
153 |
|
typedef struct { /* rendering parameter holder */ |
154 |
|
int do_irrad; |
155 |
+ |
int rand_samp; |
156 |
|
double dstrsrc; |
157 |
|
double shadthresh; |
158 |
|
double shadcert; |
180 |
|
int ambincl; |
181 |
|
short amblndx[AMBLLEN+1]; |
182 |
|
char amblval[AMBLLEN*AMBWORD]; |
183 |
+ |
|
184 |
+ |
/* PMAP: photon mapping parameters */ |
185 |
+ |
PhotonMapParams pmapParams [NUM_PMAP_TYPES]; |
186 |
|
} RAYPARAMS; |
187 |
|
|
188 |
|
#define rpambmod(p,i) ( (i)>=AMBLLEN||(p)->amblndx[i]<0 ? \ |
189 |
|
(char *)NULL : (p)->amblval+(p)->amblndx[i] ) |
190 |
|
|
158 |
– |
#ifdef NOPROTO |
159 |
– |
|
160 |
– |
extern void headclean(); |
161 |
– |
extern void openheader(); |
162 |
– |
extern void dupheader(); |
163 |
– |
extern void pfdetach(); |
164 |
– |
extern void pfclean(); |
165 |
– |
extern void pflock(); |
166 |
– |
extern void pfhold(); |
167 |
– |
extern void io_process(); |
168 |
– |
extern int free_objs(); |
169 |
– |
extern void free_objmem(); |
170 |
– |
extern int load_os(); |
171 |
– |
extern void preload_objs(); |
172 |
– |
extern void ray_init(); |
173 |
– |
extern void ray_trace(); |
174 |
– |
extern void ray_done(); |
175 |
– |
extern void ray_save(); |
176 |
– |
extern void ray_restore(); |
177 |
– |
extern void ray_defaults(); |
178 |
– |
extern void ray_pinit(); |
179 |
– |
extern void ray_psend(); |
180 |
– |
extern int ray_pqueue(); |
181 |
– |
extern int ray_presult(); |
182 |
– |
extern void ray_pdone(); |
183 |
– |
extern void ray_popen(); |
184 |
– |
extern void ray_pclose(); |
185 |
– |
extern int rayorigin(); |
186 |
– |
extern void rayclear(); |
187 |
– |
extern void raytrace(); |
188 |
– |
extern void rayhit(); |
189 |
– |
extern void raycont(); |
190 |
– |
extern void raytrans(); |
191 |
– |
extern int rayshade(); |
192 |
– |
extern void rayparticipate(); |
193 |
– |
extern void raytexture(); |
194 |
– |
extern int raymixture(); |
195 |
– |
extern double raydist(); |
196 |
– |
extern double raynormal(); |
197 |
– |
extern void newrayxf(); |
198 |
– |
extern void flipsurface(); |
199 |
– |
extern int localhit(); |
200 |
– |
extern int getrenderopt(); |
201 |
– |
extern void print_rdefaults(); |
202 |
– |
extern void drawsources(); |
203 |
– |
extern void rtrace(); |
204 |
– |
extern void rview(); |
205 |
– |
extern void rpict(); |
206 |
– |
|
207 |
– |
#else |
191 |
|
/* defined in duphead.c */ |
192 |
|
extern void headclean(void); |
193 |
|
extern void openheader(void); |
194 |
|
extern void dupheader(void); |
195 |
+ |
/* defined in persist.c */ |
196 |
+ |
extern void persistfile(char *pfn); |
197 |
|
extern void pfdetach(void); |
198 |
|
extern void pfclean(void); |
199 |
|
extern void pflock(int lf); |
214 |
|
extern void ray_defaults(RAYPARAMS *rp); |
215 |
|
/* defined in raypcalls.c */ |
216 |
|
extern void ray_pinit(char *otnm, int nproc); |
217 |
< |
extern void ray_psend(RAY *r); |
217 |
> |
extern int ray_psend(RAY *r); |
218 |
|
extern int ray_pqueue(RAY *r); |
219 |
|
extern int ray_presult(RAY *r, int poll); |
220 |
|
extern void ray_pdone(int freall); |
221 |
|
extern void ray_popen(int nadd); |
222 |
|
extern void ray_pclose(int nsub); |
223 |
+ |
/* defined in ray_fifo.c */ |
224 |
+ |
extern int (*ray_fifo_out)(RAY *r); |
225 |
+ |
extern int ray_fifo_in(RAY *r); |
226 |
+ |
extern int ray_fifo_flush(void); |
227 |
|
/* defined in raytrace.c */ |
228 |
< |
extern int rayorigin(RAY *r, RAY *ro, int rt, double rw); |
228 |
> |
extern int rayorigin(RAY *r, int rt, const RAY *ro, const SCOLOR rc); |
229 |
|
extern void rayclear(RAY *r); |
230 |
|
extern void raytrace(RAY *r); |
231 |
+ |
extern int rayreject(OBJREC *o, RAY *r, double t, double rod); |
232 |
|
extern void rayhit(OBJECT *oset, RAY *r); |
233 |
|
extern void raycont(RAY *r); |
234 |
|
extern void raytrans(RAY *r); |
235 |
+ |
extern int raytirrad(OBJREC *m, RAY *r); |
236 |
|
extern int rayshade(RAY *r, int mod); |
237 |
|
extern void rayparticipate(RAY *r); |
238 |
|
extern void raytexture(RAY *r, OBJECT mod); |
239 |
|
extern int raymixture(RAY *r, OBJECT fore, OBJECT back, double coef); |
240 |
< |
extern double raydist(RAY *r, int flags); |
240 |
> |
extern void raycontrib(SCOLOR rc, const RAY *r, int flags); |
241 |
> |
extern double raydist(const RAY *r, int flags); |
242 |
|
extern double raynormal(FVECT norm, RAY *r); |
243 |
|
extern void newrayxf(RAY *r); |
244 |
|
extern void flipsurface(RAY *r); |
245 |
|
extern int localhit(RAY *r, CUBE *scene); |
246 |
|
/* defined in renderopts.c */ |
247 |
+ |
extern int feature_status(int ac, char *av[]); |
248 |
|
extern int getrenderopt(int ac, char *av[]); |
249 |
|
extern void print_rdefaults(void); |
250 |
|
/* defined in srcdraw.c */ |
251 |
< |
extern void drawsources(COLOR *pic[], float *zbf[], |
251 |
> |
extern void init_drawsources(int rad); |
252 |
> |
extern void drawsources(COLORV *pic[], RGBPRIMP primp, float *zbf[], |
253 |
|
int x0, int xsiz, int y0, int ysiz); |
254 |
+ |
/* defined in rt/initotypes.c */ |
255 |
+ |
extern void initotypes(void); |
256 |
|
/* module main procedures */ |
257 |
< |
extern void rtrace(char *fname); |
257 |
> |
extern void rtrace(char *fname, int nproc); |
258 |
> |
extern const char *formstr(int f); |
259 |
|
extern void rview(void); |
260 |
|
extern void rpict(int seq, char *pout, char *zout, char *prvr); |
261 |
|
|
262 |
+ |
#ifdef __FAST_MATH__ |
263 |
+ |
#define checknorm(vn) (void)normalize(vn) |
264 |
+ |
#else |
265 |
+ |
#define checknorm(vn) |
266 |
|
#endif |
267 |
+ |
|
268 |
+ |
#ifdef __cplusplus |
269 |
+ |
} |
270 |
+ |
#endif |
271 |
+ |
#endif /* _RAD_RAY_H_ */ |
272 |
+ |
|