| 50 |
|
|
| 51 |
|
typedef struct { |
| 52 |
|
OBJREC *mp; /* material pointer */ |
| 53 |
+ |
RAY *rp; /* ray pointer */ |
| 54 |
|
short specfl; /* specularity flags, defined above */ |
| 55 |
|
COLOR mcolor; /* color of this material */ |
| 56 |
|
COLOR scolor; /* color of specular component */ |
| 72 |
|
double omega; /* light source size */ |
| 73 |
|
{ |
| 74 |
|
double ldot; |
| 75 |
< |
double dtmp; |
| 76 |
< |
int i; |
| 75 |
> |
double dtmp, d2; |
| 76 |
> |
FVECT vtmp; |
| 77 |
|
COLOR ctmp; |
| 78 |
|
|
| 79 |
|
setcolor(cval, 0.0, 0.0, 0.0); |
| 100 |
|
* gaussian distribution model. |
| 101 |
|
*/ |
| 102 |
|
/* roughness */ |
| 103 |
< |
dtmp = 2.0*np->alpha2; |
| 103 |
> |
dtmp = np->alpha2; |
| 104 |
|
/* + source if flat */ |
| 105 |
|
if (np->specfl & SP_FLAT) |
| 106 |
< |
dtmp += omega/(2.0*PI); |
| 106 |
> |
dtmp += omega/(4.0*PI); |
| 107 |
> |
/* delta */ |
| 108 |
> |
vtmp[0] = ldir[0] - np->rp->rdir[0]; |
| 109 |
> |
vtmp[1] = ldir[1] - np->rp->rdir[1]; |
| 110 |
> |
vtmp[2] = ldir[2] - np->rp->rdir[2]; |
| 111 |
> |
d2 = DOT(vtmp, np->pnorm); |
| 112 |
> |
d2 = 2.0 - 2.0*d2/sqrt(DOT(vtmp,vtmp)); |
| 113 |
|
/* gaussian */ |
| 114 |
< |
dtmp = exp((DOT(np->vrefl,ldir)-1.)/dtmp)/(2.*PI)/dtmp; |
| 114 |
> |
dtmp = exp(-d2/dtmp)/(4.*PI*dtmp); |
| 115 |
|
/* worth using? */ |
| 116 |
|
if (dtmp > FTINY) { |
| 117 |
|
copycolor(ctmp, np->scolor); |
| 135 |
|
* is always modified by material color. |
| 136 |
|
*/ |
| 137 |
|
/* roughness + source */ |
| 138 |
< |
dtmp = np->alpha2/2.0 + omega/(2.0*PI); |
| 138 |
> |
dtmp = np->alpha2 + omega/PI; |
| 139 |
|
/* gaussian */ |
| 140 |
< |
dtmp = exp((DOT(np->prdir,ldir)-1.)/dtmp)/(2.*PI)/dtmp; |
| 140 |
> |
dtmp = exp((2.*DOT(np->prdir,ldir)-2.)/dtmp)/(4.*PI*dtmp); |
| 141 |
|
/* worth using? */ |
| 142 |
|
if (dtmp > FTINY) { |
| 143 |
|
copycolor(ctmp, np->mcolor); |
| 144 |
< |
dtmp *= np->tspec * omega * sqrt(ldot/np->pdot); |
| 144 |
> |
dtmp *= np->tspec * omega * sqrt(-ldot/np->pdot); |
| 145 |
|
scalecolor(ctmp, dtmp); |
| 146 |
|
addcolor(cval, ctmp); |
| 147 |
|
} |
| 165 |
|
if (m->oargs.nfargs != (m->otype == MAT_TRANS ? 7 : 5)) |
| 166 |
|
objerror(m, USER, "bad number of arguments"); |
| 167 |
|
nd.mp = m; |
| 168 |
+ |
nd.rp = r; |
| 169 |
|
/* get material color */ |
| 170 |
|
setcolor(nd.mcolor, m->oargs.farg[0], |
| 171 |
|
m->oargs.farg[1], |
| 203 |
|
if (!(nd.specfl & SP_PURE) && |
| 204 |
|
specthresh > FTINY && |
| 205 |
|
(specthresh >= 1.-FTINY || |
| 206 |
< |
specthresh > nd.rspec)) |
| 206 |
> |
specthresh + .05 - .1*frandom() > nd.rspec)) |
| 207 |
|
nd.specfl |= SP_RBLT; |
| 208 |
|
/* compute reflected ray */ |
| 209 |
|
for (i = 0; i < 3; i++) |
| 232 |
|
/* check threshold */ |
| 233 |
|
if (!(nd.specfl & SP_PURE) && specthresh > FTINY && |
| 234 |
|
(specthresh >= 1.-FTINY || |
| 235 |
< |
specthresh > nd.tspec)) |
| 235 |
> |
specthresh + .05 - .1*frandom() > nd.tspec)) |
| 236 |
|
nd.specfl |= SP_TBLT; |
| 237 |
|
if (r->crtype & SHADOW || |
| 238 |
|
DOT(r->pert,r->pert) <= FTINY*FTINY) { |
| 240 |
|
transtest = 2; |
| 241 |
|
} else { |
| 242 |
|
for (i = 0; i < 3; i++) /* perturb */ |
| 243 |
< |
nd.prdir[i] = r->rdir[i] - |
| 236 |
< |
0.5*r->pert[i]; |
| 243 |
> |
nd.prdir[i] = r->rdir[i] - r->pert[i]; |
| 244 |
|
if (DOT(nd.prdir, r->ron) < -FTINY) |
| 245 |
|
normalize(nd.prdir); /* OK */ |
| 246 |
|
else |