5
$\begingroup$

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));
}
$\endgroup$

1 Answer 1

3
$\begingroup$

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.

$\endgroup$
0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.