| 1 | greg | 1.1 | /* Copyright (c) 1986 Regents of the University of California */ | 
| 2 |  |  |  | 
| 3 |  |  | /* SCCSid "$SunId$ LBL" */ | 
| 4 |  |  |  | 
| 5 |  |  | /* | 
| 6 |  |  | *  source.h - header file for ray tracing sources. | 
| 7 |  |  | * | 
| 8 |  |  | *     8/20/85 | 
| 9 |  |  | */ | 
| 10 |  |  |  | 
| 11 | greg | 1.6 | #define  AIMREQT        100             /* required aim success/failure */ | 
| 12 |  |  |  | 
| 13 | greg | 1.1 | #define  SDISTANT       01              /* source distant flag */ | 
| 14 |  |  | #define  SSKIP          02              /* source skip flag */ | 
| 15 | greg | 1.3 | #define  SPROX          04              /* source proximity flag */ | 
| 16 |  |  | #define  SSPOT          010             /* source spotlight flag */ | 
| 17 | greg | 1.6 | #define  SVIRTUAL       020             /* source virtual flag */ | 
| 18 |  |  | #define  SFLAT          040             /* source flat flag */ | 
| 19 | greg | 1.14 | #define  SCYL           0100            /* source cylindrical flag */ | 
| 20 |  |  | #define  SFOLLOW        0200            /* source follow path flag */ | 
| 21 | greg | 1.1 |  | 
| 22 |  |  | typedef struct { | 
| 23 | greg | 1.6 | FVECT  aim;             /* aim direction or center */ | 
| 24 |  |  | float  siz;             /* output solid angle or area */ | 
| 25 | greg | 1.3 | float  flen;            /* focal length */ | 
| 26 |  |  | } SPOT;                 /* spotlight */ | 
| 27 |  |  |  | 
| 28 |  |  | typedef struct { | 
| 29 | greg | 1.6 | int  sflags;            /* source flags */ | 
| 30 | greg | 1.1 | FVECT  sloc;            /* direction or position of source */ | 
| 31 | greg | 1.14 | FVECT  ss[3];           /* source dimension vectors, U, V, and W */ | 
| 32 |  |  | float  srad;            /* maximum source radius */ | 
| 33 |  |  | float  ss2;             /* solid angle or projected area */ | 
| 34 | greg | 1.6 | struct { | 
| 35 | greg | 1.3 | float  prox;            /* proximity */ | 
| 36 |  |  | SPOT  *s;               /* spot */ | 
| 37 |  |  | } sl;                   /* localized source information */ | 
| 38 | greg | 1.6 | union { | 
| 39 |  |  | int  success;           /* successes - AIMREQT*failures */ | 
| 40 | greg | 1.12 | struct { | 
| 41 |  |  | short  pn;              /* projection number */ | 
| 42 |  |  | short  sn;              /* next source to aim for */ | 
| 43 |  |  | }  sv;                  /* virtual source */ | 
| 44 | greg | 1.6 | } sa;                   /* source aiming information */ | 
| 45 | greg | 1.2 | long  ntests, nhits;    /* shadow tests and hits */ | 
| 46 | greg | 1.6 | OBJREC  *so;            /* source destination object */ | 
| 47 | greg | 1.2 | }  SRCREC;              /* light source */ | 
| 48 | greg | 1.1 |  | 
| 49 | greg | 1.15 | #define MAXSPART        64              /* maximum partitions per source */ | 
| 50 | greg | 1.14 |  | 
| 51 |  |  | #define SU              0               /* U vector or partition */ | 
| 52 |  |  | #define SV              1               /* V vector or partition */ | 
| 53 |  |  | #define SW              2               /* W vector or partition */ | 
| 54 |  |  | #define S0              3               /* leaf partition */ | 
| 55 |  |  |  | 
| 56 |  |  | #define snorm           ss[SW]          /* normal vector for flat source */ | 
| 57 |  |  |  | 
| 58 |  |  | typedef struct { | 
| 59 |  |  | int  sn;                                /* source number */ | 
| 60 |  |  | short  np;                              /* number of partitions */ | 
| 61 |  |  | short  sp;                              /* this partition number */ | 
| 62 |  |  | double  dom;                            /* solid angle of partition */ | 
| 63 |  |  | unsigned char  spt[MAXSPART/2];         /* source partitioning */ | 
| 64 |  |  | }  SRCINDEX;            /* source index structure */ | 
| 65 |  |  |  | 
| 66 |  |  | #define initsrcindex(s) ((s)->sn = (s)->sp = -1, (s)->np = 0) | 
| 67 |  |  |  | 
| 68 |  |  | #define clrpart(pt)     bzero((char *)(pt), MAXSPART/2) | 
| 69 |  |  | #define setpart(pt,i,v) ((pt)[(i)>>2] |= (v)<<(((i)&3)<<1)) | 
| 70 |  |  | #define spart(pt,pi)    ((pt)[(pi)>>2] >> (((pi)&3)<<1) & 3) | 
| 71 |  |  |  | 
| 72 | greg | 1.8 | /* | 
| 73 |  |  | * Special support functions for sources | 
| 74 |  |  | */ | 
| 75 |  |  |  | 
| 76 |  |  | /* | 
| 77 | greg | 1.10 | * Virtual source materials must define the following. | 
| 78 | greg | 1.8 | * | 
| 79 |  |  | *      vproj(pm, op, sp, i)    Compute i'th virtual projection | 
| 80 |  |  | *                              of source sp in object op and assign | 
| 81 |  |  | *                              the 4x4 transformation matrix pm. | 
| 82 |  |  | *                              Return 1 on success, 0 if no i'th projection. | 
| 83 |  |  | * | 
| 84 |  |  | *      nproj                   The number of projections.  The value of | 
| 85 |  |  | *                              i passed to vproj runs from 0 to nproj-1. | 
| 86 |  |  | */ | 
| 87 |  |  |  | 
| 88 | greg | 1.2 | typedef struct { | 
| 89 | greg | 1.8 | int  (*vproj)();        /* project virtual sources */ | 
| 90 |  |  | int  nproj;             /* number of possible projections */ | 
| 91 |  |  | } VSMATERIAL;           /* virtual source material functions */ | 
| 92 | greg | 1.4 |  | 
| 93 |  |  | typedef struct { | 
| 94 | greg | 1.8 | int     (*setsrc)();    /* set light source for object */ | 
| 95 | greg | 1.14 | int     (*partit)();    /* partition light source object */ | 
| 96 | greg | 1.8 | double  (*getpleq)();   /* plane equation for surface */ | 
| 97 |  |  | double  (*getdisk)();   /* maximum disk for surface */ | 
| 98 |  |  | } SOBJECT;              /* source object functions */ | 
| 99 | greg | 1.1 |  | 
| 100 | greg | 1.8 | typedef union { | 
| 101 |  |  | VSMATERIAL  *mf;        /* material functions */ | 
| 102 |  |  | SOBJECT  *of;           /* object functions */ | 
| 103 |  |  | } SRCFUNC;              /* source functions */ | 
| 104 |  |  |  | 
| 105 |  |  | extern SRCFUNC  sfun[];                 /* source dispatch table */ | 
| 106 |  |  |  | 
| 107 | greg | 1.2 | extern SRCREC  *source;                 /* our source list */ | 
| 108 | greg | 1.1 | extern int  nsources;                   /* the number of sources */ | 
| 109 |  |  |  | 
| 110 | greg | 1.10 | extern int  srcvalue();                 /* compute source value w/o shadows */ | 
| 111 | greg | 1.14 | extern double  nextssamp();             /* get next source sample location */ | 
| 112 |  |  | extern double  scylform();              /* cosine to axis of cylinder */ | 
| 113 | greg | 1.3 |  | 
| 114 | greg | 1.14 | #define  sflatform(sn,dir)      -DOT(source[sn].snorm, dir) | 
| 115 |  |  |  | 
| 116 | greg | 1.16 | extern OBJREC  *vsmaterial();           /* virtual source material */ | 
| 117 |  |  |  | 
| 118 | greg | 1.10 | extern double  intercircle();           /* intersect two circles */ | 
| 119 | greg | 1.11 | extern double  spotdisk();              /* intersecting disk for spot */ | 
| 120 |  |  | extern double  beamdisk();              /* intersecting disk for beam */ | 
| 121 | greg | 1.10 |  | 
| 122 | greg | 1.3 | extern SPOT  *makespot();               /* make spotlight */ | 
| 123 | greg | 1.6 |  | 
| 124 | greg | 1.8 | extern double  dstrsrc;                 /* source distribution amount */ | 
| 125 |  |  | extern double  shadthresh;              /* relative shadow threshold */ | 
| 126 |  |  | extern double  shadcert;                /* shadow testing certainty */ | 
| 127 | greg | 1.14 | extern double  srcsizerat;              /* max. ratio of source size/dist. */ | 
| 128 | greg | 1.8 | extern int  directrelay;                /* maximum number of source relays */ | 
| 129 | greg | 1.10 | extern int  vspretest;                  /* virtual source pretest density */ | 
| 130 | greg | 2.2 | extern int  directvis;                  /* sources visible? */ | 
| 131 | greg | 1.11 |  | 
| 132 |  |  | #define  getplaneq(c,o)         (*sfun[(o)->otype].of->getpleq)(c,o) | 
| 133 |  |  | #define  getmaxdisk(c,o)        (*sfun[(o)->otype].of->getdisk)(c,o) | 
| 134 |  |  | #define  setsource(s,o)         (*sfun[(o)->otype].of->setsrc)(s,o) |