0
$\begingroup$

What would cause this grayscaled backside?

enter image description here

When my camera is behind my model I see a grayscale specular highlight. However, in front of it is perfectly fine. Here's my shading code. (Software rendering)

  // diffuse cosines
  float diffVal1 = MathHelper::Dot(n1, dirLight);
  float diffVal2 = MathHelper::Dot(n2, dirLight);
  float diffVal3 = MathHelper::Dot(n3, dirLight);

  // Get the specular shade
  // Reflectance vectors
  float3 r1 = dirLight - n1 * 2 * diffVal1;
  float3 r2 = dirLight - n2 * 2 * diffVal2;
  float3 r3 = dirLight - n3 * 2 * diffVal3;

  float spec1 = pow(MathHelper::Dot(r1, cam->GetViewDir()), mesh->mat->specularShine);    
  float spec2 = pow(MathHelper::Dot(r2, cam->GetViewDir()), mesh->mat->specularShine);
  float spec3 = pow(MathHelper::Dot(r3, cam->GetViewDir()), mesh->mat->specularShine);

  Color col1 = mesh->mat->diffuse * Utility::Saturate(diff1) + mesh->mat->specular * Utility::Saturate(spec1) + mesh->mat->ambient;
  Color col2 = mesh->mat->diffuse * Utility::Saturate(diff2) + mesh->mat->specular * Utility::Saturate(spec2) + mesh->mat->ambient;
  Color col3 = mesh->mat->diffuse * Utility::Saturate(diff3) + mesh->mat->specular * Utility::Saturate(spec3) + mesh->mat->ambient);

  DrawBaryTriangle(screen, triangle, col1, col2, col3);

It's simply

Diffuse Color * Sat(diffuseVal) + Specular Color * Sat(specularVal) + Ambient Color

Where Sat clamps any color values to [0, 255] and any scalars [0, 1].

$\endgroup$
5
  • $\begingroup$ Have you tried saturating the dot products before raising it to some power ? They should not go < 0 $\endgroup$
    – PaulHK
    Commented May 5, 2017 at 10:17
  • $\begingroup$ @PaulHK Just tried it and it didn't work. But there is the possibility the specular values are less than 0 when raising it to a power. $\endgroup$ Commented May 5, 2017 at 10:26
  • $\begingroup$ How about diffVal ? They also need saturating as they are used in your reflection calculation. I say this because it looks like your specular reflections are at N.L < 0 $\endgroup$
    – PaulHK
    Commented May 9, 2017 at 6:25
  • $\begingroup$ Have you tried regenerating your vertex normals to be sure they're accurate? $\endgroup$
    – Jack
    Commented May 9, 2017 at 13:43
  • $\begingroup$ It was the diff value. Needed to be saturated before calculating the reflectance vector. $\endgroup$ Commented May 9, 2017 at 13:57

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.