158 |
|
return(set_modval(mp, lastmod(objndx(wp->mtp), mp->nam), wp->rp)); |
159 |
|
} |
160 |
|
|
161 |
+ |
/* set calculation context for given component of MAT_WGMDF */ |
162 |
|
static int |
163 |
|
setWGMDfunc(MODVAL *mp, const WGMDDAT *wp) |
164 |
|
{ |
165 |
< |
static char lastMod[MAXSTR] = ""; |
165 |
> |
static char lastMod[MAXSTR]; |
166 |
|
double sf; |
167 |
|
FVECT vec; |
168 |
|
|
169 |
|
if (setfunc(wp->mtp, wp->rp) == 0 && |
170 |
|
!strcmp(mp->nam, lastMod)) |
171 |
|
return(0); /* already set */ |
171 |
– |
/* else (re)assign special variables */ |
172 |
|
strcpy(lastMod, mp->nam); |
173 |
< |
sf = (wp->rp->rod > 0) ? 1. : -1.; |
174 |
< |
varset("RdotP`", '=', (-1. < mp->pdot) & (mp->pdot < 1.) |
175 |
< |
? sf*mp->pdot : 1.); |
176 |
< |
sf /= funcxf.sca; |
173 |
> |
/* else (re)assign special variables */ |
174 |
> |
sf = 1 - 2*(wp->rp->rod < 0); |
175 |
> |
varset("RdotP`", '=', mp->pdot*sf); |
176 |
|
multv3(vec, mp->pnorm, funcxf.xfm); |
177 |
+ |
sf /= funcxf.sca; |
178 |
|
varset("NxP`", '=', vec[0]*sf); |
179 |
|
varset("NyP`", '=', vec[1]*sf); |
180 |
|
varset("NzP`", '=', vec[2]*sf); |
213 |
|
static void |
214 |
|
set_scomp(WGMDDAT *wp, int trans) |
215 |
|
{ |
216 |
< |
SCOMP *sp = trans ? &wp->ts : &wp->rs; |
217 |
< |
const int eoff = 3*(trans != 0); |
218 |
< |
double coef; |
216 |
> |
SCOMP *sp = trans ? &wp->ts : &wp->rs; |
217 |
> |
EPNODE **exa = wp->mf->ep + 3*(trans != 0); |
218 |
> |
double coef; |
219 |
|
/* constant zero check */ |
220 |
< |
if (wp->mf->ep[eoff]->type == NUM && |
221 |
< |
wp->mf->ep[eoff]->v.num <= FTINY) { |
222 |
< |
scolorblack(sp->scol); |
223 |
< |
return; |
224 |
< |
} /* need modifier */ |
220 |
> |
if (exa[0]->type == NUM && exa[0]->v.num <= FTINY) |
221 |
> |
goto blackout; |
222 |
> |
/* need modifier */ |
223 |
|
sp->mo.nam = wp->mtp->oargs.sarg[4*(trans != 0)]; |
224 |
|
if (!fill_modval(&sp->mo, wp)) { |
225 |
|
sprintf(errmsg, "unknown specular %s modifier '%s'", |
226 |
|
trans ? "transmission" : "reflection", sp->mo.nam); |
227 |
|
objerror(wp->mtp, USER, errmsg); |
228 |
|
} |
229 |
< |
setWGMDfunc(&sp->mo, wp); |
229 |
> |
if (sintens(sp->mo.pcol) <= FTINY) |
230 |
> |
goto blackout; /* got black pattern */ |
231 |
> |
setWGMDfunc(&sp->mo, wp); /* else compute coefficient */ |
232 |
|
errno = 0; |
233 |
< |
coef = evalue(wp->mf->ep[eoff]); |
233 |
> |
coef = evalue(exa[0]); |
234 |
|
if ((errno == EDOM) | (errno == ERANGE)) { |
235 |
|
objerror(wp->mtp, WARNING, "specular compute error"); |
236 |
< |
scolorblack(sp->scol); |
237 |
< |
return; |
236 |
> |
goto blackout; |
237 |
|
} |
238 |
< |
if (coef <= FTINY) { /* negligible value? */ |
239 |
< |
scolorblack(sp->scol); |
241 |
< |
return; |
242 |
< |
} |
238 |
> |
if (coef <= FTINY) /* negligible value? */ |
239 |
> |
goto blackout; |
240 |
|
copyscolor(sp->scol, sp->mo.pcol); |
241 |
|
scalescolor(sp->scol, coef); |
245 |
– |
if (sintens(sp->scol) <= FTINY) { |
246 |
– |
scolorblack(sp->scol); |
247 |
– |
return; /* got black pattern */ |
248 |
– |
} |
242 |
|
errno = 0; /* else get roughness */ |
243 |
< |
sp->u_alpha = evalue(wp->mf->ep[eoff+1]); |
244 |
< |
sp->v_alpha = (sp->u_alpha > FTINY) ? evalue(wp->mf->ep[eoff+2]) : 0.0; |
243 |
> |
sp->u_alpha = evalue(exa[1]); |
244 |
> |
sp->v_alpha = (sp->u_alpha > FTINY) ? evalue(exa[2]) : 0.0; |
245 |
|
if ((errno == EDOM) | (errno == ERANGE)) { |
246 |
|
objerror(wp->mtp, WARNING, "roughness compute error"); |
247 |
< |
scolorblack(sp->scol); |
255 |
< |
return; |
247 |
> |
goto blackout; |
248 |
|
} /* we have something... */ |
249 |
|
wp->specfl |= trans ? SP_TRAN : SP_REFL; |
250 |
|
if (sp->v_alpha <= FTINY) { /* is it pure specular? */ |
251 |
|
wp->specfl |= trans ? SP_TPURE : SP_RPURE; |
252 |
|
sp->u_alpha = sp->v_alpha = 0.0; |
253 |
|
return; |
254 |
< |
} |
263 |
< |
/* get anisotropic coordinates */ |
254 |
> |
} /* else get aniso coordinates */ |
255 |
|
fcross(sp->v, sp->mo.pnorm, wp->ulocal); |
256 |
|
if (normalize(sp->v) == 0.0) { /* orientation vector==normal? */ |
257 |
|
if (fabs(sp->u_alpha - sp->v_alpha) > 0.001) |
262 |
|
(sp->u_alpha*sp->u_alpha + sp->v_alpha*sp->v_alpha) ); |
263 |
|
} else |
264 |
|
fcross(sp->u, sp->v, sp->mo.pnorm); |
265 |
+ |
return; |
266 |
+ |
blackout: |
267 |
+ |
scolorblack(sp->scol); /* zero out component */ |
268 |
|
} |
269 |
|
|
270 |
|
/* sample anisotropic Gaussian specular */ |
452 |
|
*/ |
453 |
|
/* add source width if flat */ |
454 |
|
if (wp->specfl & SP_FLAT) |
455 |
< |
au2 = av2 = omega * (0.25/PI); |
455 |
> |
au2 = av2 = (1. - dstrsrc) * omega * (0.25/PI); |
456 |
|
else |
457 |
|
au2 = av2 = 0.0; |
458 |
|
au2 += wp->rs.u_alpha*wp->rs.u_alpha; |
553 |
|
return(1); /* second shadow test */ |
554 |
|
set_dcomp(&wd, 1); |
555 |
|
set_scomp(&wd, 0); |
556 |
< |
wd.specfl |= SP_FLAT*(r->ro != NULL && isflat(r->ro->otype)); |
556 |
> |
wd.specfl |= SP_FLAT*(!wd.rs.mo.hastexture && |
557 |
> |
r->ro != NULL && isflat(r->ro->otype)); |
558 |
|
/* apply Fresnel adjustments? */ |
559 |
|
if (wd.specfl & SP_RPURE && pbright(wd.rs.scol) >= FRESTHRESH) { |
560 |
|
const double fest = FRESNE(fabs(wd.rs.mo.pdot)); |
613 |
|
copyscolor(r->mcol, lr.rcol); |
614 |
|
saddscolor(r->rcol, lr.rcol); |
615 |
|
r->rmt = r->rot; |
616 |
< |
if (wd.specfl & SP_FLAT && |
622 |
< |
!wd.rs.mo.hastexture | (r->crtype & AMBIENT)) |
616 |
> |
if (wd.specfl & SP_FLAT && r->crtype & AMBIENT) |
617 |
|
r->rmt += raydistance(&lr); |
618 |
|
} |
619 |
|
if (wd.specfl & (SP_REFL|SP_TRAN)) /* specularly scattered rays */ |