Skip to content

Commit

Permalink
perf: Minor efficiency improvement for -bv0
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregungory committed Dec 13, 2024
1 parent f9c86b4 commit 1230f38
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
10 changes: 5 additions & 5 deletions src/rt/m_brdf.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef lint
static const char RCSid[] = "$Id: m_brdf.c,v 2.42 2024/12/05 19:23:43 greg Exp $";
static const char RCSid[] = "$Id: m_brdf.c,v 2.43 2024/12/13 19:05:03 greg Exp $";
#endif
/*
* Shading for materials with arbitrary BRDF's
Expand Down Expand Up @@ -346,10 +346,6 @@ m_brdf2( /* color a ray that hit a BRDF material */
/* always a shadow */
if (r->crtype & SHADOW)
return(1);
/* check arguments */
if ((m->oargs.nsargs < (hasdata(m->otype)?4:2)) | (m->oargs.nfargs <
((m->otype==MAT_TFUNC)|(m->otype==MAT_TDATA)?6:4)))
objerror(m, USER, "bad # arguments");
/* check for back side */
if (r->rod < 0.0) {
if (!backvis) {
Expand All @@ -360,6 +356,10 @@ m_brdf2( /* color a ray that hit a BRDF material */
flipsurface(r); /* reorient if backvis */
} else
raytexture(r, m->omod);
/* check arguments */
if ((m->oargs.nsargs < (hasdata(m->otype)?4:2)) | (m->oargs.nfargs <
((m->otype==MAT_TFUNC)|(m->otype==MAT_TDATA)?6:4)))
objerror(m, USER, "bad # arguments");

nd.mp = m;
nd.pr = r;
Expand Down
18 changes: 8 additions & 10 deletions src/rt/m_bsdf.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef lint
static const char RCSid[] = "$Id: m_bsdf.c,v 2.74 2024/09/18 19:52:35 greg Exp $";
static const char RCSid[] = "$Id: m_bsdf.c,v 2.75 2024/12/13 19:05:03 greg Exp $";
#endif
/*
* Shading for materials with BSDFs taken from XML data files
Expand Down Expand Up @@ -626,19 +626,22 @@ sample_sdf(BSDFDAT *ndp, int sflags)
int
m_bsdf(OBJREC *m, RAY *r)
{
int hasthick = (m->otype == MAT_BSDF);
int hitfront;
const int hasthick = (m->otype == MAT_BSDF);
const int hitfront = (r->rod > 0);
SCOLOR sctmp;
SDError ec;
FVECT upvec, vtmp;
MFUNC *mf;
BSDFDAT nd;
/* check backface visibility */
if (!hitfront & !backvis) {
raytrans(r);
return(1);
}
/* check arguments */
if ((m->oargs.nsargs < hasthick+5) | (m->oargs.nfargs > 9) |
(m->oargs.nfargs % 3))
objerror(m, USER, "bad # arguments");
/* record surface struck */
hitfront = (r->rod > 0);
/* load cal file */
mf = hasthick ? getfunc(m, 5, 0x1d, 1)
: getfunc(m, 4, 0xe, 1) ;
Expand All @@ -648,11 +651,6 @@ m_bsdf(OBJREC *m, RAY *r)
nd.thick = evalue(mf->ep[0]);
if ((-FTINY <= nd.thick) & (nd.thick <= FTINY))
nd.thick = 0;
}
/* check backface visibility */
if (!hitfront & !backvis) {
raytrans(r);
return(1);
}
/* check other rays to pass */
if (nd.thick != 0 && (r->crtype & SHADOW ||
Expand Down

0 comments on commit 1230f38

Please # to comment.