Results 1 to 3 of 3

Thread: Accuracy issues with vertex attribues interpolation

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2014
    Posts
    13

    Question Accuracy issues with vertex attribues interpolation

    Hello,

    I'm facing a problem with attribute values received in shaders not corresponding to what I'm giving them as input. I've been pulling my hair over this for two days so I hope somebody can help me figure this one out.
    Itís kind of hard to explain so I'll just show you what I do.
    Consider the following vertex shader:


    Code :
    out vec4 intensityInfo;
    in vec4 intensity;
     
    void main()
    {
        intensityInfo = intensity;
        gl_Position = ftransform();
    }


    and fragment shader:

    Code :
    in vec4 intensityInfo;
     
    void main()
    {
        if (intensityInfo.g > .9)
            gl_FragColor = vec4(1,1,1,1);
        else
            gl_FragColor = intensityInfo;
    }


    and a series of triangles being displayed with the following code:

    Code :
    // Assume 1 is the index of the attribute named intensity
    gl.glVertexAttrib4f(1, 0, 0, 0, 1);
    [snip: calculate vertex coordinates]
    gl.glVertex3f(x, y, z);
    gl.glVertexAttrib4f(1, 0, .8f, 0, 1);
    [snip: calculate vertex coordinates]
    gl.glVertex3f(x, y, z);
    gl.glVertexAttrib4f(1, 0, .8f, 0, 1);
    [snip: calculate vertex coordinates]
    gl.glVertex3f(x, y, z);


    Now, in theory, the condition intensityInfo.g > .9 in the fragment shader should never be true, since the values I pass into the vertex attributes for the green component range from 0 to 0.8. However, sometimes they do! I'd like to know why, and how to prevent it because it's keeping my shader from giving the result I'm going for.

    The interresting thing is that this happens only when the triangle is close to being perpendicular to the view, as illustrated by these two pictures of a series of triangles:





    As you can see, the polygons that are far away and almost perpendicular to the view contain white/grey pixels, when in theory there shouldn't be anything else than green-black gradient.

    Any help would be appreciated!

    (Not sure if it matters, but Iím developing in Java with JOGL)

  2. #2
    Senior Member Frequent Contributor arekkusu's Avatar
    Join Date
    Nov 2003
    Posts
    891
    Attributes may be extrapolated (not interpolated) outside the triangle when:
    * you use multisampling without centroid interpolation (from your screenshots, this looks like the issue...)
    * "helper" pixels in a 2x2 quad fragment are evaluated outside the triangle (doesn't affect your simple example...)

  3. #3
    Junior Member Newbie
    Join Date
    Aug 2014
    Posts
    13
    Excellent! Thank you!

Similar Threads

  1. Replies: 3
    Last Post: 10-04-2016, 06:15 AM
  2. Vertex interpolation in a shader - how?
    By Nikki_k in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 06-19-2014, 02:15 PM
  3. Vertex shader interpolation is weird
    By tsnwp in forum OpenGL: GLSL
    Replies: 5
    Last Post: 07-02-2010, 12:09 PM
  4. Texture interpolation with vertex buffers
    By misaaak in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 06-25-2008, 02:15 AM
  5. Vertex programs - About keyframe interpolation
    By Obli in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 04-15-2003, 03:05 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