Permalink
Browse files

-Fix for Oren-Nayar shading:

fixed white (black on windows OS) dots for
oren-nayar in shinydiffuse, glossy and
coated glossy material.
For explanation see this link:
http://dl.dropbox.com/u/21229169/oren_nayar_fix.jpg
  • Loading branch information...
1 parent ecab381 commit bcc58f3e402258d105fd37ac044e222915147d25 @OlafArnold OlafArnold committed with Gustavo Pichorim Boiko Feb 7, 2012
Showing with 6 additions and 6 deletions.
  1. +2 −2 src/materials/coatedglossy.cc
  2. +2 −2 src/materials/glossy_mat.cc
  3. +2 −2 src/materials/shinydiff.cc
@@ -142,12 +142,12 @@ float coatedGlossyMat_t::OrenNayar(const vector3d_t &wi, const vector3d_t &wo, c
if(cos_to >= cos_ti)
{
sin_alpha = fSqrt(1.f - cos_ti*cos_ti);
- tan_beta = fSqrt(1.f - cos_to*cos_to) / cos_to;
+ tan_beta = fSqrt(1.f - cos_to*cos_to) / (cos_to == 0.f)?1e-8f:cos_to; // white (black on windows) dots fix for oren-nayar, could happen with bad normals
}
else
{
sin_alpha = fSqrt(1.f - cos_to*cos_to);
- tan_beta = fSqrt(1.f - cos_ti*cos_ti) / cos_ti;
+ tan_beta = fSqrt(1.f - cos_ti*cos_ti) / (cos_ti == 0.f)?1e-8f:cos_ti; // white (black on windows) dots fix for oren-nayar, could happen with bad normals
}
return orenA + orenB * maxcos_f * sin_alpha * tan_beta;
@@ -120,12 +120,12 @@ float glossyMat_t::OrenNayar(const vector3d_t &wi, const vector3d_t &wo, const v
if(cos_to >= cos_ti)
{
sin_alpha = fSqrt(1.f - cos_ti*cos_ti);
- tan_beta = fSqrt(1.f - cos_to*cos_to) / cos_to;
+ tan_beta = fSqrt(1.f - cos_to*cos_to) / (cos_to == 0.f)?1e-8f:cos_to; // white (black on windows) dots fix for oren-nayar, could happen with bad normals
}
else
{
sin_alpha = fSqrt(1.f - cos_to*cos_to);
- tan_beta = fSqrt(1.f - cos_ti*cos_ti) / cos_ti;
+ tan_beta = fSqrt(1.f - cos_ti*cos_ti) / (cos_ti == 0.f)?1e-8f:cos_ti; // white (black on windows) dots fix for oren-nayar, could happen with bad normals
}
return orenA + orenB * maxcos_f * sin_alpha * tan_beta;
@@ -192,12 +192,12 @@ CFLOAT shinyDiffuseMat_t::OrenNayar(const vector3d_t &wi, const vector3d_t &wo,
if(cos_to >= cos_ti)
{
sin_alpha = fSqrt(1.f - cos_ti*cos_ti);
- tan_beta = fSqrt(1.f - cos_to*cos_to) / cos_to;
+ tan_beta = fSqrt(1.f - cos_to*cos_to) / (cos_to == 0.f)?1e-8f:cos_to; // white (black on windows) dots fix for oren-nayar, could happen with bad normals
}
else
{
sin_alpha = fSqrt(1.f - cos_to*cos_to);
- tan_beta = fSqrt(1.f - cos_ti*cos_ti) / cos_ti;
+ tan_beta = fSqrt(1.f - cos_ti*cos_ti) / (cos_ti == 0.f)?1e-8f:cos_ti; // white (black on windows) dots fix for oren-nayar, could happen with bad normals
}
return A + B * maxcos_f * sin_alpha * tan_beta;

1 comment on commit bcc58f3

@ghost

ghost commented on bcc58f3 Mar 3, 2012

Nice catch Olaf

Please sign in to comment.