Skip to content

Commit

Permalink
perf: Minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregungory committed Dec 18, 2024
1 parent a62af6b commit 6c9ff23
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
5 changes: 2 additions & 3 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.43 2024/12/13 19:05:03 greg Exp $";
static const char RCSid[] = "$Id: m_brdf.c,v 2.44 2024/12/18 17:57:06 greg Exp $";
#endif
/*
* Shading for materials with arbitrary BRDF's
Expand Down Expand Up @@ -432,8 +432,7 @@ setbrdfunc( /* set up brdf function and variables */
varset("NxP`", '=', vec[0]/funcxf.sca);
varset("NyP`", '=', vec[1]/funcxf.sca);
varset("NzP`", '=', vec[2]/funcxf.sca);
varset("RdotP`", '=', np->pdot <= -1.0 ? -1.0 :
np->pdot >= 1.0 ? 1.0 : np->pdot);
varset("RdotP`", '=', np->pdot);
scolor_color(ctmp, np->mcolor); /* should use scolor_rgb()? */
varset("CrP", '=', colval(ctmp,RED));
varset("CgP", '=', colval(ctmp,GRN));
Expand Down
29 changes: 14 additions & 15 deletions src/rt/m_wgmdf.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef lint
static const char RCSid[] = "$Id: m_wgmdf.c,v 2.5 2024/12/17 20:03:13 greg Exp $";
static const char RCSid[] = "$Id: m_wgmdf.c,v 2.6 2024/12/18 17:57:06 greg Exp $";
#endif
/*
* Shading function for programmable Ward-Geisler-Moroder-Duer material.
Expand Down Expand Up @@ -158,23 +158,23 @@ fill_modval(MODVAL *mp, const WGMDDAT *wp)
return(set_modval(mp, lastmod(objndx(wp->mtp), mp->nam), wp->rp));
}

/* set calculation context for given component of MAT_WGMDF */
static int
setWGMDfunc(MODVAL *mp, const WGMDDAT *wp)
{
static char lastMod[MAXSTR] = "";
static char lastMod[MAXSTR];
double sf;
FVECT vec;

if (setfunc(wp->mtp, wp->rp) == 0 &&
!strcmp(mp->nam, lastMod))
return(0); /* already set */
/* else (re)assign special variables */
strcpy(lastMod, mp->nam);
sf = (wp->rp->rod > 0) ? 1. : -1.;
varset("RdotP`", '=', (-1. < mp->pdot) & (mp->pdot < 1.)
? sf*mp->pdot : 1.);
sf /= funcxf.sca;
/* else (re)assign special variables */
sf = 1 - 2*(wp->rp->rod < 0);
varset("RdotP`", '=', mp->pdot*sf);
multv3(vec, mp->pnorm, funcxf.xfm);
sf /= funcxf.sca;
varset("NxP`", '=', vec[0]*sf);
varset("NyP`", '=', vec[1]*sf);
varset("NzP`", '=', vec[2]*sf);
Expand Down Expand Up @@ -213,12 +213,11 @@ set_dcomp(WGMDDAT *wp, int trans)
static void
set_scomp(WGMDDAT *wp, int trans)
{
SCOMP *sp = trans ? &wp->ts : &wp->rs;
const int eoff = 3*(trans != 0);
double coef;
SCOMP *sp = trans ? &wp->ts : &wp->rs;
EPNODE **exa = wp->mf->ep + 3*(trans != 0);
double coef;
/* constant zero check */
if (wp->mf->ep[eoff]->type == NUM &&
wp->mf->ep[eoff]->v.num <= FTINY) {
if (exa[0]->type == NUM && exa[0]->v.num <= FTINY) {
scolorblack(sp->scol);
return;
} /* need modifier */
Expand All @@ -230,7 +229,7 @@ set_scomp(WGMDDAT *wp, int trans)
}
setWGMDfunc(&sp->mo, wp);
errno = 0;
coef = evalue(wp->mf->ep[eoff]);
coef = evalue(exa[0]);
if ((errno == EDOM) | (errno == ERANGE)) {
objerror(wp->mtp, WARNING, "specular compute error");
scolorblack(sp->scol);
Expand All @@ -247,8 +246,8 @@ set_scomp(WGMDDAT *wp, int trans)
return; /* got black pattern */
}
errno = 0; /* else get roughness */
sp->u_alpha = evalue(wp->mf->ep[eoff+1]);
sp->v_alpha = (sp->u_alpha > FTINY) ? evalue(wp->mf->ep[eoff+2]) : 0.0;
sp->u_alpha = evalue(exa[1]);
sp->v_alpha = (sp->u_alpha > FTINY) ? evalue(exa[2]) : 0.0;
if ((errno == EDOM) | (errno == ERANGE)) {
objerror(wp->mtp, WARNING, "roughness compute error");
scolorblack(sp->scol);
Expand Down

0 comments on commit 6c9ff23

Please sign in to comment.