5

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));
}
Archmede
  • 481
  • 2
  • 7
  • 21
Will D
  • 115
  • 2
  • 5

1 Answers1

3

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.

Nathan Reed
  • 25,002
  • 2
  • 68
  • 107