591 |
|
subtract_min(C_COLOR *cs, SDMat *sm) |
592 |
|
{ |
593 |
|
const int ncomp = 1 + 2*(sm->chroma != NULL); |
594 |
< |
float min_coef[3], coef[3]; |
594 |
> |
float min_coef[3], ymin, coef[3]; |
595 |
|
int i, o, c; |
596 |
|
|
597 |
|
min_coef[0] = min_coef[1] = min_coef[2] = FHUGE; |
602 |
|
if (coef[c] < min_coef[c]) |
603 |
|
min_coef[c] = coef[c]; |
604 |
|
} |
605 |
+ |
ymin = 0; |
606 |
|
for (c = ncomp; c--; ) |
607 |
< |
if (min_coef[c] > FTINY) |
608 |
< |
break; |
608 |
< |
if (c < 0) |
607 |
> |
ymin += min_coef[c]; |
608 |
> |
if (ymin <= .01/M_PI) /* not worth bothering about? */ |
609 |
|
return .0; |
610 |
|
if (ncomp == 1) { /* subtract grayscale minimum */ |
611 |
|
for (i = sm->ninc*sm->nout; i--; ) |
612 |
< |
sm->bsdf[i] -= min_coef[0]; |
612 |
> |
sm->bsdf[i] -= ymin; |
613 |
|
*cs = c_dfcolor; |
614 |
< |
return min_coef[0]*M_PI; |
614 |
> |
return M_PI*ymin; |
615 |
|
} |
616 |
|
/* else subtract colored minimum */ |
617 |
|
for (i = 0; i < sm->ninc; i++) |
623 |
|
mtx_RGB_coef[c]; |
624 |
|
if (c_fromSharpRGB(coef, &cxy) > 1e-5) |
625 |
|
sm->chroma[o*sm->ninc + i] = c_encodeChroma(&cxy); |
626 |
< |
mBSDF_value(sm,i,o) -= min_coef[0]+min_coef[1]+min_coef[2]; |
626 |
> |
mBSDF_value(sm,i,o) -= ymin; |
627 |
|
} |
628 |
|
/* return colored minimum */ |
629 |
|
for (i = 3; i--; ) |
630 |
|
coef[i] = min_coef[i]/mtx_RGB_coef[i]; |
631 |
|
c_fromSharpRGB(coef, cs); |
632 |
|
|
633 |
< |
return (min_coef[0]+min_coef[1]+min_coef[2])*M_PI; |
633 |
> |
return M_PI*ymin; |
634 |
|
} |
635 |
|
|
636 |
|
/* Extract and separate diffuse portion of BSDF & convert color */ |