sdl-gpu icon indicating copy to clipboard operation
sdl-gpu copied to clipboard

Snapping is performed before scaling which produces flickering

Open zmeyc opened this issue 8 years ago • 2 comments

In tests/pixel-perfect/main.c I added camera.zoom = 0.5 and switched filtering to NEAREST by pressing 'f' (but the effect is observed without this as well).

When I move rectangles by 1.0 they flicker, i.e.: when y=0: 0-st, 2-nd, 4-th lines of the image are drawn when y=1: 1-st, 3-rd, 5-th lines are drawn when y=2: 0-st, 2-nd, 4-th lines are drawn and the image is moved down 1 pixel row

Am I right that snapping is applied before scaling? I think it would be better for pixel art games to apply snapping to the resulting vertices, i.e.: when y=0: 0-st, 2-nd, 4-th lines are drawn when y=1: 0-st, 2-nd, 4-th lines are drawn when y=2: 0-st, 2-nd, 4-th lines are drawn and image is moved down 1 pixel row etc

upd:

                float k = 1.0 / camera.zoom;
                float y_ = floorf((y + image->h/2) / k) * k;
                float x_ = floorf((x + image->w/2) / k) * k;
                GPU_Blit(image, NULL, screen, x_, y_);
                //GPU_Blit(image, NULL, screen, floorf(x + image->w/2), floorf(y + image->h/2));

I've tried disabling snap and rounding the values manually and this fixed the flickering. Should this be a separate snapping mode? For example, Oxygine has OXYGINE_NO_SUBPIXEL_RENDERING, Cocos also has a similar mode. http://oxygine.org/doc/api/_renderer_8h_source.html

zmeyc avatar Nov 15 '16 16:11 zmeyc

I'm not confident that the snapping code is really that good (I haven't given it any attention in a long time). If you do improve it, I'd appreciate a pull request. If not, I'll see how I can work this in when I have the chance.

grimfang4 avatar Nov 29 '16 14:11 grimfang4

I am having problems with pixel perfect scaling of textures and ended up here while searching for clues. Any news about this?

Thanks

beddueimpossibile avatar Oct 02 '21 10:10 beddueimpossibile