25 |
|
#define MAXAC 64 /* maximum number of args */ |
26 |
|
|
27 |
|
#ifndef MINTHRESH |
28 |
< |
#define MINTHRESH 7.0 /* source threshold w.r.t. mean */ |
28 |
> |
#define MINTHRESH 5.0 /* source threshold w.r.t. mean */ |
29 |
|
#endif |
30 |
|
|
31 |
|
#ifndef NALT |
69 |
|
static int lastxfac; /* last number of transform args */ |
70 |
|
static char *lastxfav[MAXAC+1]; /* saved transform arguments */ |
71 |
|
|
72 |
+ |
#define getdcent(c,op) multp3(c,(op)->center,(op)->xfb.f.xfm) |
73 |
+ |
#define getdrad(op) ((op)->radius*(op)->xfb.f.sca) |
74 |
+ |
|
75 |
|
#define RTARGC 8 |
76 |
|
static char *rtargv[RTARGC+1] = {"rtrace", "-h-", "-w-", "-fdd", |
77 |
|
"-x", "1", "-oL"}; |
282 |
|
ncells++; |
283 |
|
} |
284 |
|
if (dlightsets == NULL | ncells < NALT*NAZI/4) { |
285 |
< |
bzero((char *)ssamp, sizeof(ssamp)); |
286 |
< |
return(0); |
285 |
> |
ncells = 0; |
286 |
> |
goto done; |
287 |
|
} |
288 |
|
/* harmonic mean distance */ |
289 |
|
if (dlightsets->ravg > FTINY) |
292 |
|
dlightsets->ravg = FHUGE; |
293 |
|
/* light source threshold */ |
294 |
|
thresh = MINTHRESH*bright(csum)/ncells; |
295 |
+ |
if (thresh <= FTINY) { |
296 |
+ |
ncells = 0; |
297 |
+ |
goto done; |
298 |
+ |
} |
299 |
|
/* avg. reflected brightness */ |
300 |
|
d = AVGREFL / (double)ncells; |
301 |
|
scalecolor(csum, d); |
302 |
|
if (tmCvColors(&dlightsets->larb, TM_NOCHROM, csum, 1) != TM_E_OK) |
303 |
< |
error(CONSISTENCY, "bad tone mapping in ssph_compute"); |
303 |
> |
error(CONSISTENCY, "tone mapping problem in ssph_compute"); |
304 |
|
/* greedy light source clustering */ |
305 |
|
while (dlightsets->nl < MAXLIGHTS) { |
306 |
|
maxbr = 0.; /* find brightest cell */ |
336 |
|
addcolor(dlightsets->lamb, ssamp[alt][azi].val); |
337 |
|
d = 1.0/ncells; |
338 |
|
scalecolor(dlightsets->lamb, d); |
339 |
< |
/* clear sphere sample array */ |
339 |
> |
done: /* clear sphere sample array */ |
340 |
|
bzero((char *)ssamp, sizeof(ssamp)); |
341 |
|
return(ncells); |
342 |
|
} |
356 |
|
if (op->drawcode != DO_LIGHT) |
357 |
|
return(0); |
358 |
|
/* check for usable light set */ |
359 |
< |
multp3(ocent, op->center, op->xfb.f.xfm); |
359 |
> |
getdcent(ocent, op); |
360 |
|
for (dl = dlightsets; dl != NULL; dl = dl->next) |
361 |
|
if ((d2 = dist2(dl->lcent, ocent)) < mind2) { |
362 |
|
op->ol = dl; |
363 |
|
mind2 = d2; |
364 |
|
} |
365 |
|
/* the following is heuristic */ |
366 |
< |
d2 = 2.*op->radius*op->xfb.f.sca; d2 *= d2; |
366 |
> |
d2 = 2.*getdrad(op); d2 *= d2; |
367 |
|
if ((dl = op->ol) != NULL && (mind2 < 0.0625*dl->ravg*dl->ravg || |
368 |
< |
mind2 < 4.*op->radius*op->xfb.f.sca*op->radius*op->xfb.f.sca)) |
368 |
> |
mind2 < 4.*getdrad(op)*getdrad(op))) |
369 |
|
return(1); |
370 |
|
if (!force) |
371 |
|
return(0); |
662 |
|
error(COMMAND, "unknown object"); |
663 |
|
return(0); |
664 |
|
} |
665 |
< |
multp3(ocent, op->center, op->xfb.f.xfm); |
665 |
> |
getdcent(ocent, op); |
666 |
|
fprintf(fp, "%s: %s, center [%f %f %f], radius %f", op->name, |
667 |
|
op->drawcode==DO_HIDE ? "hid" : |
668 |
|
op->drawcode==DO_LIGHT && op->ol!=NULL ? "lit" : |
669 |
|
"shown", |
670 |
< |
ocent[0],ocent[1],ocent[2], op->radius*op->xfb.f.sca); |
670 |
> |
ocent[0],ocent[1],ocent[2], getdrad(op)); |
671 |
|
if (op->xfac) |
672 |
|
fputs(", (xform", fp); |
673 |
|
for (i = 0; i < op->xfac; i++) { |
779 |
|
|
780 |
|
|
781 |
|
double |
782 |
< |
dobj_trace(rorg, rdir) /* check for ray intersection with objects */ |
782 |
> |
dobj_trace(nm, rorg, rdir) /* check for ray intersection with object(s) */ |
783 |
> |
char nm[]; |
784 |
|
FVECT rorg, rdir; |
785 |
|
{ |
786 |
|
register DOBJECT *op; |
787 |
|
FVECT xorg, xdir; |
788 |
< |
double darr[6], mindist = FHUGE; |
788 |
> |
double darr[6]; |
789 |
> |
|
790 |
> |
if (nm == NULL || *nm == '*') { |
791 |
> |
double dist, mindist = 1.01*FHUGE; |
792 |
|
/* check each visible object */ |
793 |
< |
for (op = dobjects; op != NULL; op = op->next) { |
794 |
< |
if (op->drawcode == DO_HIDE) |
795 |
< |
continue; |
796 |
< |
if (op->xfac) { /* transform ray */ |
797 |
< |
multp3(xorg, rorg, op->xfb.b.xfm); |
798 |
< |
multv3(xdir, rdir, op->xfb.b.xfm); |
799 |
< |
VCOPY(darr, xorg); VCOPY(darr+3, xdir); |
800 |
< |
} else { |
801 |
< |
VCOPY(darr, rorg); VCOPY(darr+3, rdir); |
793 |
> |
for (op = dobjects; op != NULL; op = op->next) { |
794 |
> |
if (op->drawcode == DO_HIDE) |
795 |
> |
continue; |
796 |
> |
dist = dobj_trace(op->name, rorg, rdir); |
797 |
> |
if (dist < mindist) { |
798 |
> |
dist = mindist; |
799 |
> |
if (nm != NULL) |
800 |
> |
strcpy(nm, op->name); |
801 |
> |
} |
802 |
|
} |
803 |
< |
/* trace it */ |
793 |
< |
if (process(op->rtp, darr, darr, sizeof(double), |
794 |
< |
6*sizeof(double)) != sizeof(double)) |
795 |
< |
error(SYSTEM, "rtrace communication error"); |
796 |
< |
/* get closest */ |
797 |
< |
if ((darr[0] *= op->xfb.f.sca) < mindist) |
798 |
< |
mindist = darr[0]; |
803 |
> |
return(mindist); |
804 |
|
} |
805 |
< |
return(mindist); |
805 |
> |
/* else check particular object */ |
806 |
> |
if ((op = getdobj(nm)) == NULL) { |
807 |
> |
error(COMMAND, "unknown object"); |
808 |
> |
return(FHUGE); |
809 |
> |
} |
810 |
> |
if (op->xfac) { /* transform ray */ |
811 |
> |
multp3(xorg, rorg, op->xfb.b.xfm); |
812 |
> |
multv3(xdir, rdir, op->xfb.b.xfm); |
813 |
> |
VCOPY(darr, xorg); VCOPY(darr+3, xdir); |
814 |
> |
} else { |
815 |
> |
VCOPY(darr, rorg); VCOPY(darr+3, rdir); |
816 |
> |
} |
817 |
> |
/* trace it */ |
818 |
> |
if (process(op->rtp, darr, darr, sizeof(double), |
819 |
> |
6*sizeof(double)) != sizeof(double)) |
820 |
> |
error(SYSTEM, "rtrace communication error"); |
821 |
> |
/* return distance */ |
822 |
> |
if (darr[0] >= .99*FHUGE) |
823 |
> |
return(FHUGE); |
824 |
> |
return(darr[0] * op->xfb.f.sca); |
825 |
|
} |
826 |
|
|
827 |
|
|
829 |
|
{ |
830 |
|
GLboolean normalizing; |
831 |
|
GLfloat vec[4]; |
832 |
+ |
FVECT v1; |
833 |
|
register DOBJECT *op; |
834 |
|
register int i; |
835 |
|
/* anything to render? */ |
861 |
|
if (op->drawcode == DO_LIGHT && op->ol != NULL) { |
862 |
|
BYTE pval; |
863 |
|
double expval, d; |
864 |
< |
|
864 |
> |
/* use computed sources */ |
865 |
|
if (tmMapPixels(&pval, &op->ol->larb, TM_NOCHROM, 1) |
866 |
|
!= TM_E_OK) |
867 |
|
error(CONSISTENCY, "dobj_render w/o tone map"); |
887 |
|
glLightfv(glightid[i], GL_AMBIENT, vec); |
888 |
|
glEnable(glightid[i]); |
889 |
|
} |
890 |
< |
} else { |
891 |
< |
vec[0] = vec[1] = vec[2] = 1.; vec[3] = 1.; |
890 |
> |
} else { /* no sources to draw on */ |
891 |
> |
vec[0] = vec[1] = vec[2] = 0.; vec[3] = 1.; |
892 |
|
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, vec); |
893 |
+ |
getdcent(v1, op); |
894 |
+ |
VSUB(v1, odev.v.vp, v1); |
895 |
+ |
if (normalize(v1) <= getdrad(op)) { |
896 |
+ |
vec[0] = -odev.v.vdir[0]; |
897 |
+ |
vec[1] = -odev.v.vdir[1]; |
898 |
+ |
vec[2] = -odev.v.vdir[2]; |
899 |
+ |
} else |
900 |
+ |
VCOPY(vec, v1); |
901 |
+ |
vec[3] = 0.; |
902 |
+ |
glLightfv(GL_LIGHT0, GL_POSITION, vec); |
903 |
+ |
vec[0] = vec[1] = vec[2] = .7; vec[3] = 1.; |
904 |
+ |
glLightfv(GL_LIGHT0, GL_SPECULAR, vec); |
905 |
+ |
glLightfv(GL_LIGHT0, GL_DIFFUSE, vec); |
906 |
+ |
vec[0] = vec[1] = vec[2] = .3; vec[3] = 1.; |
907 |
+ |
glLightfv(GL_LIGHT0, GL_AMBIENT, vec); |
908 |
+ |
glEnable(GL_LIGHT0); |
909 |
|
} |
910 |
|
/* set up object transform */ |
911 |
|
if (op->xfac) { |
934 |
|
if (op->drawcode == DO_LIGHT && op->ol != NULL) |
935 |
|
for (i = op->ol->nl; i--; ) |
936 |
|
glDisable(glightid[i]); |
937 |
+ |
else |
938 |
+ |
glDisable(GL_LIGHT0); |
939 |
|
/* check errors */ |
940 |
|
rgl_checkerr("rendering object in dobj_render"); |
941 |
|
} |