Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

HELP! My textures keep getting lower resolution!

Discussion in 'Editor & General Support' started by Marscaleb, Jun 30, 2014.

  1. Marscaleb

    Marscaleb

    Joined:
    Jan 7, 2014
    Posts:
    973
    At the moment, I'm only building my game fro Android, as I'm pushing it onto my Ouya. I'm going to be showcasing my game at a big event next week with thousands of people, and my Ouya is the prime choice to run the demo on.

    And I just found a very critical problem that appears to be coming from the back-end of the engine.

    My game is in 2D, and nearly everything is built with sprites. However, there are a couple objects that are made with textures on 3D objects so that I can have the texture pan/scroll. The sprites are running fine, but the textures are losing quality.

    At first I only saw it happening with two of my textures, both of which it seemed fairly negligible. But after a little bit of extensive play I found that it is effecting all of my textures/materials, and it gets worse the longer I play.

    It is not simply losing resolution. I've seen that before and I know what it looks like. Textures look overly compressed and blurry. But here, my textures are becoming pixelated. It's like they reduce in their resolution AND turn into point filtering. Some of these textures begin to look like graphics from an Arati 2600 with giant texel blocks that far exceed any reasonable expectation. My waterfall texture got so bad it didn't even look like it was panning, it was just a solid row of vertical blue streaks.

    I have no idea why this is happening. All the sprites looks fine. The textures start off fine but get worse the longer I play. These textures are each either 64x64 or 128x128. The materials all use the "Mobile/Unlit" shader, except for one using "Unlit/Transparent" as I have no mobile unlit transparent shader.
    I am using Unity 4.5.1p2.
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    If you're scrolling the textures, keep the UVs close to the 0.0 - 1.0 range.

    --Eric
     
  3. Marscaleb

    Marscaleb

    Joined:
    Jan 7, 2014
    Posts:
    973
    This is my texture panning code:
    Code (CSharp):
    1. public class TexturePanner : MonoBehaviour {
    2.  
    3.     public float xPanSpeed;
    4.     public float yPanSpeed;
    5.  
    6.     Vector2 vOffset;
    7.  
    8.     // Use this for initialization
    9.     void Start () {
    10.    
    11.     }
    12.    
    13.     // Update is called once per frame
    14.     void Update () {
    15.         vOffset.x = Time.time * xPanSpeed;
    16.         vOffset.y = Time.time * yPanSpeed;
    17.         renderer.material.mainTextureOffset = vOffset;
    18.    
    19.     }
    20. }
    Is that really going to be the problem?
    I'm not seeing this problem on my PC when I test the level.
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    Right, the offset is continuously increasing, getting further away from the 0..1 range every moment. Mobile GPUs generally don't have the precision to handle that, so keep the UV offset in the 0..1 range. (Presumably it would be a problem eventually on desktop GPUs as well, but would take a lot longer.)

    --Eric
     
  5. Marscaleb

    Marscaleb

    Joined:
    Jan 7, 2014
    Posts:
    973
    Well, how do I reverse-truncate a number so I can keep only what is on the right of the decimal point?

    Also, you're totally right. I just left the game running on the title screen for several hours and now my textures are the worst I've ever seen.
    I thought there was memory leak or faulty garbage collection or something.
     
  6. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    Code (csharp):
    1.  
    2. void Update () {
    3.     vOffset.x = Mathf.Repeat (Time.time * xPanSpeed, 1);
    4.     vOffset.y = Mathf.Repeat (Time.time * yPanSpeed, 1);
    5.     renderer.material.mainTextureoffset = vOffset;
    6. }
    7.  
     
  7. Marscaleb

    Marscaleb

    Joined:
    Jan 7, 2014
    Posts:
    973
    Thank you!
     
  8. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    Or you could use modulo: (Time.time * xPanSpeed) % 1

    --Eric
     
  9. Marscaleb

    Marscaleb

    Joined:
    Jan 7, 2014
    Posts:
    973
    I thought the percent sign gave me the remainder after dividing it. Wouldn't % 1 always return zero?
    You couldn't even feed it a float, if I am not mistaken.
     
  10. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    You can certainly use a float. Try it. ;)

    --Eric