Skip to content

Commit

Permalink
perf: Improved source scatter sampling
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregungory committed Nov 9, 2024
1 parent 57900be commit bd998fa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
6 changes: 4 additions & 2 deletions src/rt/source.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef lint
static const char RCSid[] = "$Id: source.c,v 2.82 2024/04/05 01:10:26 greg Exp $";
static const char RCSid[] = "$Id: source.c,v 2.83 2024/11/09 15:21:32 greg Exp $";
#endif
/*
* source.c - routines dealing with illumination sources.
Expand Down Expand Up @@ -596,13 +596,15 @@ srcscatter( /* compute source scattering into ray */
setcolor(cvext, re > 92. ? 0. : exp(-re),
ge > 92. ? 0. : exp(-ge),
be > 92. ? 0. : exp(-be));
if (intens(cvext) <= FTINY)
if (intens(cvext) <= FTINY*FTINY)
break; /* too far away */
sr.rorg[0] = r->rorg[0] + r->rdir[0]*t;
sr.rorg[1] = r->rorg[1] + r->rdir[1]*t;
sr.rorg[2] = r->rorg[2] + r->rdir[2]*t;

if (!volumePhotonMapping) {
if (srcskip(r->slights[i], r))
continue;
initsrcindex(&si); /* sample ray to this source */
si.sn = r->slights[i];
nopart(&si, &sr);
Expand Down
3 changes: 2 additions & 1 deletion src/rt/source.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* RCSid $Id: source.h,v 2.24 2023/11/15 18:02:53 greg Exp $ */
/* RCSid $Id: source.h,v 2.25 2024/11/09 15:21:32 greg Exp $ */
/*
* source.h - header file for ray tracing sources.
*
Expand Down Expand Up @@ -163,6 +163,7 @@ extern int srcblocked(RAY *r);
extern void freeobscache(SRCREC *s);
extern void markclip(OBJREC *m);
/* defined in srcsamp.c */
extern int srcskip(int sn, RAY *r);
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);
Expand Down
18 changes: 10 additions & 8 deletions src/rt/srcsamp.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef lint
static const char RCSid[] = "$Id: srcsamp.c,v 2.20 2019/06/11 17:00:59 greg Exp $";
static const char RCSid[] = "$Id: srcsamp.c,v 2.21 2024/11/09 15:21:32 greg Exp $";
#endif
/*
* Source sampling routines
Expand All @@ -16,26 +16,28 @@ static const char RCSid[] = "$Id: srcsamp.c,v 2.20 2019/06/11 17:00:59 greg Exp
#include "random.h"


static int
srcskip( /* pre-emptive test for out-of-range glow */
SRCREC *sp,
FVECT orig
int
srcskip( /* pre-emptive test for source to skip */
int sn,
RAY *r
)
{
SRCREC *sp = source + sn;

if (sp->sflags & SSKIP)
return(1);

if ((sp->sflags & (SPROX|SDISTANT)) != SPROX)
return(0);

return(dist2(orig, sp->sloc) >
return(dist2(r->rorg, sp->sloc) >
(sp->sl.prox + sp->srad)*(sp->sl.prox + sp->srad));
}

double
nextssamp( /* compute sample for source, rtn. distance */
RAY *r, /* origin is read, direction is set */
SRCINDEX *si /* source index (modified to current) */\
SRCINDEX *si /* source index (modified to current) */
)
{
int cent[3], size[3], parr[2];
Expand All @@ -47,7 +49,7 @@ nextssamp( /* compute sample for source, rtn. distance */
while (++si->sp >= si->np) { /* get next sample */
if (++si->sn >= nsources)
return(0.0); /* no more */
if (srcskip(source+si->sn, r->rorg))
if (srcskip(si->sn, r))
si->np = 0;
else if (srcsizerat <= FTINY)
nopart(si, r);
Expand Down

0 comments on commit bd998fa

Please sign in to comment.