<p>What would cause this grayscaled backside?</p>

<p><a href="https://i.sstatic.net/mkpo3.gif" rel="nofollow noreferrer"><img src="https://i.sstatic.net/mkpo3.gif" alt="enter image description here"></a></p>

<p>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)</p>

<pre><code>  // 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-&gt;GetViewDir()), mesh-&gt;mat-&gt;specularShine);    
  float spec2 = pow(MathHelper::Dot(r2, cam-&gt;GetViewDir()), mesh-&gt;mat-&gt;specularShine);
  float spec3 = pow(MathHelper::Dot(r3, cam-&gt;GetViewDir()), mesh-&gt;mat-&gt;specularShine);

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

  DrawBaryTriangle(screen, triangle, col1, col2, col3);
</code></pre>

<p>It's simply </p>

<pre><code>Diffuse Color * Sat(diffuseVal) + Specular Color * Sat(specularVal) + Ambient Color
</code></pre>

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

CC BY-SA 3.0
2017-05-05T10:17:14.290Z
Have you tried saturating the dot products before raising it to some power ? They should not go < 0
PaulHK
CC BY-SA 3.0
2017-05-05T10:26:43.137Z
@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
CC BY-SA 3.0
2017-05-09T06:25:20.790Z
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
CC BY-SA 3.0
2017-05-09T13:43:17.977Z
Have you tried regenerating your vertex normals to be sure they're accurate?
Jack
CC BY-SA 3.0
2017-05-09T13:57:31.543Z
It was the diff value. Needed to be saturated before calculating the reflectance vector.
Andrew Wilson
<rendering><shader><lighting>
Specular Highlight Gray When Behind Model
Andrew Wilson
# Specular Highlight Gray When Behind Model

(Asked by: username_0 on 2017-05-05)

What would cause this grayscaled backside?

[![enter image description here](https://i.sstatic.net/mkpo3.gif)](https://i.sstatic.net/mkpo3.gif)

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

**Tags:** rendering, shader, lighting

> **Comments:**
> **username_1**: Have you tried saturating the dot products before raising it to some power ? They should not go < 0  
> **username_0**: @username_1 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.  
> **username_1**: 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  
> **username_2**: Have you tried regenerating your vertex normals to be sure they're accurate?  
> **username_0**: It was the diff value. Needed to be saturated before calculating the reflectance vector.  

---

## 0 answers

