Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: soulburner on December 06, 2014, 09:04:31 AM

Title: Disabling DirectX 11 makes picture fuzzy
Post by: soulburner on December 06, 2014, 09:04:31 AM
Here's a short reproduction:

That's it.

Then, switching DirectX 11 in Build Settings->Player Settings will turn bug on and off.

In my case I'm using a sharp checkboard texture.

It is perfectly OK in DX11 is on.

But when I switch it off, I get this:

(http://habrastorage.org/files/db0/7e8/e0e/db07e8e0e2a444e2ab0c25473b4151ec.png)

The lower-right triangle is OK, but the top-left one is broken.

I'm confused. Its OK with any other height I set: 720, 180, 90, etc. But when I set height just 50% of my window size, I get this.

I can't change the resolution of my project. It should be exactly x2-pixel-size at 1280x720 resolution.
Title: Re: Disabling DirectX 11 makes picture fuzzy
Post by: soulburner on December 06, 2014, 09:29:35 AM
PS: Dividing UI Root height by 2 and setting it to 180 and setting UI Camera size to 2 fixed the issue.

But that's very strange anyway.

Seems like the reason is floating point numbers somewhere in the engine...


PS: Nope, that didn't fix the issue in all cases. In some rare cases I still have sprite fuzzyness.
Title: Re: Disabling DirectX 11 makes picture fuzzy
Post by: Nicki on December 06, 2014, 09:18:21 PM
Isn't that perhaps just the DX9 half pixel offset? Try to move a parent game object by 0.5 on either axis and see if that helps.

see more http://drilian.com/2008/11/25/understanding-half-pixel-and-half-texel-offsets/
Title: Re: Disabling DirectX 11 makes picture fuzzy
Post by: ArenMook on December 06, 2014, 10:29:37 PM
Constrained root = UI will never be pixel perfect to begin with.

After switching from DX9 to DX11 or vice versa you need to hit Play to refresh the changes.
Title: Re: Disabling DirectX 11 makes picture fuzzy
Post by: soulburner on December 07, 2014, 06:21:53 AM
Isn't that perhaps just the DX9 half pixel offset? Try to move a parent game object by 0.5 on either axis and see if that helps.

see more http://drilian.com/2008/11/25/understanding-half-pixel-and-half-texel-offsets/
No, that is not related to half-pixel offset. That was my 1st guess and I tried to move the camera with no result.
Title: Re: Disabling DirectX 11 makes picture fuzzy
Post by: soulburner on December 07, 2014, 06:27:46 AM
Constrained root = UI will never be pixel perfect to begin with.
So, what's the solution?

I've got GUI drawn in 640x360. So, I want it to be pixel-perfect in two resolutions: 1280x720 (exactly x2) and FullHD (exactly x3)

After switching from DX9 to DX11 or vice versa you need to hit Play to refresh the changes.
When I tick DX11 checkbox the window with apply settings appear. The picture changes after I click "Apply" button. Further pressing "play" doesn't change anything.
Title: Re: Disabling DirectX 11 makes picture fuzzy
Post by: soulburner on December 09, 2014, 12:27:55 AM
Any ideas?

Here's the example project (you need to import NGUI for yourself): https://www.dropbox.com/s/ipx07yyt3y0c0rd/NGUI_bug.zip?dl=0
Title: Re: Disabling DirectX 11 makes picture fuzzy
Post by: ArenMook on December 09, 2014, 01:50:58 PM
Pixel perfect means it corresponds to actual pixels on the screen 1:1. What you are trying to do is not pixel perfect by definition. I'm not sure what solution you are looking for here. As I mentioned, after changing from DX9 to DX11 and vice versa you need to actually hit Play for the changes to take effect properly.
Title: Re: Disabling DirectX 11 makes picture fuzzy
Post by: soulburner on December 10, 2014, 05:36:01 AM
Pixel perfect means it corresponds to actual pixels on the screen 1:1. What you are trying to do is not pixel perfect by definition. I'm not sure what solution you are looking for here. As I mentioned, after changing from DX9 to DX11 and vice versa you need to actually hit Play for the changes to take effect properly.
I'm getting fuzzy pictures (as an image in the 1st post shows) in the described situation in DX9 mode. No matter - in editor, in play mode or in compiled .exe
Title: Re: Disabling DirectX 11 makes picture fuzzy
Post by: ArenMook on December 11, 2014, 08:44:26 AM
Of course you do. And I've mentioned it twice already. Constrained = not pixel perfect.

Want crispness? Use a Flexible UIRoot.
Title: Re: Disabling DirectX 11 makes picture fuzzy
Post by: soulburner on December 12, 2014, 03:32:54 AM
Sorry for misunderstanding, but what's the solution?

I've tried to use Flexible or Constrained modes. The result is always the same when the screen resolution is 720 height and my GUI height is exactly 1/2 of it.

I thought I have a simple situation - I've got a GUI drawn in 640x360 and I want it to be exactly double-pixel in 1280x720.

The best solution I have for now is set constrained height mode with height = 18, and camera size = 20. In this mode I've got the minimum amount of artefacts, but still got some.
Title: Re: Disabling DirectX 11 makes picture fuzzy
Post by: ArenMook on December 12, 2014, 11:34:22 PM
I just did a test.

1. New scene.
2. ALT+SHIFT+S to create a sprite, set to tiled, overlay the whole screen. This also created the UI that defaulted to flexible style.
3. Double-checked the game window, made sure its using even dimensions (1600x900 in my case). Using odd dimensions that don't divide by two cleanly = problems.
4. Sprite is crisp.
5. Switched to DX11, hit Play to refresh. Sprite is still crisp.
Title: Re: Disabling DirectX 11 makes picture fuzzy
Post by: soulburner on December 17, 2014, 12:13:38 PM
I just did a test.

1. New scene.
2. ALT+SHIFT+S to create a sprite, set to tiled, overlay the whole screen. This also created the UI that defaulted to flexible style.
3. Double-checked the game window, made sure its using even dimensions (1600x900 in my case). Using odd dimensions that don't divide by two cleanly = problems.
4. Sprite is crisp.
5. Switched to DX11, hit Play to refresh. Sprite is still crisp.

I just did it too.

1. New scene, imported my GFX (in point filter mode) http://gyazo.com/c0028cd07f40de3490bf14d205f39bce
2. ALT+SHIFT+D (Unity 2D Sprite!!), set the sprite, clicked "Snap", no tiling
3. Used my dimension (1600x900 doesn't have a bug): game window 1280x720, flexible max/min height = 360 (exactly divided by 2)
4. Hit play, no problems
5. Switch DX11 off, hit play

problems:

http://gyazo.com/638734e18cc8a86dd4c9312f039f1f27

sprite settings: http://gyazo.com/f9b014f04ffdd2b855f23e7424ef6f29
sprite png itself: http://gyazo.com/0c9dcef2960d656e89e92022163215d5
Title: Re: Disabling DirectX 11 makes picture fuzzy
Post by: ArenMook on December 17, 2014, 03:26:34 PM
Flexible set to min/max of 360 is the same exact thing as using Constrained = not pixel perfect.
Title: Re: Disabling DirectX 11 makes picture fuzzy
Post by: soulburner on December 18, 2014, 02:57:33 AM
Then I don't understand  :(

So, I need my GUI to be excactly double-sized pixel-perfect in 1280x720 resolution. How do I make it? What settings should I set? Other resolutions don't matter.
Title: Re: Disabling DirectX 11 makes picture fuzzy
Post by: ArenMook on December 19, 2014, 07:41:12 AM
As I mentioned in a previous post:
Pixel perfect means it corresponds to actual pixels on the screen 1:1. What you are trying to do is not pixel perfect by definition.
I'm going to assume that what you want is simply have 1 virtual pixel be a 2x2 on-screen pixel. This isn't pixel perfect, but I assume you simply got your terminology wrong. Open up UICamera.cs, find the drawCallOffset property on line 315:
  1. float mod = (1f / size.y) / mCam.orthographicSize;
You will want to change this to:
  1. float pixelSize = (root != null) ? root.pixelSizeAdjustment : 1f;
  2. float mod = (pixelSize / size.y) / mCam.orthographicSize;
Title: Re: Disabling DirectX 11 makes picture fuzzy
Post by: soulburner on December 19, 2014, 09:00:52 AM
Thank you. I'll try to.

Yes, I want my 1x1 pixel on the art to be exactly 2x2 pixel on the screen. And to have no sprite breaks.
Title: Re: Disabling DirectX 11 makes picture fuzzy
Post by: soulburner on December 20, 2014, 11:32:41 AM
Thank you again! I've applied your code and atrefacts seem to be gone.

PS: the source code was UIPanel.cs, btw ;)