| 1 | 
schorsch | 
2.22 | 
/* RCSid $Id: ray.h,v 2.21 2003/08/28 03:22:16 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 | 
1.1 | 
 | 
| 13 | 
schorsch | 
2.20 | 
#ifdef __cplusplus | 
| 14 | 
  | 
  | 
extern "C" { | 
| 15 | 
  | 
  | 
#endif | 
| 16 | 
greg | 
1.1 | 
 | 
| 17 | 
greg | 
2.6 | 
#define  MAXDIM         32      /* maximum number of dimensions */ | 
| 18 | 
  | 
  | 
 | 
| 19 | 
greg | 
1.1 | 
                                /* ray type flags */ | 
| 20 | 
  | 
  | 
#define  PRIMARY        01              /* original ray */ | 
| 21 | 
  | 
  | 
#define  SHADOW         02              /* ray to light source */ | 
| 22 | 
  | 
  | 
#define  REFLECTED      04              /* reflected ray */ | 
| 23 | 
  | 
  | 
#define  REFRACTED      010             /* refracted (bent) ray */ | 
| 24 | 
  | 
  | 
#define  TRANS          020             /* transmitted/transferred ray */ | 
| 25 | 
  | 
  | 
#define  AMBIENT        040             /* ray scattered for interreflection */ | 
| 26 | 
greg | 
2.2 | 
#define  SPECULAR       0100            /* ray scattered for specular */ | 
| 27 | 
greg | 
1.1 | 
 | 
| 28 | 
  | 
  | 
                                /* reflected ray types */ | 
| 29 | 
greg | 
2.2 | 
#define  RAYREFL        (SHADOW|REFLECTED|AMBIENT|SPECULAR) | 
| 30 | 
greg | 
1.1 | 
 | 
| 31 | 
  | 
  | 
typedef struct ray { | 
| 32 | 
greg | 
2.3 | 
        unsigned long  rno;     /* unique ray number */ | 
| 33 | 
greg | 
2.12 | 
        int     rlvl;           /* number of reflections for this ray */ | 
| 34 | 
  | 
  | 
        float   rweight;        /* cumulative weight of this ray */ | 
| 35 | 
  | 
  | 
        short   rtype;          /* ray type */ | 
| 36 | 
  | 
  | 
        short   crtype;         /* cumulative ray type */ | 
| 37 | 
greg | 
1.1 | 
        struct ray  *parent;    /* ray this originated from */ | 
| 38 | 
greg | 
2.12 | 
        FVECT   rorg;           /* origin of ray */ | 
| 39 | 
  | 
  | 
        FVECT   rdir;           /* normalized direction of ray */ | 
| 40 | 
  | 
  | 
        double  rmax;           /* maximum distance (aft clipping plane) */ | 
| 41 | 
  | 
  | 
        int     rsrc;           /* source we're aiming for */ | 
| 42 | 
  | 
  | 
        OBJECT  *clipset;       /* set of objects currently clipped */ | 
| 43 | 
  | 
  | 
        OBJECT  *newcset;       /* next clipset, used for transmission */ | 
| 44 | 
greg | 
2.21 | 
        void    (*revf)(struct ray *);  /* evaluation function for this ray */ | 
| 45 | 
  | 
  | 
        void    (*hitf)(OBJECT *, struct ray *);        /* custom hit test */ | 
| 46 | 
greg | 
2.11 | 
        OBJECT  robj;           /* intersected object number */ | 
| 47 | 
greg | 
2.12 | 
        OBJREC  *ro;            /* intersected object (one with material) */ | 
| 48 | 
  | 
  | 
        double  rot;            /* distance to object */ | 
| 49 | 
  | 
  | 
        FVECT   rop;            /* intersection point */ | 
| 50 | 
  | 
  | 
        FVECT   ron;            /* intersection surface normal */ | 
| 51 | 
  | 
  | 
        double  rod;            /* -DOT(rdir, ron) */ | 
| 52 | 
  | 
  | 
        FULLXF  *rox;           /* object transformation */ | 
| 53 | 
schorsch | 
2.18 | 
        RREAL   uv[2];          /* local coordinates */ | 
| 54 | 
greg | 
2.12 | 
        FVECT   pert;           /* surface normal perturbation */ | 
| 55 | 
  | 
  | 
        COLOR   pcol;           /* pattern color */ | 
| 56 | 
  | 
  | 
        COLOR   rcol;           /* returned ray value */ | 
| 57 | 
  | 
  | 
        double  rt;             /* returned effective ray length */ | 
| 58 | 
  | 
  | 
        COLOR   cext;           /* medium extinction coefficient */ | 
| 59 | 
  | 
  | 
        COLOR   albedo;         /* medium scattering albedo */ | 
| 60 | 
  | 
  | 
        float   gecc;           /* scattering eccentricity coefficient */ | 
| 61 | 
  | 
  | 
        int     *slights;       /* list of lights to test for scattering */ | 
| 62 | 
greg | 
1.1 | 
}  RAY; | 
| 63 | 
  | 
  | 
 | 
| 64 | 
greg | 
2.12 | 
#define  rayvalue(r)    (*(r)->revf)(r) | 
| 65 | 
  | 
  | 
 | 
| 66 | 
  | 
  | 
extern char  VersionID[];       /* Radiance version ID string */ | 
| 67 | 
greg | 
1.6 | 
 | 
| 68 | 
greg | 
2.12 | 
extern CUBE     thescene;       /* our scene */ | 
| 69 | 
  | 
  | 
extern OBJECT   nsceneobjs;     /* number of objects in our scene */ | 
| 70 | 
greg | 
2.5 | 
 | 
| 71 | 
greg | 
2.12 | 
extern unsigned long    raynum; /* next ray ID */ | 
| 72 | 
  | 
  | 
extern unsigned long    nrays;  /* total rays traced so far */ | 
| 73 | 
greg | 
1.5 | 
 | 
| 74 | 
greg | 
2.12 | 
extern OBJREC  Lamb;            /* a Lambertian surface */ | 
| 75 | 
  | 
  | 
extern OBJREC  Aftplane;        /* aft clipping object */ | 
| 76 | 
  | 
  | 
 | 
| 77 | 
  | 
  | 
extern void     (*trace)();     /* global trace reporting callback */ | 
| 78 | 
  | 
  | 
 | 
| 79 | 
  | 
  | 
extern int      dimlist[];      /* dimension list for distribution */ | 
| 80 | 
  | 
  | 
extern int      ndims;          /* number of dimensions so far */ | 
| 81 | 
  | 
  | 
extern int      samplendx;      /* index for this sample */ | 
| 82 | 
  | 
  | 
 | 
| 83 | 
  | 
  | 
extern int      ray_savesiz;    /* size of parameter save buffer */ | 
| 84 | 
  | 
  | 
 | 
| 85 | 
  | 
  | 
extern int      do_irrad;       /* compute irradiance? */ | 
| 86 | 
  | 
  | 
 | 
| 87 | 
  | 
  | 
extern double   dstrsrc;        /* square source distribution */ | 
| 88 | 
  | 
  | 
extern double   shadthresh;     /* shadow threshold */ | 
| 89 | 
  | 
  | 
extern double   shadcert;       /* shadow testing certainty */ | 
| 90 | 
  | 
  | 
extern int      directrelay;    /* number of source relays */ | 
| 91 | 
  | 
  | 
extern int      vspretest;      /* virtual source pretest density */ | 
| 92 | 
  | 
  | 
extern int      directvis;      /* light sources visible to eye? */ | 
| 93 | 
  | 
  | 
extern double   srcsizerat;     /* maximum source size/dist. ratio */ | 
| 94 | 
  | 
  | 
 | 
| 95 | 
  | 
  | 
extern double   specthresh;     /* specular sampling threshold */ | 
| 96 | 
  | 
  | 
extern double   specjitter;     /* specular sampling jitter */ | 
| 97 | 
  | 
  | 
 | 
| 98 | 
  | 
  | 
extern COLOR    cextinction;    /* global extinction coefficient */ | 
| 99 | 
  | 
  | 
extern COLOR    salbedo;        /* global scattering albedo */ | 
| 100 | 
  | 
  | 
extern double   seccg;          /* global scattering eccentricity */ | 
| 101 | 
  | 
  | 
extern double   ssampdist;      /* scatter sampling distance */ | 
| 102 | 
  | 
  | 
 | 
| 103 | 
  | 
  | 
extern int      backvis;        /* back face visibility */ | 
| 104 | 
  | 
  | 
 | 
| 105 | 
  | 
  | 
extern int      maxdepth;       /* maximum recursion depth */ | 
| 106 | 
  | 
  | 
extern double   minweight;      /* minimum ray weight */ | 
| 107 | 
  | 
  | 
 | 
| 108 | 
  | 
  | 
extern char     *ambfile;       /* ambient file name */ | 
| 109 | 
  | 
  | 
extern COLOR    ambval;         /* ambient value */ | 
| 110 | 
  | 
  | 
extern int      ambvwt;         /* initial weight for ambient value */ | 
| 111 | 
  | 
  | 
extern double   ambacc;         /* ambient accuracy */ | 
| 112 | 
  | 
  | 
extern int      ambres;         /* ambient resolution */ | 
| 113 | 
  | 
  | 
extern int      ambdiv;         /* ambient divisions */ | 
| 114 | 
  | 
  | 
extern int      ambssamp;       /* ambient super-samples */ | 
| 115 | 
  | 
  | 
extern int      ambounce;       /* ambient bounces */ | 
| 116 | 
  | 
  | 
extern char     *amblist[];     /* ambient include/exclude list */ | 
| 117 | 
  | 
  | 
extern int      ambincl;        /* include == 1, exclude == 0 */ | 
| 118 | 
  | 
  | 
 | 
| 119 | 
  | 
  | 
extern int      ray_pnprocs;    /* number of child processes */ | 
| 120 | 
  | 
  | 
extern int      ray_pnidle;     /* number of idle processes */ | 
| 121 | 
  | 
  | 
 | 
| 122 | 
  | 
  | 
#define AMBLLEN         128     /* max. ambient list length */ | 
| 123 | 
  | 
  | 
#define AMBWORD         8       /* average word length */ | 
| 124 | 
  | 
  | 
 | 
| 125 | 
  | 
  | 
typedef struct {                /* rendering parameter holder */ | 
| 126 | 
  | 
  | 
        int     do_irrad; | 
| 127 | 
  | 
  | 
        double  dstrsrc; | 
| 128 | 
  | 
  | 
        double  shadthresh; | 
| 129 | 
  | 
  | 
        double  shadcert; | 
| 130 | 
  | 
  | 
        int     directrelay; | 
| 131 | 
  | 
  | 
        int     vspretest; | 
| 132 | 
  | 
  | 
        int     directvis; | 
| 133 | 
  | 
  | 
        double  srcsizerat; | 
| 134 | 
  | 
  | 
        COLOR   cextinction; | 
| 135 | 
  | 
  | 
        COLOR   salbedo; | 
| 136 | 
  | 
  | 
        double  seccg; | 
| 137 | 
  | 
  | 
        double  ssampdist; | 
| 138 | 
  | 
  | 
        double  specthresh; | 
| 139 | 
  | 
  | 
        double  specjitter; | 
| 140 | 
  | 
  | 
        int     backvis; | 
| 141 | 
  | 
  | 
        int     maxdepth; | 
| 142 | 
  | 
  | 
        double  minweight; | 
| 143 | 
  | 
  | 
        char    ambfile[512]; | 
| 144 | 
  | 
  | 
        COLOR   ambval; | 
| 145 | 
  | 
  | 
        int     ambvwt; | 
| 146 | 
  | 
  | 
        double  ambacc; | 
| 147 | 
  | 
  | 
        int     ambres; | 
| 148 | 
  | 
  | 
        int     ambdiv; | 
| 149 | 
  | 
  | 
        int     ambssamp; | 
| 150 | 
  | 
  | 
        int     ambounce; | 
| 151 | 
  | 
  | 
        int     ambincl; | 
| 152 | 
  | 
  | 
        short   amblndx[AMBLLEN+1]; | 
| 153 | 
  | 
  | 
        char    amblval[AMBLLEN*AMBWORD]; | 
| 154 | 
  | 
  | 
} RAYPARAMS; | 
| 155 | 
  | 
  | 
 | 
| 156 | 
  | 
  | 
#define rpambmod(p,i)   ( (i)>=AMBLLEN||(p)->amblndx[i]<0 ? \ | 
| 157 | 
  | 
  | 
                          (char *)NULL : (p)->amblval+(p)->amblndx[i] ) | 
| 158 | 
  | 
  | 
 | 
| 159 | 
  | 
  | 
                                        /* defined in duphead.c */ | 
| 160 | 
  | 
  | 
extern void     headclean(void); | 
| 161 | 
  | 
  | 
extern void     openheader(void); | 
| 162 | 
  | 
  | 
extern void     dupheader(void); | 
| 163 | 
schorsch | 
2.22 | 
                                        /* defined in persist.c */ | 
| 164 | 
  | 
  | 
extern void persistfile(char *pfn); | 
| 165 | 
greg | 
2.12 | 
extern void     pfdetach(void); | 
| 166 | 
  | 
  | 
extern void     pfclean(void); | 
| 167 | 
  | 
  | 
extern void     pflock(int lf); | 
| 168 | 
  | 
  | 
extern void     pfhold(void); | 
| 169 | 
  | 
  | 
extern void     io_process(void); | 
| 170 | 
  | 
  | 
                                        /* defined in freeobjmem.c */ | 
| 171 | 
  | 
  | 
extern int      free_objs(OBJECT on, OBJECT no); | 
| 172 | 
  | 
  | 
extern void     free_objmem(void); | 
| 173 | 
  | 
  | 
                                        /* defined in preload.c */ | 
| 174 | 
  | 
  | 
extern int      load_os(OBJREC *op); | 
| 175 | 
  | 
  | 
extern void     preload_objs(void); | 
| 176 | 
  | 
  | 
                                        /* defined in raycalls.c */ | 
| 177 | 
  | 
  | 
extern void     ray_init(char *otnm); | 
| 178 | 
  | 
  | 
extern void     ray_trace(RAY *r); | 
| 179 | 
  | 
  | 
extern void     ray_done(int freall); | 
| 180 | 
  | 
  | 
extern void     ray_save(RAYPARAMS *rp); | 
| 181 | 
  | 
  | 
extern void     ray_restore(RAYPARAMS *rp); | 
| 182 | 
  | 
  | 
extern void     ray_defaults(RAYPARAMS *rp); | 
| 183 | 
  | 
  | 
                                        /* defined in raypcalls.c */ | 
| 184 | 
  | 
  | 
extern void     ray_pinit(char *otnm, int nproc); | 
| 185 | 
  | 
  | 
extern void     ray_psend(RAY *r); | 
| 186 | 
  | 
  | 
extern int      ray_pqueue(RAY *r); | 
| 187 | 
  | 
  | 
extern int      ray_presult(RAY *r, int poll); | 
| 188 | 
  | 
  | 
extern void     ray_pdone(int freall); | 
| 189 | 
  | 
  | 
extern void     ray_popen(int nadd); | 
| 190 | 
  | 
  | 
extern void     ray_pclose(int nsub); | 
| 191 | 
  | 
  | 
                                        /* defined in raytrace.c */ | 
| 192 | 
  | 
  | 
extern int      rayorigin(RAY *r, RAY *ro, int rt, double rw); | 
| 193 | 
  | 
  | 
extern void     rayclear(RAY *r); | 
| 194 | 
  | 
  | 
extern void     raytrace(RAY *r); | 
| 195 | 
greg | 
2.14 | 
extern void     rayhit(OBJECT *oset, RAY *r); | 
| 196 | 
greg | 
2.12 | 
extern void     raycont(RAY *r); | 
| 197 | 
  | 
  | 
extern void     raytrans(RAY *r); | 
| 198 | 
  | 
  | 
extern int      rayshade(RAY *r, int mod); | 
| 199 | 
  | 
  | 
extern void     rayparticipate(RAY *r); | 
| 200 | 
greg | 
2.16 | 
extern void     raytexture(RAY *r, OBJECT mod); | 
| 201 | 
greg | 
2.12 | 
extern int      raymixture(RAY *r, OBJECT fore, OBJECT back, double coef); | 
| 202 | 
  | 
  | 
extern double   raydist(RAY *r, int flags); | 
| 203 | 
  | 
  | 
extern double   raynormal(FVECT norm, RAY *r); | 
| 204 | 
  | 
  | 
extern void     newrayxf(RAY *r); | 
| 205 | 
  | 
  | 
extern void     flipsurface(RAY *r); | 
| 206 | 
  | 
  | 
extern int      localhit(RAY *r, CUBE *scene); | 
| 207 | 
  | 
  | 
                                        /* defined in renderopts.c */ | 
| 208 | 
  | 
  | 
extern int      getrenderopt(int ac, char *av[]); | 
| 209 | 
  | 
  | 
extern void     print_rdefaults(void); | 
| 210 | 
  | 
  | 
                                        /* defined in srcdraw.c */ | 
| 211 | 
  | 
  | 
extern void     drawsources(COLOR *pic[], float *zbf[], | 
| 212 | 
  | 
  | 
                        int x0, int xsiz, int y0, int ysiz); | 
| 213 | 
schorsch | 
2.22 | 
extern void init_drawsources(int rad); | 
| 214 | 
  | 
  | 
                                        /* defined in rt/initotypes.c */ | 
| 215 | 
  | 
  | 
extern void initotypes(void); | 
| 216 | 
greg | 
2.12 | 
                                        /* module main procedures */ | 
| 217 | 
  | 
  | 
extern void     rtrace(char *fname); | 
| 218 | 
schorsch | 
2.22 | 
extern char * formstr(int  f); | 
| 219 | 
greg | 
2.12 | 
extern void     rview(void); | 
| 220 | 
  | 
  | 
extern void     rpict(int seq, char *pout, char *zout, char *prvr); | 
| 221 | 
greg | 
1.6 | 
 | 
| 222 | 
schorsch | 
2.17 | 
 | 
| 223 | 
  | 
  | 
#ifdef __cplusplus | 
| 224 | 
  | 
  | 
} | 
| 225 | 
greg | 
2.12 | 
#endif | 
| 226 | 
schorsch | 
2.17 | 
#endif /* _RAD_RAY_H_ */ | 
| 227 | 
  | 
  | 
 |