Hello Guest

Author Topic: 1 "Actual" pixel off?  (Read 5049 times)

Majicpanda

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 62
    • View Profile
1 "Actual" pixel off?
« on: March 03, 2014, 11:04:32 pm »
Currently I have all images in 1 atlas using the same settings and am seeing things like the above where the hair doesn't quite go flush with the head.

The PSD these are exported from is the exact same image, 64x64 canvas size and straight to PNG.  What is happening is not 100% of the time and depends on position on screen, so it seems as if the resolution is trying to adjust images drawn by pixels and calculates that the hair should be shifted left 1 column on your screen and the main head not.  If the character moves across the screen the issue disappears and depends where he stops.


unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: 1 "Actual" pixel off?
« Reply #1 on: March 03, 2014, 11:48:08 pm »
Do you have any padding?
If that isn't the cause, try making sure your sprite is on a pixel coordinate - you can have bits shaved off texels due to inaccuracies in the texture filtering hardware.

mitralone

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: 1 "Actual" pixel off?
« Reply #2 on: March 04, 2014, 01:13:24 am »
I usually have this in Photoshop when the size of the image part I try to move is somehow not an exact number. When photoshop tries to move, if somehow it moves by half a pixel, the image will get a shady side and it is only fixed when you move to exact integer coordinate.

In Unity, probably same thing is happening. My suggestions

1- Make sure you move only to full integer values.
2- Also make sure your images in PS have square pixel ratio.

Majicpanda

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 62
    • View Profile
Re: 1 "Actual" pixel off?
« Reply #3 on: March 05, 2014, 02:01:05 pm »
It is definitely in relation to where the character is on the screen so how do I call a method possibly at the end of movement to make sure it's a "pixel location?" And yes I do use padding because without it I was getting weird black lines during animating around the outside of the sprite bounds.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: 1 "Actual" pixel off?
« Reply #4 on: March 05, 2014, 02:47:13 pm »
The pixel snapping should really be performed by unity when it goes to render an object. We can't hook into that part of Unity or we could do it properly, automatically. They try to do this with a vertex shader as far as I can tell in the unity 2d system but that fails horribly in places too.

But what you could do is -
keep your own internal position and update that as opposed to the transform.positon. At the end of your update, assign a pixel snapped internal_position to transform.positon. If your camera is 100 pixels per meter, you will need to round to closest 0.01, etc.