--- ray/src/util/glarendx.c 1991/04/18 15:18:20 1.4 +++ ray/src/util/glarendx.c 1991/04/29 08:31:23 1.7 @@ -134,7 +134,7 @@ char *s; sscanview(&midview, s+VIEWSTRL); else if (isformat(s)) { formatval(fmt, s); - wrongformat = strcmp(fmt, "ASCII"); + wrongformat = strcmp(fmt, "ascii"); } } @@ -239,6 +239,7 @@ struct glare_dir *gd; * All vectors are assumed to be normalized. * This function is an implementation of the method proposed by * Robert Levin in his 1975 JIES article. + * This calculation presumes the view direction and up vectors perpendicular. * We return a value less than zero for improper positions. */ @@ -252,8 +253,14 @@ FVECT sd, vd, vu; d = DOT(sd,vd); if (d <= 0.0) return(-1.0); + if (d >= 1.0) + return(1.0); sigma = acos(d) * (180./PI); - tau = acos(DOT(sd,vu)/sqrt(1.0-d*d)) * (180./PI); + d = DOT(sd,vu)/sqrt(1.0-d*d); + if (d >= 1.0) + tau = 0.0; + else + tau = acos(d) * (180./PI); return( exp( sigma*( (35.2 - tau*.31889 - 1.22*exp(-.22222*tau))*1e-3 + sigma*(21. + tau*(.26667 + tau*-.002963))*1e-5 ) ) ); @@ -266,14 +273,16 @@ struct glare_dir *gd; { #define q(w) (20.4*w+1.52*pow(w,.2)-.075) register struct glare_src *gs; + FVECT mydir; double p; double sum; double wtot, brsum; int n; + spinvector(mydir, midview.vdir, midview.vup, gd->ang); sum = wtot = brsum = 0.0; n = 0; for (gs = all_srcs; gs != NULL; gs = gs->next) { - p = posindex(gs->dir, midview.vdir, midview.vup); + p = posindex(gs->dir, mydir, midview.vup); if (p <= FTINY) continue; sum += gs->lum * q(gs->dom) / p; @@ -304,5 +313,10 @@ double guth_vcp(gd) /* compute Guth visual comfort probability */ struct glare_dir *gd; { - return(100.*norm_integral(6.374-1.3227*log(guth_dgr(gd)))); + double dgr; + + dgr = guth_dgr(gd); + if (dgr <= FTINY) + return(100.0); + return(100.*norm_integral(6.374-1.3227*log(dgr))); }