Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: Emulating OpenGL Normals Calculation

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2008
    Posts
    11

    Emulating OpenGL Normals Calculation

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

  2. #2
    Member Regular Contributor
    Join Date
    Feb 2002
    Posts
    377

    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. #3
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    2,704

    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.
    "If you can't afford to do something right,
    you'd better make sure you can afford to do it wrong!"

  4. #4
    Junior Member Newbie
    Join Date
    Aug 2008
    Posts
    11

    Re: Emulating OpenGL Normals Calculation

    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?

  5. #5
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,370

    Re: Emulating OpenGL Normals Calculation

    Yes

  6. #6
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,655

    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
  •