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 13

Thread: Choppy movement with floats

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2012
    Posts
    12

    Choppy movement with floats

    The footage pretty much shows the problem:
    http://www.youtube.com/watch?v=cOKF3jj-sPI

    When I move text slower than a pixel at a time, it doesn't move in subpixels, instead it jumps from pixel to pixel. How can I fix that?
    I searched for days, still nothing that could help me with that.
    Let me know if I need to show code of some part, I can upload everything, but it'll be a lot to fit in here.

    Thanks for the help in advance, hope it will resolve.

  2. #2
    Member Regular Contributor malexander's Avatar
    Join Date
    Aug 2009
    Location
    Ontario
    Posts
    324
    Use a multisampled buffer. This will give you sub-pixel coverage, and smooth out the rasterization of your text. The higher the number of samples, the smoother it will become.

    Alternatively, you can make the quad 1 pixel larger in each direction, compute the floating point position in screen coordinates where it should appear, and then compare that to the actual GL coords using gl_FragCoord.xy. Use the difference to adjust your texture coordinates.

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2012
    Posts
    12
    Thanks for reply, I'm a little concerned about multisampling (performance wise), because DirectX doesn't use it and it has smooth movement out of the box, but OpenGL is not?
    Last edited by SoulSharer; 11-23-2012 at 09:57 AM.

  4. #4
    Junior Member Regular Contributor
    Join Date
    Oct 2007
    Location
    Phoenix, AZ
    Posts
    109
    Can you explain what you are actually doing?
    Is the text in that video a raster image that you are drawing as a textured quad?
    Or are the letters a bunch of 3d geometric shapes?

  5. #5
    Junior Member Newbie
    Join Date
    Nov 2012
    Posts
    12
    It is textured quads, I move this text by 0.01f each frame.
    Last edited by SoulSharer; 11-23-2012 at 11:19 AM.

  6. #6
    Junior Member Regular Contributor
    Join Date
    Oct 2007
    Location
    Phoenix, AZ
    Posts
    109
    I just did a test and while the edge of a textured quad is not anti-aliased and will pop pixel to pixel, the texture pixels move smoothly with sub-pixel accuracy.

    Are you enabling bi-linear filtering?

    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);

  7. #7
    Junior Member Newbie
    Join Date
    Nov 2012
    Posts
    12
    I'm using GL_NEAREST, because GL_LINEAR is not what I'm looking for, it makes texture blurry. I want something like D3DTEXF_POINT (DX), it is smooth and have a nearest filtering. Exactly what I need for pixel art and stuff.
    Thanks.

  8. #8
    Junior Member Regular Contributor
    Join Date
    Oct 2007
    Location
    Phoenix, AZ
    Posts
    109
    Can you verify that GL_LINEAR gives a smoother animation? In spite of how you feel about the fidelity.

    I don't see how something can use nearest-neighbor sampling and, at the same time, not pop.

  9. #9
    Junior Member Newbie
    Join Date
    Nov 2012
    Posts
    12
    Yeah linear does look smooth, though blurry. =(

    And in Direct3D9/10/11 it is nearest with smooth movements
    I dunno if that will help, but here is documentation about it: http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx

  10. #10
    Junior Member Regular Contributor
    Join Date
    Oct 2007
    Location
    Phoenix, AZ
    Posts
    109
    What I mean is: You are seeing an unsightly "pop" when your text image animates (moves). Because 1 pixel from the source image is being drawn at a particular destination pixel one second; then it is drawn in a neighboring destination pixel the next second. That is the "pop". You are moving the texture 1/100th of a pixel on every draw, but the results don't show until you have crossed a mathematical threshold.

    That is the nature of nearest-neighbor sampling.
    That is the point of it.
    There is no sub-pixel distinction.
    A source pixel can either live in one destination pixel, or it's neighbor. It can't live in both.

    Living in both is what linear does.
    (20% in the first pixel, 80% in the second pixel)

Posting Permissions

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