View Full Version : Emulating OpenGL Normals Calculation

Glex1

08-06-2008, 05:39 AM

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

glShadeModel is set to GL_SMOOTH.

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. =)

satan

08-06-2008, 06:24 AM

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?

jwatte

08-06-2008, 09:09 AM

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.

Glex1

08-06-2008, 01:07 PM

jwatte,

Thanks a lot!

About barycentric coords:

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?

dletozeun

08-07-2008, 01:22 AM

Yes

ZbuffeR

08-07-2008, 07:51 PM

Yes but you may need to renormalize the interpolated normal.

Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.