Back to index

radiance  4R0+20100331
ray.h
Go to the documentation of this file.
00001 /* RCSid $Id: ray.h,v 2.33 2009/12/15 18:21:53 greg Exp $ */
00002 /*
00003  *  ray.h - header file for routines using rays.
00004  */
00005 #ifndef _RAD_RAY_H_
00006 #define _RAD_RAY_H_
00007 
00008 #include  "standard.h"
00009 #include  "octree.h"
00010 #include  "object.h"
00011 #include  "color.h"
00012 
00013 #ifdef __cplusplus
00014 extern "C" {
00015 #endif
00016 
00017 #ifndef RNUMBER
00018 #define RNUMBER             unsigned long /* ray counter (>= sizeof pointer) */
00019 #endif
00020 
00021 #define  MAXDIM             32     /* maximum number of dimensions */
00022 
00023                             /* ray type flags */
00024 #define  PRIMARY     01            /* original ray */
00025 #define  SHADOW             02            /* ray to light source */
00026 #define  REFLECTED   04            /* reflected ray */
00027 #define  REFRACTED   010           /* refracted (bent) ray */
00028 #define  TRANS              020           /* transmitted/transferred ray */
00029 #define  AMBIENT     040           /* ray scattered for interreflection */
00030 #define  SPECULAR    0100          /* ray scattered for specular */
00031 
00032                             /* reflected ray types */
00033 #define  RAYREFL     (SHADOW|REFLECTED|AMBIENT|SPECULAR)
00034 
00035 /* Arrange so double's come first for optimal alignment */
00036 /* Pointers and long's come second for 64-bit mode */
00037 /* Int's next (unknown length), then floats, followed by short's & char's */
00038 typedef struct ray {
00039        FVECT  rorg;         /* origin of ray */
00040        FVECT  rdir;         /* normalized direction of ray */
00041        RREAL  rmax;         /* maximum distance (aft clipping plane) */
00042        RREAL  rot;          /* distance to object */
00043        FVECT  rop;          /* intersection point */
00044        FVECT  ron;          /* intersection surface normal */
00045        RREAL  rod;          /* -DOT(rdir, ron) */
00046        RREAL  uv[2];        /* local coordinates */
00047        FVECT  pert;         /* surface normal perturbation */
00048        RREAL  rt;           /* returned effective ray length */
00049        const struct ray  *parent;  /* ray this originated from */
00050        OBJECT *clipset;     /* set of objects currently clipped */
00051        OBJECT *newcset;     /* next clipset, used for transmission */
00052        void   (*revf)(struct ray *);      /* ray evaluation function */
00053        void   (*hitf)(OBJECT *, struct ray *);   /* custom hit test */
00054        OBJREC *ro;          /* intersected object (one with material) */
00055        FULLXF *rox;         /* object transformation */
00056        int    *slights;     /* list of lights to test for scattering */
00057        RNUMBER       rno;          /* unique ray number */
00058        int    rlvl;         /* number of reflections for this ray */
00059        int    rsrc;         /* source we're aiming for */
00060        float  rweight;      /* cumulative weight (for termination) */
00061        COLOR  rcoef;        /* contribution coefficient w.r.t. parent */
00062        COLOR  pcol;         /* pattern color */
00063        COLOR  rcol;         /* returned radiance value */
00064        COLOR  cext;         /* medium extinction coefficient */
00065        COLOR  albedo;              /* medium scattering albedo */
00066        float  gecc;         /* scattering eccentricity coefficient */
00067        OBJECT robj;         /* intersected object number */
00068        short  rtype;        /* ray type */
00069        short  crtype;              /* cumulative ray type */
00070 }  RAY;
00071 
00072 #define  rayvalue(r) (*(r)->revf)(r)
00073 
00074 extern char  VersionID[];   /* Radiance version ID string */
00075 
00076 extern CUBE   thescene;     /* our scene */
00077 extern OBJECT nsceneobjs;   /* number of objects in our scene */
00078 
00079 extern unsigned long raynum;       /* next ray ID */
00080 extern unsigned long nrays; /* total rays traced so far */
00081 
00082 extern OBJREC  Lamb;        /* a Lambertian surface */
00083 extern OBJREC  Aftplane;    /* aft clipping object */
00084 
00085 extern void   (*trace)();   /* global trace reporting callback */
00086 
00087 extern int    dimlist[];    /* dimension list for distribution */
00088 extern int    ndims;        /* number of dimensions so far */
00089 extern int    samplendx;    /* index for this sample */
00090 
00091 extern int    ray_savesiz;  /* size of parameter save buffer */
00092 
00093 extern int    do_irrad;     /* compute irradiance? */
00094 
00095 extern int    rand_samp;    /* pure Monte Carlo sampling? */
00096 
00097 extern double dstrsrc;      /* square source distribution */
00098 extern double shadthresh;   /* shadow threshold */
00099 extern double shadcert;     /* shadow testing certainty */
00100 extern int    directrelay;  /* number of source relays */
00101 extern int    vspretest;    /* virtual source pretest density */
00102 extern int    directvis;    /* light sources visible to eye? */
00103 extern double srcsizerat;   /* maximum source size/dist. ratio */
00104 
00105 extern double specthresh;   /* specular sampling threshold */
00106 extern double specjitter;   /* specular sampling jitter */
00107 
00108 extern COLOR  cextinction;  /* global extinction coefficient */
00109 extern COLOR  salbedo;      /* global scattering albedo */
00110 extern double seccg;        /* global scattering eccentricity */
00111 extern double ssampdist;    /* scatter sampling distance */
00112 
00113 extern int    backvis;      /* back face visibility */
00114 
00115 extern int    maxdepth;     /* maximum recursion depth */
00116 extern double minweight;    /* minimum ray weight */
00117 
00118 extern char   *ambfile;     /* ambient file name */
00119 extern COLOR  ambval;              /* ambient value */
00120 extern int    ambvwt;              /* initial weight for ambient value */
00121 extern double ambacc;              /* ambient accuracy */
00122 extern int    ambres;              /* ambient resolution */
00123 extern int    ambdiv;              /* ambient divisions */
00124 extern int    ambssamp;     /* ambient super-samples */
00125 extern int    ambounce;     /* ambient bounces */
00126 extern char   *amblist[];   /* ambient include/exclude list */
00127 extern int    ambincl;      /* include == 1, exclude == 0 */
00128 
00129 extern int    ray_pnprocs;  /* number of child processes */
00130 extern int    ray_pnidle;   /* number of idle processes */
00131 
00132 #ifndef AMBLLEN
00133 #define AMBLLEN             512    /* max. ambient list length */
00134 #endif
00135 #define AMBWORD             12     /* average word length */
00136 
00137 typedef struct {            /* rendering parameter holder */
00138        int    do_irrad;
00139        int    rand_samp;
00140        double dstrsrc;
00141        double shadthresh;
00142        double shadcert;
00143        int    directrelay;
00144        int    vspretest;
00145        int    directvis;
00146        double srcsizerat;
00147        COLOR  cextinction;
00148        COLOR  salbedo;
00149        double seccg;
00150        double ssampdist;
00151        double specthresh;
00152        double specjitter;
00153        int    backvis;
00154        int    maxdepth;
00155        double minweight;
00156        char   ambfile[512];
00157        COLOR  ambval;
00158        int    ambvwt;
00159        double ambacc;
00160        int    ambres;
00161        int    ambdiv;
00162        int    ambssamp;
00163        int    ambounce;
00164        int    ambincl;
00165        short  amblndx[AMBLLEN+1];
00166        char   amblval[AMBLLEN*AMBWORD];
00167 } RAYPARAMS;
00168 
00169 #define rpambmod(p,i)       ( (i)>=AMBLLEN||(p)->amblndx[i]<0 ? \
00170                        (char *)NULL : (p)->amblval+(p)->amblndx[i] )
00171 
00172                                    /* defined in duphead.c */
00173 extern void   headclean(void);
00174 extern void   openheader(void);
00175 extern void   dupheader(void);
00176                                    /* defined in persist.c */
00177 extern void persistfile(char *pfn);
00178 extern void   pfdetach(void);
00179 extern void   pfclean(void);
00180 extern void   pflock(int lf);
00181 extern void   pfhold(void);
00182 extern void   io_process(void);
00183                                    /* defined in freeobjmem.c */
00184 extern int    free_objs(OBJECT on, OBJECT no);
00185 extern void   free_objmem(void);
00186                                    /* defined in preload.c */
00187 extern int    load_os(OBJREC *op);
00188 extern void   preload_objs(void);
00189                                    /* defined in raycalls.c */
00190 extern void   ray_init(char *otnm);
00191 extern void   ray_trace(RAY *r);
00192 extern void   ray_done(int freall);
00193 extern void   ray_save(RAYPARAMS *rp);
00194 extern void   ray_restore(RAYPARAMS *rp);
00195 extern void   ray_defaults(RAYPARAMS *rp);
00196                                    /* defined in raypcalls.c */
00197 extern void   ray_pinit(char *otnm, int nproc);
00198 extern int    ray_psend(RAY *r);
00199 extern int    ray_pqueue(RAY *r);
00200 extern int    ray_presult(RAY *r, int poll);
00201 extern void   ray_pdone(int freall);
00202 extern void   ray_popen(int nadd);
00203 extern void   ray_pclose(int nsub);
00204                                    /* defined in ray_fifo.c */
00205 extern int    (*ray_fifo_out)(RAY *r);
00206 extern int    ray_fifo_in(RAY *r);
00207 extern int    ray_fifo_flush(void);
00208                                    /* defined in raytrace.c */
00209 extern int    rayorigin(RAY *r, int rt, const RAY *ro, const COLOR rc);
00210 extern void   rayclear(RAY *r);
00211 extern void   raytrace(RAY *r);
00212 extern void   rayhit(OBJECT *oset, RAY *r);
00213 extern void   raycont(RAY *r);
00214 extern void   raytrans(RAY *r);
00215 extern int    rayshade(RAY *r, int mod);
00216 extern void   rayparticipate(RAY *r);
00217 extern void   raytexture(RAY *r, OBJECT mod);
00218 extern int    raymixture(RAY *r, OBJECT fore, OBJECT back, double coef);
00219 extern void   raycontrib(double rc[3], const RAY *r, int flags);
00220 extern double raydist(const RAY *r, int flags);
00221 extern double raynormal(FVECT norm, RAY *r);
00222 extern void   newrayxf(RAY *r);
00223 extern void   flipsurface(RAY *r);
00224 extern int    localhit(RAY *r, CUBE *scene);
00225                                    /* defined in renderopts.c */
00226 extern int    getrenderopt(int ac, char *av[]);
00227 extern void   print_rdefaults(void);
00228                                    /* defined in srcdraw.c */
00229 extern void   drawsources(COLOR *pic[], float *zbf[],
00230                      int x0, int xsiz, int y0, int ysiz);
00231 extern void init_drawsources(int rad);
00232                                    /* defined in rt/initotypes.c */
00233 extern void initotypes(void);
00234                                    /* module main procedures */
00235 extern void   rtrace(char *fname, int nproc);
00236 extern char   *formstr(int  f);
00237 extern void   rview(void);
00238 extern void   rpict(int seq, char *pout, char *zout, char *prvr);
00239 
00240 
00241 #ifdef __cplusplus
00242 }
00243 #endif
00244 #endif /* _RAD_RAY_H_ */
00245