<p>Your first version was correct, except that <code>alpha</code> and <code>1-alpha</code> should be swapped (the result should be <code>a</code> when <code>alpha == 0</code> and <code>b</code> when <code>alpha == 1</code>). </p>

<p>For Phong shading, you <em>do</em> want to keep the normalize on the end; that's the key thing that makes Phong different from Gouraud shading. But also, normalize isn't part of the usual definition of "lerp" (linear interpolation), so I would keep it out of the <code>lerp</code> function, and move the normalize to the Phong shading function where you call <code>lerp</code>.</p>

CC BY-SA 3.0
2017-05-11T13:52:09.930Z
2017-05-11T13:52:09.930Z
Nathan Reed
<p>As the title says I have been trying to understand the normal interpolation for the Phong shading/lighting model. I am unsure of the equation to calculate the normal but I have come across this equation:</p>

<p>N=Na*α+Nb(1−α)</p>

<p>Where N is the interpolated vector, Na and Nb are unit vectors to interpolate between and I'm assuming α is the percentage between the two. However in using this model as shown here: </p>

<pre><code>public static Vector3 lerp(Vector3 a, Vector3 b, double alpha){
     return (a.multiply(alpha)).add(b.multiply(1-alpha)).normalize();
}
</code></pre>

<p>I am not obtaining the correct results, so any advice on the topic, such as what I may be doing wrong etc, would be appreciated.</p>

<p>EDIT: I found my mistake in the interpolation, here is the updated method for those who are interested:</p>

<pre><code>public static Vector3 lerp(Vector3 a, Vector3 b, double gradient){
    return a.add((b.minus(a)).multiply(gradient));
}
</code></pre>

<interpolation>
Normal Interpolation for Phong shading
Will D
# Normal Interpolation for Phong shading

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

As the title says I have been trying to understand the normal interpolation for the Phong shading/lighting model. I am unsure of the equation to calculate the normal but I have come across this equation:

N=Na\*α+Nb(1−α)

Where N is the interpolated vector, Na and Nb are unit vectors to interpolate between and I'm assuming α is the percentage between the two. However in using this model as shown here:

```
public static Vector3 lerp(Vector3 a, Vector3 b, double alpha){
     return (a.multiply(alpha)).add(b.multiply(1-alpha)).normalize();
}

```

I am not obtaining the correct results, so any advice on the topic, such as what I may be doing wrong etc, would be appreciated.

EDIT: I found my mistake in the interpolation, here is the updated method for those who are interested:

```
public static Vector3 lerp(Vector3 a, Vector3 b, double gradient){
    return a.add((b.minus(a)).multiply(gradient));
}

```

**Tags:** interpolation


---

## 1 answers

### Answer by username_1 on 2017-05-11. Score: 3 | Accepted answer

Your first version was correct, except that `alpha` and `1-alpha` should be swapped (the result should be `a` when `alpha == 0` and `b` when `alpha == 1`).

For Phong shading, you *do* want to keep the normalize on the end; that's the key thing that makes Phong different from Gouraud shading. But also, normalize isn't part of the usual definition of "lerp" (linear interpolation), so I would keep it out of the `lerp` function, and move the normalize to the Phong shading function where you call `lerp`.


---

