Hey !

I started a new project with the new 2D system and I realized that by default Sprite texture are not drawn properly.

I have a little rectangle in 64x64

Unity default parameters on texture :

Texture type : sprite
Sprite mode : single
Pixels to Unit : 100
Filter mode : Trilinear
Format : compressed
Max size : 64

If I change the params of the Texture sprite to :

Texture type : sprite
Sprite mode : single
Pixels to Unit : 100
Filter mode : Point
Format : True Color
Max size : 64

This picture show the original file and what it looks like when I export the unity project with both parameters.

19064-answer_001.png

Notice the difference of size (64 to 49) and so difference of quality.
( Camera is Orthographic with a size of 5 )

Is it possible to fix that to have a pixel perfect display ?

Thanks !

EDIT : another good way is to create a new material in the library, set the sprite > default shader and tick the “pixel snap” property. Then assign that material to the scene sprite.

The best I managed to get …
“most of the time” it’s displaying the sprite perfectly.

Here is my script to attach to the scene camera to adapt the display based on the device screen size.

  • Basically the script will change the camera orthographicSize based on the pixel size of the screen to match with the texture parameters. (updateOrtho())

  • I also wanted the screen origin at top left of the screen so the camera will be moved accordingly. (updatePosition())

    using UnityEngine;
    using System.Collections;

    public class CameraScreenPoints : MonoBehaviour {

    public Vector2 screenSize = Vector2.zero;
    public Vector2 pixelSize = Vector2.zero;
    
    public Vector3 center;
    public Vector3 bottomRight;
    public Rect bounds;
    
    void updatePosition(){
      Vector2 worldCenter = Vector2.zero;
      float ratio = pixelSize.x / pixelSize.y; // screen ratio => 1.775, 1.5, 1.33333, etc
      worldCenter.x = Camera.main.orthographicSize * ratio; worldCenter.y = -Camera.main.orthographicSize;
      transform.position = new Vector3(worldCenter.x, worldCenter.y, -5f);
    
    }
    
    void updateOrtho(){
      pixelSize.x = Camera.main.pixelWidth;
      pixelSize.y = Camera.main.pixelHeight;
      screenSize.x = Screen.width;
      screenSize.y = Screen.height;
      Camera.main.orthographicSize = pixelSize.y * 0.5f * (1f / 100f);
    }
    
    void Update(){
      updateOrtho();
      updatePosition();
    
      center.x = Camera.main.transform.position.x;
      center.y = Camera.main.transform.position.y;
      bottomRight.x = center.x * 2f;
      bottomRight.y = center.y * 2f;
    
      bounds.width = bottomRight.x;
      bounds.height = bottomRight.y;
    }
    
    public Rect getBounds(){ return bounds; }
    

    }

If you find a better way. I’d like to hear it :slight_smile: