HaxeFlixel / flixel

Free, cross-platform 2D game engine powered by Haxe and OpenFL
https://haxeflixel.com/
MIT License
1.96k stars 432 forks source link

Strange antialiasing glitch for outlined image on native platforms. #1401

Closed iam-jim closed 9 years ago

iam-jim commented 9 years ago

Today I noticed a strange bug for outlined image. This is noticeable in native platform, flash is okay. I have made a sample image to reproduce this bug. Here is the sample image outline-test

Load this image in a hello world project, and you will notice this

2014-12-10 01_21_45-test

Scaling would make this bug more visible,

2014-12-10 01_22_18-test Look at the bottom of the square.

It happens if antialiasing is set to false, which is the default case.

I am using latest version of everything.

Gama11 commented 9 years ago

Can you provide the code to reproduce this?

sruloart commented 9 years ago

I can't reproduce this with this image / or with this code.

iam-jim commented 9 years ago

var temp = new FlxSprite(); temp.loadGraphic(AssetPaths.outline_test__png); temp.scale.set(3, 3); add(temp);

Gama11 commented 9 years ago

@solewalker And the asset?

iam-jim commented 9 years ago

The project is uploaded here, build for neko or windows. I have run, haxelib upgrade, so I have latest lime, openfl and I am using git version of flixel and other flixel stuffs. https://drive.google.com/viewerng/viewer?a=v&pid=forums&srcid=MTQ4NTIxMzQ5MTk4ODYxODkyNzABMDQwNTMyMTI0MTg3NTUwMDUzNzEBYzRxNFFBaEVHVU1KATAuMQEBdjI

Tiago-Ling commented 9 years ago

I can confirm this happens in cpp and neko, i did some investigation on the issue and also on the sprite jittering some time ago. Maybe this repo helps, it has an example showing the same problem (which happens even without scaling):

https://github.com/Tiago-Ling/FlixelRenderProblemDemo

iam-jim commented 9 years ago

This problem is more apparent if image size is uneven, like if I use the image of size 217x121, I see this problem, but if I use 216x120 or 218x122, problem never happens. And it's not about the actual image size but frame size. Even if my image is packed in 512x512 sprite-sheet it does not matter.

sruloart commented 9 years ago

Hmm...it does sound like the same issue. Weird I can't reproduce this. My guess would be something to do with the video-card drivers. @solewalker @Tiago-Ling what's your hardware and os?

Tiago-Ling commented 9 years ago

Yeah, the same thing happens to me (also explained in the repo link i posted above). While his is solved by setting antialising as true, this is a very problematic issue.

@sruloart Could you please try @solewalker or my project and see if this happens for you?

I get this problem on various machines, i don't think hardware or OS has anything to do with this, but here goes (my home pc):

Win 8 Pro x64
Core i7 950 @ 3.07Ghz
12GB DDR3
GeForce GTX 580

The same problem happens in 3 other pcs at work, i didn't test it in a Mac yet, but almost 100% it will happen there also - i'm positive this is a Flixel problem, there are various related issues, i linked some of them here: https://github.com/Tiago-Ling/FlixelRenderProblemDemo

iam-jim commented 9 years ago

I am on win 7 ultimate 64, core i5 3450 with on board graphic. This is definitely haxeflixel or openfl issue. As I have tried the same image with other engine. And no problem there.

sruloart commented 9 years ago

It doesn't happen to me with both projects (I mean the tearing not the jittering, but that's another issue), but it's not the hardware and it's not the os (I have a win 7(x64)/GTX as well)...So, my best guess is that you're building for native with corrupted OpenFL/Lime/HaxeFlixel libraries (or else I would've experienced the same problem, right?).

The catch is it's just a guess (because I can't reproduce this), and it might take a while to physically delete all of the OpenFL/Lime/HaxeFlixel libraries (don't use haxelib for that) and then to install all over again.

Tiago-Ling commented 9 years ago

@sruloart Are you using everything flixel, openfl and lime from the dev branch of their repos?

sruloart commented 9 years ago

No, I always install OpenFL/Lime official releases only (and with good reason, don't use their dev branches if you value your time). With Flixel it's a lot safer to use the dev branch, so I do.

Tiago-Ling commented 9 years ago

So this seems a Lime / OpenFL thing. Do you have the jittering problem?

sruloart commented 9 years ago

It's a jittering problem, not "the" (your) jittering problem.

sruloart commented 9 years ago

Try adding the "next" flag to your project.xml

Tiago-Ling commented 9 years ago

Sorry, i'm not a native speaker, sometimes i want to write fast and it becomes easy to make mistakes. However, this is a specific problem i'm referring to - "the" jittering problem that HaxeFlixel has for a long time. How should i refer to it? Please enlighten me.

I'll try with the -next flag, but it'll take some time. I'll post the results here later.

sruloart commented 9 years ago

Non-native speaker here as well! it's a miracle we can understand each other at all :D

Your ("The") jittering problem is related to floating point movement (actual tiny movements), but for me this kind of jittering is replaced with blurry rendering (at least on native), which is a reasonable fix. I still call it "The" jittering problem because it still happens on Flash / Html5 (and might not be fixable).

The ("a") jittering problem I'm referring to is the gpu tearing, i.e. when all the graphics move back a few pixels after a few frames, like they got rewind / stuck or something. Like I said, that is mostly because of the gpu, but it can be mitigated by some code tricks.

Tiago-Ling commented 9 years ago

I think "your" jittering and "my" jittering might be the same problem. Using dev both things happen to me: blurry movement (which is also ugly and a hack, not a fix imho) AND jittering (every few frames there are "hiccups" in the camera movement. Curiously this seems to be much more noticeable with individual FlxSprites.

Using the -next flag actually increased the jittering in neko - the hiccups are more frequent and also more intense. In cpp, no tearing and no jittering (i didn't test much, may be just luck), but the blurry movement still happens.

The tearing, as i understand is the problem @solewalker is having right? This apparently happens with the latest dev version only, since you couldn't reproduce it in your machine.

Anyway, these bugs, whatever the names we may call them are the biggest problems HaxeFlixel have right now imho. They make the framework look very unprofessional and hacky - we should join forces and get rid of them as soon as possible (ideally before the release of 4.0.0).

I asked @Beeblerox about it, he told me to look inside the draw method of FlxSprite. I tried a lot of stuff there and nothing i did made any difference - i think it might be related to camera scroll actually, what do you think?

sruloart commented 9 years ago

What I mean to say is that, yes, there are many more possible "solutions" to implement but at this point it's getting a little ridiculous. A "proper" fix would mean rewriting / rearranging / separating Flixel's core logic, and success is not guaranteed. At this point I'm just lowering the FPS and tweaking what I can.

Tiago-Ling commented 9 years ago

The problem is that using the dev branch the blurring fix is not preventing the "hiccups" anymore. So, we get the ugliness of the blur plus the stuttering every few frames.

I agree that it might require a a big refactor / rearrangement of the core api, but this will have to be done, sooner or later. This problem is a huge deal breaker - you can make your game in HaxeFlixel, but don't expect production quality, because we have this jittering / blurring / artifacts problem. I think that if we keep hiding it with workarounds and hacks it makes the problem even harder to identify and solve.

I know solving it will be no easy task, and might require a lot of effort from the core team, which knows how the framework stuff works better than anybody. I'm willing to provide all the help / assistance i can to contribute to the solution (i know i can't do this by myself, having no prior knowledge of the fixes already implemented and also where to look inside the core api for probable causes).

goshki commented 9 years ago

I've seen this problem in my games and it's been always caused by non-integer values in sprite position. Could you check if the problem persists if you round to position to an integer value?

Btw. I've seen this problem in pixel-perfect mobile games as well.

Tiago-Ling commented 9 years ago

Hi @goshki, rounding sprite positions does not change anything for me (i tried flooring the positions and also making every position an even number), but after reading your comment i disabled pixelPerfectRender and got the following results:

I'm wondering, as @sruloart said, if the blurring effect is a fix to mitigate these problems, is there a way to disable it? Where is the code responsible for that?

sruloart commented 9 years ago
Tiago-Ling commented 9 years ago

By reading your explanation and looking at the classes now i know that all rendering is done every frame by simply callling Tilesheet.drawTiles / drawTriangles. And since the "blurring" (let's call this specific problem blurring - the tiny consistent movements as you said) only happens with moving stuff, it looks like the problem is the difference in position for sprites at each frame. As i see it, there can be two possible cases for the blurring:

I definitely want to research this problem more and i am going to test the second case soon to see if pure OpenFL with drawTiles causes the same blurriness with moving Sprites.

By the way, thanks for the insights, they are really helping me to catch up with the previous discussions about this. :)

iam-jim commented 9 years ago

Also see this issue https://github.com/HaxeFlixel/flixel/issues/1402

Tiago-Ling commented 9 years ago

I've updated my repository with demos investigating these problems. I've also added a simpler and more controllable demo with binaries to facilitate download and testing in your machine. Please take a look:

FlxRenderProblem repository Demo Windows Binary - Right-click and "save as"

sruloart commented 9 years ago

For me, everything works as it should, unless the application loses its focus, i.e. when you move the cursor in and out of the game's window or when you try to maximize/minimize/move the actual window, the game would start to "hiccup" but a few seconds later would rebound back to smooth motion.

Tiago-Ling commented 9 years ago

@sruloart - Do you think you could compile the demo_b from my repository using your version of flixel and upload the binaries somewhere so i could compare the differences in rendering?

If the release version does not have the same problems as the latest dev version we can locate the cause of the problem - maybe we won't be able to fix it yet, but at least return it to same state it was in your version (if there is really any difference, that is).

Thanks!

sruloart commented 9 years ago

Sure: http://www.filedropper.com/flxrenderlime201 It does feel different.

iam-jim commented 9 years ago

Strange if I set FlxG.camera.pixelPerfectRender = false; I don't see this bug anymore. Setting pixelPerfectRender to true is creating so much problem, what is it really doing under the hood?

Tiago-Ling commented 9 years ago

@solewalker pixelPerfectRender is used to boost performance in blitting targets by flooring position values for objects seen through the camera.

As we have seen in #1402, pixelPerfectRender does have a lot of undesired side effects in Neko and cpp targets.

I also have noted that setting FlxG.camera.pixelPerfectRender = false does have different effect depending on the type of object - if you set pixelPerfectRender as false in your entire state, FlxSprite will jitter in a different pattern than FlxTileBlocks, FlxBackdrop and other objects which do not share the same drawing logic as FlxSprite.

I'll update my demos to try and show this problem - all the problems with artifacts and strange positioning seem to be tied to FlxSprite draw method.

iam-jim commented 9 years ago

I am not aware of flixel renderer but I know a bit about opengl based rendering. And some of the engines I used before has no such kind of pixel perfect rendering stuffs, or this kind of problem. But flixel is very fast to work with that's why I am sticking with this longer.

Tiago-Ling commented 9 years ago

This might be a problem in OpenFL / Lime renderer, not in HaxeFlixel - what i'm going to try is to reproduce the same conditions for the demo in pure OpenFL and see how it behaves: if it acts exactly like HaxeFlixel the problem might be there.