Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Direction of normals associated to new vertices

  1. #1
    Advanced Member Frequent Contributor
    Join Date
    Dec 2005
    Location
    Italy
    Posts
    656

    Direction of normals associated to new vertices

    Hi All,

    Here is the problem definition:

    Suppose you have a Quad face with a different normal for each vertex. Now we cut it because of a boolean operation. How shall we compute the new vertices normals? We are already using the face normal but the result is very unpleasant.

    Is there a way to compute the contribuition of each original normal at the new vertex position and get a good guess?

    The data available is of course the vertices position in 3D, the 4 original normal vectors and the face normal.



    Thanks in advance,

    Alberto

  2. #2
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Location
    Watford, UK
    Posts
    1,261

    Re: Direction of normals associated to new vertices

    You'll later need code that does the same for texcoords and vtx-varyings, so a more general solution might be nicer from the beginning. Barycentric coordinates? Some helping Maths can be found in the nVidia presentation of correct gl_quad interpolation via geometry-shaders.
    Also, I vaguely remember some Gradients maths from university, that handles this.

  3. #3
    Advanced Member Frequent Contributor
    Join Date
    Dec 2005
    Location
    Italy
    Posts
    656

    Re: Direction of normals associated to new vertices

    Hi Ilian,

    No, no need for texCoords yet, they are applied automatically later.

    Isn't is the same problem of finding the pixel color of the following -famous- OpenGL triangle?



    If I knew how to compute the pixel color here I could also guess the normal everywhere in the surface above.


    Thanks,

    Alberto

  4. #4
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Location
    Watford, UK
    Posts
    1,261

    Re: Direction of normals associated to new vertices

    Interpolating a value across a triangle is really simple:
    1) transform the verts so that z=0 on each (move "camera" to look head-on onto the triangle). Now you have have 2D triangle that isn't degenerate (unless the input was degenerate).
    2) split the triangle into 2 triangles, the division is a horizontal line that starts from the middle-Y vertex.
    3) for each of the 2 triangles (one pointing up, another pointing down):
    3.1) interpolate values linearly across edges, for "Y scanline". Interpolate linearly the two scanline-results by X value. => output result.


    But as nVidia's paper shows, we can't just split quads and N-gons into triangles and expect nice interpolations.

  5. #5
    Advanced Member Frequent Contributor
    Join Date
    Dec 2005
    Location
    Italy
    Posts
    656

    Re: Direction of normals associated to new vertices

    Ilian,

    Unfortuantely we need to work in 3D not on screen space.

    Is it not like drawing the color picker surface as in the picture below:



    In this case only three colors are involved but maybe it can be done also with four...

    Thanks,

    Alberto

  6. #6
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Location
    Watford, UK
    Posts
    1,261

    Re: Direction of normals associated to new vertices

    The method I gave for triangle-interp is rather 3D . The use of 'scanline' terms was just to help cross-reference with rasterizers .

  7. #7
    Junior Member Regular Contributor
    Join Date
    Apr 2001
    Posts
    181

    Re: Direction of normals associated to new vertices

    The normal approach would be to use Phong normal interpolation. It's essentially using linear interpolation of the vertex normals, which is then normalized. You can read up on it here: http://local.wasp.uwa.edu.au/~pbourk...interpolation/


  8. #8
    Advanced Member Frequent Contributor
    Join Date
    Dec 2005
    Location
    Italy
    Posts
    656

    Re: Direction of normals associated to new vertices

    Wow Lord, at the first sight it looks exactly what we were looking for.

    Leave me the time to read it carefully.

    Thanks,

    Alberto

  9. #9
    Advanced Member Frequent Contributor
    Join Date
    Dec 2005
    Location
    Italy
    Posts
    656

    Re: Direction of normals associated to new vertices

    Hi Lord,

    Yes, it is exactly what we were looking for.

    One point is by the way not clear to me in the suggested doc ( http://local.wasp.uwa.edu.au/~pbourk...interpolation/):

    "One way is to choose a major axis by specifying a normal. The plane with this normal that passes though the point in question cuts two of the polygon edges, this is used as the extended line"

    If I understand well we need to chose a plane to split two opposite Quad edges and get two new normals in these points.

    How shall we chose this plane?

    Thanks,

    Alberto

  10. #10
    Junior Member Regular Contributor
    Join Date
    Apr 2001
    Posts
    181

    Re: Direction of normals associated to new vertices

    I must admit I've only used the barycentric version of this method. The way I interpret that passage is that you pick one of the normals consistently for all points P within the quad. Which normal you pick is arbitrary, but it should be the same for all points within the quad. Then you construct a plane with that normal, going through the point in question P. This plane then intersects two edges, and these edges should be used for the initial interpolation.

    Please note the final remark, ie you should normalize after interpolating between the initial edges, then again after you interpolate between those two "edge-point normals". I incorrectly stated only to do the latter step.

Posting Permissions

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