# Specular Highlight Gray When Behind Model

What would cause this grayscaled backside?

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);

// 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].

• Have you tried saturating the dot products before raising it to some power ? They should not go < 0 – PaulHK May 5 '17 at 10:17
• @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. – Andrew Wilson May 5 '17 at 10:26
• 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 – PaulHK May 9 '17 at 6:25
• Have you tried regenerating your vertex normals to be sure they're accurate? – Jackalope May 9 '17 at 13:43
• It was the diff value. Needed to be saturated before calculating the reflectance vector. – Andrew Wilson May 9 '17 at 13:57