Results 1 to 3 of 3

Thread: Color/normal interpolation artifact with triangles

  1. #1
    Newbie Newbie
    Join Date
    Jan 2019
    Posts
    1

    Color/normal interpolation artifact with triangles

    Hi all, my project has a lot of quads represented with 2 triangles and I'm getting some unsightly seams with color and normal interpolation. I figured I may as well see if there's a quick fix, but based on what I've seen from Google I may just need to store these attributes differently or even add more faces to smooth things out.

    Here we see an example with color on a simple quad. I want to eliminate the clearly visible diagonal, though it may be a "human eye" thing. I remembered barycentric coordinates from graphics class a few years ago but I feel the shader pipeline does that correctly, so probably not related to this issue.
    cap1.jpg

    Here is an example with the Phong reflection model exponent set way high. This time it's the normals that are not quite right.
    cap2.jpg

    So, to smooth things out am I right in suspecting I will just have to subdivide more until there's enough points to make it unnoticeable? Or is it likely I've messed something up? I'll be happy to post any code if needed.

  2. #2
    Senior Member Regular Contributor
    Join Date
    Oct 2014
    Posts
    112
    You have a continuity problem based on the triangle interpolation. The following statements are not necessarily true for all interpolation models, but should be for the basic linear interpolations done by the GPU:

    If you have a triangle with 3 colours at the nodes, than each node will contribute to the final colour as long as you are not on the boundary. If you are on the boundary, only the 2 nodes that form that boundary will contribute.
    If you have a rectangle with 4 colours at the nodes, than each node will contribute to the final colour as long as you are not on the boundary. If you are on the boundary, only the 2 nodes that form that boundary will contribute.

    Comparing these two statements gives the following conclusion:

    If you split up a rectangle into two triangles, the interpolated values on the outer boundaries stay the same. However, the surface in each triangle is only interpolated with 3 values instead of 4. Additionally you create another boundary (the diagonal), which means that you interpolate only two points there, while the rectangle uses 4. So in your picture the diagonal values are only composed of green and blue instead of red, green, black and blue. The same problem holds for the normal interpolation.

    As said before, this is a continuity problem. The interpolation you (or the GPU) use has C0 continuity. This means that if you would do a mathematical plot of the interpolated values the resulting curve has no gaps/jumps in it, but it might contain visible kinks (located were the boundaries are) because its first derivative can have gaps/jumps. Its like a car that drives with 10km/h and its speed suddenly jumps to 30km/h with no acceleration phase in between as soon as it passes the boundary. Even though its position (C0) does not jump, its velocity (C1) does which would result in a kink in a time-position plot.


    So how to solve that?

    The best solution would be to use an interpolation that is C1 contiguous. This can normally be achieved with splines/NURBS. I am not sure if this is possible here, since it requires higher order interpolations of triangles, which is not possible to my knowledge. Maybe one of the more experienced users can give a statement on that (Curious if it is possible in Vulkan...).
    The second possibility woul be to use higher order triangle interpolation without splines/NURBS, but the same question as before remains.
    The third and last option I know is to simply subdivide your mesh (as you suggested), until the the kinks are barely noticeable.

    The combination of the second and third solution is known as h-p-refinement in case you want to know more about it.

    Hope I could help you a little to understand what's going on.

    Greetings

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    3,105
    Quote Originally Posted by deadbeef View Post
    So, to smooth things out am I right in suspecting I will just have to subdivide more until there's enough points to make it unnoticeable? Or is it likely I've messed something up?
    Hard to say.

    Interpolating normals then performing normalisation and a dot product for each fragment (Phong shading) will give better results than calculating colours at the vertices and interpolating colours (Gouraud shading). More vertices will give better results than fewer vertices. If you're calculating vertex normals from face normals, averaging un-normalised face normals (so the weight is proportional to the area of the face) will give better results than normalising the face normals prior to averaging. If the vertices are obtained by sampling a smooth surface, calculating the normals from the surface's derivatives will be better than calculating them from the sampled mesh. Also, vertex normals don't need to have unit length; you can scale them in proportion to their weight (which should be inversely proportional to the curvature at the vertex).

Similar Threads

  1. GL_SMOOTH interpolation causes highlights on edges of triangles
    By zaphara in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-03-2013, 08:11 PM
  2. Color Interpolation
    By shezad in forum OpenGL: GLSL
    Replies: 0
    Last Post: 08-30-2012, 05:41 AM
  3. color interpolation
    By ugluk in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 07-14-2010, 12:26 AM
  4. color interpolation
    By jyoung77 in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 03-12-2007, 08:04 PM
  5. normal interpolation in rasterization
    By thinks in forum OpenGL: GLSL
    Replies: 2
    Last Post: 04-08-2005, 01:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean