Author Topic: Three strange problems in pixel  (Read 7555 times)

xushunwang

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Three strange problems in pixel
« on: May 07, 2014, 10:28:53 PM »
I'm using ngui 3.0.8 f1.
Sorry for that I don't know how to insert pictures in my text using my attachments

1、
I used a bitmap font in some labels but i find it have something wrong.

see:bitmap_font_1.jpg
see:bitmap_font_2.jpg

Words are not positioned the same in y axis in my pc.

But I found they are positioned right in mac .

see:bitmap_font_right.png

2、
My map are makd up of 5 * 8 grids.Every grid is 40 * 40 size.
I position them like this:

  1.  for (int row = 0; row < 5; row++)
  2.   {
  3.             for (int col = 0; col < 8; col++)
  4.             {
  5.  
  6.                 //generate grids
  7.  
  8.                 grid.transform.localPosition = new Vector3(startX + 40 * row , startY  + 40 * col , 0);
  9.             }
  10. }
  11.  
  12.  

In some resolution or pc(I'm not sure which affects) , It displayed well.

see:no_gap.jpg

But sometimes it displayed with gaps:

see:gap.jpg
3、
I used a sliced sprite in my game

see:sliced.jpg

But sometimes it displayed with some distortions at the edge of the sprite

see:distorted.jpg

sometimes it displayed well

see:no_distorted.jpg


 
« Last Edit: May 07, 2014, 10:38:19 PM by xushunwang »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Three strange problems in pixel
« Reply #1 on: May 08, 2014, 02:51:04 AM »
I'm sorry but 3.0.8 is very old, and you should update to the latest before posting about issues.

xushunwang

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: Three strange problems in pixel
« Reply #2 on: May 19, 2014, 10:39:40 PM »
Hey , I upgrade my ngui to version 3.5.9 and I find it's the same !

I set UIRoot scalingStyle to fixedSize and manual Height 384.

It will happen  when I scale the game view to 1024*768.

one pixel gap in my map,see:gap_1.jpg

and I replace the grid sprite using another one in the same atlas,see:gap_2.jpg
there is no gap
« Last Edit: May 19, 2014, 10:52:55 PM by xushunwang »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Three strange problems in pixel
« Reply #3 on: May 20, 2014, 01:19:53 PM »
Such gap can be caused by either texture filtering or by using a sprite that has dimensions that are not dividable by 2.

The fix for the former is to add a border to your sprite by editing the sprite (click the Edit button). After giving it a border you can also use Advanced sprite drawing option and turning off everything except center.

xushunwang

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: Three strange problems in pixel
« Reply #4 on: May 20, 2014, 09:45:48 PM »
Such gap can be caused by either texture filtering or by using a sprite that has dimensions that are not dividable by 2.

The fix for the former is to add a border to your sprite by editing the sprite (click the Edit button). After giving it a border you can also use Advanced sprite drawing option and turning off everything except center.

I tried this but it's the same.I set all my texture type "GUI" and filter Mode Point and the grid sprite is 40*40 .

I suspect if it due to the atlas.If I use UITexture , they are fine, but if I use UISprite and get texture from the atlas , the problem happened.

Here is my test scene . You can see the gap problem inthe gridPanel and other two problems in fontPanel.

 
 

xushunwang

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: Three strange problems in pixel
« Reply #5 on: May 20, 2014, 09:51:20 PM »
I tried this but it's the same.I set all my texture type "GUI" and filter Mode Point and the grid sprite is 40*40 .

I suspect if it due to the atlas.If I use UITexture , they are fine, but if I use UISprite and get texture from the atlas , the problem happened.

Here is my test scene . You can see the gap problem inthe gridPanel and other two problems in fontPanel.

 

Please turn on the "Maximize on Play" in Game window and set the Resolution to Standalone(1024*768).And it seems only happened in windows:-[
In Mac OS or IOS it displayed well.
« Last Edit: May 20, 2014, 10:16:20 PM by xushunwang »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Three strange problems in pixel
« Reply #6 on: May 21, 2014, 11:22:47 AM »
No visible gaps on my end, but my console log is full of errors because you put UISprites and UITextures on the same object.

Make sure your game window's dimensions are dividable by two. Generally when you use Maximize on Play, they often aren't. Although if you forced it to 1024x768 they should be.

In any case, if you want to eliminate such issues when zooming in / out (non-pixel perfect sprites), then you should give your sprite a border by editing the sprite within the atlas and clicking the "Add a Clamped Border" button. Just keep in mind that this adds +2 to your sprite's dimensions, so your 40x40 sprites will now be 42x42. You should then use Advanced type rather than Simple (chosen on UISprite), with left, right, top and bottom set to Invisible.

xushunwang

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: Three strange problems in pixel
« Reply #7 on: May 22, 2014, 02:21:22 AM »
No visible gaps on my end, but my console log is full of errors because you put UISprites and UITextures on the same object.

Make sure your game window's dimensions are dividable by two. Generally when you use Maximize on Play, they often aren't. Although if you forced it to 1024x768 they should be.

In any case, if you want to eliminate such issues when zooming in / out (non-pixel perfect sprites), then you should give your sprite a border by editing the sprite within the atlas and clicking the "Add a Clamped Border" button. Just keep in mind that this adds +2 to your sprite's dimensions, so your 40x40 sprites will now be 42x42. You should then use Advanced type rather than Simple (chosen on UISprite), with left, right, top and bottom set to Invisible.

It works! I can not see the gap any more .

But how to solve other two problems ? You can find them in fontPanel.

All the problems only appear in windows , are you using mac ?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Three strange problems in pixel
« Reply #8 on: May 22, 2014, 03:46:40 PM »
No, I use Windows. What dimensions do you see in the "Stats" window?

xushunwang

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: Three strange problems in pixel
« Reply #9 on: May 22, 2014, 09:05:56 PM »
No, I use Windows. What dimensions do you see in the "Stats" window?

It's 1024 * 768.
The background sprite is a sliced sprite.
The font is NGUI bitmap font.
My screen resolution is 1920 * 1080

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Three strange problems in pixel
« Reply #10 on: May 23, 2014, 03:47:55 PM »
Hmm... odd.

xushunwang

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: Three strange problems in pixel
« Reply #11 on: May 30, 2014, 02:38:31 AM »
Hey,I find a lot and finally find how to solve it.

It seems the "half pixel offset dx9" problem you said in the question:http://www.tasharen.com/forum/index.php?topic=8219.msg38954#msg38954

So I  check the optional "Use direct3d 11" on.Now they are all right!

But I don't want to use dx11 in my game because it may be bad for my performance.

Do you have any other ideas ?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Three strange problems in pixel
« Reply #12 on: May 30, 2014, 02:19:13 PM »
Using DX11 won't be bad for performance. It simply means your game will not run on older operating systems like Windows XP.

This is some issue with Point Filtering and DX9. Using anything other than Point Filtering, such as Trilinear fixes the problem.