Multiple sprite sizes, is this LOD?

I would like to learn more about handling this issue, but I’m not sure what it is called, so having trouble finding information. I don’t think it is LOD (Level of Detail), LOD seems more about quality loss for improvement performance, and in my case I just want high quality.

Here is an image with 2 captures of a test scene I created:

1823246--116738--Untitled.png

This is a 2D game, so these are sprites. All images started as 1024x1024 PNGs. The image on the right is scaled down by Unity. The image on the left is scaled down using Adobe Fireworks CS3 “soft” method.

This game will support everything from high-end PCs down to low-end mobile devices (kind of the nature of Unity eh?). It will allow the user to zoom in and out… so the sprite above could be 20" wide and 2000 pixels, or 1/8" wide and 16 pixels.

I’m guessing there is no way to make Unity scale sprites as nice as graphics programs do, probably for performance issues. So my current plan is to include several versions of my sprites, ranging from 1024x1024 down to 16x16, and calculate the optimal size to display for each frame.

I have some code that works, but I’d like to read a lot more on this topic before getting too far along, it seems like an area that could get messy pretty fast… as far as game state management/etc.

Here is my code in case anyone is interested (I named the class “LOD” but probably will find a better name):

using UnityEngine;
using System.Collections;
 
public class LOD : MonoBehaviour
{
    // Sprites must be in order by size, largest first
    public Sprite[] Sprites;
    float DesignedSizeInUnits;
 
    void Awake()
    {
        SpriteRenderer sr = GetComponent<SpriteRenderer>();
        Sprite sprite = sr.sprite;
 
        // This is size of sprite in game units
        float spriteUnits = sprite.bounds.size.y;
 
        // This is scaled size of sprite in game units
        DesignedSizeInUnits = spriteUnits * transform.localScale.y;
 
        Debug.Log("DesignedSizeInUnits: " + DesignedSizeInUnits.ToString("F2"));
    }
 
    void Update()
    {
        // Number of pixels per unit for current screen and camera size
        float pixelsPerUnit = (float)Screen.height / (Camera.main.orthographicSize * 2);
 
        SpriteRenderer sr = GetComponent<SpriteRenderer>();
 
        // Size in pixels that our sprite needs to be
        float sizeInPixels = pixelsPerUnit * DesignedSizeInUnits;
 
        // Loop through sprites...
        Sprite s = null;
        for(int x=0;x<Sprites.Length;x++)
        {
            s = Sprites[x];
 
#if false
            // If we find a sprite that is same or smaller than required size...
            if(s.texture.height <= sizeInPixels)
            {
                // If we have a larger sprite...
                if(x > 0)
                {
                    // If larger sprite is closer to the required size...
                    Sprite s2 = Sprites[x-1];
                    float d1 = sizeInPixels - s.texture.height;
                    float d2 = Mathf.Abs(sizeInPixels - s2.texture.height);
                    if(d2 < d1)
                    {
                        // Use the larger one.
                        s = s2;
                    }
                }
#else
            // If we find a sprite that is smaller than required size...
            if (s.texture.height < sizeInPixels)
            {
                // If we have a larger sprite...
                if (x > 0)
                {
                    // Use the larger one.
                    Sprite s2 = Sprites[x - 1];
                    s = s2;
                }
#endif
 
                // We can stop loop now, sprites are in order by size.
                break;
            }
        }
 
        // Use the sprite we found above
        sr.sprite = s;
 
        Debug.Log("pixelsPerUnit: " + pixelsPerUnit.ToString("F2") + " sizeInPixels: " + sizeInPixels.ToString("F2") + " spriteSize: " + s.texture.height);
    }
}

The sprites all have PixelsPerUnit values adjusted so that they are all the same size, without having to change the scale of my GameObjects.

Mipmapping?

Thanks! Looks like what I’m looking for…

The “reduce aliasing artifacts” part. Should be able to find some topics online now, Unity specific or otherwise.

The very best way is to create your own mipmap textures and upload them, which you’d have to do with a script at runtime.