# Thread: Emulating OpenGL Normals Calculation

1. ## Emulating OpenGL Normals Calculation

Imagine we have a triangle ABC with normals a, b, c.

The question is:
from OpenGL point of view, what is the normal to a point p inside a triangle?

Why do I need this:
I slice a triangle in two, but I want the picture to look exactly the same way as before slicing. This extra tesselation is required for sophisticated coloring, we develop 3D graphs plotter. =)

2. ## Re: Emulating OpenGL Normals Calculation

AFAIK there is no 'OpenGL normal' to a point inside the triangle. OpenGL just uses vertex normals and does not interpolate the normals when rendering with GL_SMOOTH but interpolates the color values of the lighting equation.
I don't understand why you cannot just calculate the interpolated or even the 'correct' normal and use that, as the result should be nearly the same as your original rendering and definitely more correct than OpenGLs color interpolation.
I also don't get why this is an advanced question?

3. ## Re: Emulating OpenGL Normals Calculation

from OpenGL point of view, what is the normal to a point p inside a triangle?
GL typically does Goraud shading, which means that the lighting equation is evaluated only at the vertices. This, in turn, means that you can't get perfect interpolation for tesselated vertices.

If you use a particular shader that interpolates normals and does lighting per pixel, then you can emulate the interpolation that that shader does. It's pretty common to use the barycentric coordinates and interpolate the normals based on that.

4. ## Re: Emulating OpenGL Normals Calculation

jwatte,
Thanks a lot!

If I have a point p and a triangle abc, and I know scalars k_1, k_2, k_3, such that:
p = a * k_1 + b * k_2 + c * k_3,
where k_1 + k_2 + k_3 = 1,
then the normal at p would be similar to
n(a) * k_1 + n(b) * k_2 + n(c) * k_3
(where n(p) denotes normal at point p)

Did I get it right?

Yes

6. ## Re: Emulating OpenGL Normals Calculation

Yes but you may need to renormalize the interpolated normal.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•