--- ray/src/rt/srcsupp.c 1991/10/21 12:58:16 1.14 +++ ray/src/rt/srcsupp.c 1992/08/28 14:07:45 2.5 @@ -1,4 +1,4 @@ -/* Copyright (c) 1991 Regents of the University of California */ +/* Copyright (c) 1992 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -174,7 +174,7 @@ register OBJREC *so; for (i = 0; i < 3; i++) src->ss[SU][i] = src->ss[SV][i] = src->ss[SW][i] = 0.0; for (i = 0; i < 3; i++) - src->ss[i][i] = .886227 * so->oargs.farg[3]; + src->ss[i][i] = .7236 * so->oargs.farg[3]; } @@ -212,9 +212,10 @@ OBJREC *so; co = getcone(so, 0); if (CO_R0(co) > .2*co->al) /* heuristic constraint */ objerror(so, WARNING, "source aspect too small"); + src->sflags |= SCYL; for (i = 0; i < 3; i++) src->sloc[i] = .5 * (CO_P1(co)[i] + CO_P0(co)[i]); - src->srad = co->al; + src->srad = .5*co->al; src->ss2 = 2.*CO_R0(co)*co->al; /* set sampling vectors */ for (i = 0; i < 3; i++) @@ -227,7 +228,7 @@ OBJREC *so; fcross(src->ss[SW], src->ss[SV], co->ad); normalize(src->ss[SW]); for (i = 0; i < 3; i++) - src->ss[SW][i] *= .886227 * CO_R0(co); + src->ss[SW][i] *= .8559 * CO_R0(co); fcross(src->ss[SV], src->ss[SW], co->ad); } @@ -238,16 +239,49 @@ register OBJREC *m; { register SPOT *ns; + if ((ns = (SPOT *)m->os) != NULL) + return(ns); if ((ns = (SPOT *)malloc(sizeof(SPOT))) == NULL) return(NULL); ns->siz = 2.0*PI * (1.0 - cos(PI/180.0/2.0 * m->oargs.farg[3])); VCOPY(ns->aim, m->oargs.farg+4); if ((ns->flen = normalize(ns->aim)) == 0.0) objerror(m, USER, "zero focus vector"); + m->os = (char *)ns; return(ns); } +spotout(r, s, dist) /* check if we're outside spot region */ +register RAY *r; +register SPOT *s; +int dist; +{ + double d; + FVECT vd; + + if (s == NULL) + return(0); + if (dist) { /* distant source */ + vd[0] = s->aim[0] - r->rorg[0]; + vd[1] = s->aim[1] - r->rorg[1]; + vd[2] = s->aim[2] - r->rorg[2]; + d = DOT(r->rdir,vd); + /* wrong side? + if (d <= FTINY) + return(1); */ + d = DOT(vd,vd) - d*d; + if (PI*d > s->siz) + return(1); /* out */ + return(0); /* OK */ + } + /* local source */ + if (s->siz < 2.0*PI * (1.0 + DOT(s->aim,r->rdir))) + return(1); /* out */ + return(0); /* OK */ +} + + double fgetmaxdisk(ocent, op) /* get center and squared radius of face */ FVECT ocent; @@ -496,55 +530,4 @@ register RAY *r; return(1); } return(0); -} - - -#define wrongsource(m, r) (r->rsrc>=0 && \ - source[r->rsrc].so!=r->ro && \ - (m->otype!=MAT_ILLUM || \ - objptr(source[r->rsrc].so->omod)->otype==MAT_ILLUM)) - -#define distglow(m, r) (m->otype==MAT_GLOW && \ - r->rot > m->oargs.farg[3]) - -#define badambient(m, r) ((r->crtype&(AMBIENT|SHADOW))==AMBIENT && \ - !distglow(m, r)) - -#define passillum(m, r) (m->otype==MAT_ILLUM && \ - !(r->rsrc>=0&&source[r->rsrc].so==r->ro)) - -#define srcignore(m, r) (directinvis && !(r->crtype&SHADOW) && \ - !distglow(m, r)) - - -m_light(m, r) /* ray hit a light source */ -register OBJREC *m; -register RAY *r; -{ - /* check for over-counting */ - if (wrongsource(m, r) || badambient(m, r)) - return; - /* check for passed illum */ - if (passillum(m, r)) { - if (m->oargs.nsargs < 1 || !strcmp(m->oargs.sarg[0], VOIDID)) - raytrans(r); - else - rayshade(r, modifier(m->oargs.sarg[0])); - return; - } - /* otherwise treat as source */ - /* check for behind */ - if (r->rod < 0.0) - return; - /* check for invisibility */ - if (srcignore(m, r)) - return; - /* get distribution pattern */ - raytexture(r, m->omod); - /* get source color */ - setcolor(r->rcol, m->oargs.farg[0], - m->oargs.farg[1], - m->oargs.farg[2]); - /* modify value */ - multcolor(r->rcol, r->pcol); }