The footage pretty much shows the problem:
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.
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.
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?
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?
It is textured quads, I move this text by 0.01f each frame.
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);
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.
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.
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/library/windows/desktop/bb147229(v=vs.85).aspx
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)
Thanks for making it clear, but how is DX doing it I wonder, maybe I could replicate it in shader or something? I just don’t have any other way I guess, since I’m going for pixel graphics. =(
I don’t think Direct X is doing anything different.
Is your image being drawn 1:1 on the screen?
As opposed to being scaled up or down when drawn to the screen?
Sorry, tested out DX more closely, seems to be almost the same as with OpenGL. Thanks for the help I really appreciate it!