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

Question Is there some way to reduce memory usage when use a large number texutre2D in unity

Discussion in '2D' started by TrinityLeaves, Jul 10, 2023.

  1. TrinityLeaves

    TrinityLeaves

    Joined:
    Jan 17, 2022
    Posts:
    2
    As we know, texture2d will save all the pixels and can be huge in RAM. But I want to reduce the RAM usage.
    my question is not about compression. I need to read a file to RAM (For example png file) and DO NOT using texure2D,because it's so large.I want to draw sprite by GPU compute and don't increase RAM usage.

    Recently I played a game named Blazblue and I found that RAM just use hundreds of Mb when the scene has 2 characters and 3D background.Though the game is not developed by Unity.In this game's assets I found that a character include about 1000 frames and It's not bone sprite. If they are read to texture2D,a character can be about 2GB size in RAM……Blazblue‘s sprite file has it's own struct and maybe like png files

    So I think there maybe a way to draw sprite without texture and use less RAM. And Because of reducing RAM usage, GPU will be used. In my limited knowledge, maybe Compute Shader can do this, but many mobile phones are not support it.

    Anyone can tell me how to resolve it or any else game engine can do it, thanks very much!
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,468
    So you know, Texture2D isn't a 2D feature, it's used by all of Unity for 3D rendering etc because it primarily represents a handle to the texture in GPU memory so questions about its specific behaviour are best asked on the General Graphics forum.

    I'm not a graphics engineer but AFAIK the Texture2D won't reside in RAM unless you've specifically asked that it can be Read/Write at runtime (see the Advanced settings in the Texture2D importer). If that's not active then it should exist in the GPU memory only.

    See the docs: https://docs.unity3d.com/ScriptReference/Texture-isReadable.html

    Direct drawing with a Texture: https://docs.unity3d.com/ScriptReference/Graphics.Blit.html
     
  3. TrinityLeaves

    TrinityLeaves

    Joined:
    Jan 17, 2022
    Posts:
    2
    Thanks a lot for your reply,finally I have reduced the RAM usage to about 100MB by using shader to compute Alpha8 texture and it's palette.
     
    MelvMay likes this.