--- ray/src/rt/source.h 1991/10/21 12:58:14 1.14 +++ ray/src/rt/source.h 2004/03/30 16:13:01 2.13 @@ -1,14 +1,24 @@ -/* Copyright (c) 1986 Regents of the University of California */ - -/* SCCSid "$SunId$ LBL" */ - +/* RCSid $Id: source.h,v 2.13 2004/03/30 16:13:01 schorsch Exp $ */ /* * source.h - header file for ray tracing sources. * - * 8/20/85 + * Include after ray.h */ +#ifndef _RAD_SOURCE_H_ +#define _RAD_SOURCE_H_ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef AIMREQT #define AIMREQT 100 /* required aim success/failure */ +#endif +#ifndef SHADCACHE +#define SHADCACHE 20 /* shadow cache resolution */ +#endif #define SDISTANT 01 /* source distant flag */ #define SSKIP 02 /* source skip flag */ @@ -22,31 +32,49 @@ typedef struct { FVECT aim; /* aim direction or center */ float siz; /* output solid angle or area */ - float flen; /* focal length */ + float flen; /* focal length (negative if distant source) */ } SPOT; /* spotlight */ typedef struct { + union { + struct { + FVECT u, v; /* unit vectors */ + } f; /* flat source indexing */ + struct { + FVECT o; /* origin position */ + RREAL e1, e2; /* 1/extent */ + int ax; /* major direction */ + } d; /* distant source indexing */ + } p; /* indexing parameters */ + OBJECT obs[1]; /* cache obstructors (extends struct) */ +} OBSCACHE; /* obstructor cache */ + +typedef struct { int sflags; /* source flags */ FVECT sloc; /* direction or position of source */ FVECT ss[3]; /* source dimension vectors, U, V, and W */ float srad; /* maximum source radius */ float ss2; /* solid angle or projected area */ + OBJREC *so; /* source destination object */ struct { float prox; /* proximity */ SPOT *s; /* spot */ } sl; /* localized source information */ union { - int success; /* successes - AIMREQT*failures */ + long success; /* successes - AIMREQT*failures */ struct { short pn; /* projection number */ - short sn; /* next source to aim for */ + int sn; /* next source to aim for */ } sv; /* virtual source */ } sa; /* source aiming information */ - long ntests, nhits; /* shadow tests and hits */ - OBJREC *so; /* source destination object */ + unsigned long + ntests, nhits; /* shadow tests and hits */ +#ifdef SHADCACHE + OBSCACHE *obscache; /* obstructor cache */ +#endif } SRCREC; /* light source */ -#define MAXSPART 32 /* maximum partitions per source */ +#define MAXSPART 64 /* maximum partitions per source */ #define SU 0 /* U vector or partition */ #define SV 1 /* V vector or partition */ @@ -65,7 +93,7 @@ typedef struct { #define initsrcindex(s) ((s)->sn = (s)->sp = -1, (s)->np = 0) -#define clrpart(pt) bzero((char *)(pt), MAXSPART/2) +#define clrpart(pt) memset((char *)(pt), '\0', MAXSPART/2) #define setpart(pt,i,v) ((pt)[(i)>>2] |= (v)<<(((i)&3)<<1)) #define spart(pt,pi) ((pt)[(pi)>>2] >> (((pi)&3)<<1) & 3) @@ -91,8 +119,8 @@ typedef struct { } VSMATERIAL; /* virtual source material functions */ typedef struct { - int (*setsrc)(); /* set light source for object */ - int (*partit)(); /* partition light source object */ + void (*setsrc)(); /* set light source for object */ + void (*partit)(); /* partition light source object */ double (*getpleq)(); /* plane equation for surface */ double (*getdisk)(); /* maximum disk for surface */ } SOBJECT; /* source object functions */ @@ -107,26 +135,68 @@ extern SRCFUNC sfun[]; /* source dispatch table */ extern SRCREC *source; /* our source list */ extern int nsources; /* the number of sources */ -extern int srcvalue(); /* compute source value w/o shadows */ -extern double nextssamp(); /* get next source sample location */ -extern double scylform(); /* cosine to axis of cylinder */ - #define sflatform(sn,dir) -DOT(source[sn].snorm, dir) -extern double intercircle(); /* intersect two circles */ -extern double spotdisk(); /* intersecting disk for spot */ -extern double beamdisk(); /* intersecting disk for beam */ - -extern SPOT *makespot(); /* make spotlight */ - -extern double dstrsrc; /* source distribution amount */ -extern double shadthresh; /* relative shadow threshold */ -extern double shadcert; /* shadow testing certainty */ -extern double srcsizerat; /* max. ratio of source size/dist. */ -extern int directrelay; /* maximum number of source relays */ -extern int vspretest; /* virtual source pretest density */ -extern int directinvis; /* sources invisible? */ - #define getplaneq(c,o) (*sfun[(o)->otype].of->getpleq)(c,o) #define getmaxdisk(c,o) (*sfun[(o)->otype].of->getdisk)(c,o) #define setsource(s,o) (*sfun[(o)->otype].of->setsrc)(s,o) + + /* defined in source.c */ +extern OBJREC *findmaterial(OBJREC *o); +extern void marksources(void); +extern void freesources(void); +extern int srcray(RAY *sr, RAY *r, SRCINDEX *si); +extern void srcvalue(RAY *r); +extern int sourcehit(RAY *r); +typedef void srcdirf_t(COLOR cv, void *np, FVECT ldir, double omega); +extern void direct(RAY *r, srcdirf_t *f, void *p); +extern void srcscatter(RAY *r); +extern int m_light(OBJREC *m, RAY *r); +extern void srcblocker(RAY *r); +extern int srcblocked(RAY *r); +extern void freeobscache(SRCREC *s); + /* defined in srcsamp.c */ +extern double nextssamp(RAY *r, SRCINDEX *si); +extern int skipparts(int ct[3], int sz[3], int pp[2], unsigned char *pt); +extern void nopart(SRCINDEX *si, RAY *r); +extern void cylpart(SRCINDEX *si, RAY *r); +extern void flatpart(SRCINDEX *si, RAY *r); +extern double scylform(int sn, FVECT dir); + /* defined in srcsupp.c */ +extern void initstypes(void); +extern int newsource(void); +extern void setflatss(SRCREC *src); +extern void fsetsrc(SRCREC *src, OBJREC *so); +extern void ssetsrc(SRCREC *src, OBJREC *so); +extern void sphsetsrc(SRCREC *src, OBJREC *so); +extern void rsetsrc(SRCREC *src, OBJREC *so); +extern void cylsetsrc(SRCREC *src, OBJREC *so); +extern SPOT *makespot(OBJREC *m); +extern int spotout(RAY *r, SPOT *s); +extern double fgetmaxdisk(FVECT ocent, OBJREC *op); +extern double rgetmaxdisk(FVECT ocent, OBJREC *op); +extern double fgetplaneq(FVECT nvec, OBJREC *op); +extern double rgetplaneq(FVECT nvec, OBJREC *op); +extern int commonspot(SPOT *sp1, SPOT *sp2, FVECT org); +extern int commonbeam(SPOT *sp1, SPOT *sp2, FVECT org); +extern int checkspot(SPOT *sp, FVECT nrm); +extern double spotdisk(FVECT oc, OBJREC *op, SPOT *sp, FVECT pos); +extern double beamdisk(FVECT oc, OBJREC *op, SPOT *sp, FVECT dir); +extern double intercircle(FVECT cc, FVECT c1, FVECT c2, + double r1s, double r2s); + /* defined in virtuals.c */ +extern void markvirtuals(void); +extern void addvirtuals(int sn, int nr); +extern void vproject(OBJREC *o, int sn, int n); +extern OBJREC *vsmaterial(OBJREC *o); +extern int makevsrc(OBJREC *op, int sn, MAT4 pm); +extern double getdisk(FVECT oc, OBJREC *op, int sn); +extern int vstestvis(int f, OBJREC *o, FVECT oc, double or2, int sn); +extern void virtverb(int sn, FILE *fp); + + +#ifdef __cplusplus +} +#endif +#endif /* _RAD_SOURCE_H_ */ +