Search Unity

WWW Streaming Compressed Textures

Discussion in 'Scripting' started by Doug, Jun 10, 2008.

  1. Doug

    Doug

    Joined:
    Oct 19, 2007
    Posts:
    36
    I am using the MeshSerializer on the Wiki to try and stream level models to a stand-alone build:
    http://www.unifycommunity.com/wiki/index.php?title=MeshSerializer

    Geometry works fine, but the problem is with textures. My scene uses about 52MB of video memory when running without streaming; however, that is when it is compressed with DXT1 DXT5 compression.

    The WWW class only streams uncompressed textures, this causes my scene to balloon up to almost 200MB of texture memory (and not all textures are streaming yet).

    Related thread:

    DXT Compressor
    http://forum.unity3d.com/viewtopic.php?t=8300
    "quite hard", but is it somehow possible?


    The 2 starting points I could think of are:

    Plugins
    The example TexturePlugin just ends up using SetPixels() which only works on uncompressed Texture2D objects.

    Low-level rendering access
    The GL class allows access to manipulate geometry, but doesn't appear to have access to textures.


    Any ideas on how to address this issue?


    One more piece of sample data:
    512x512 DXT1 Compressed = 170 KB
    512x512 RGBA32 = 1.3 MB
     
  2. apple_motion

    apple_motion

    Joined:
    Jul 2, 2009
    Posts:
    169
    "The WWW class only streams uncompressed textures..."

    Is that means, I can't load the .dds file (DXT1 or DXT5) by WWW class? Is there any solution now a day (for non-pro version user) ? :p
     
  3. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Correct
    You can not load any comrpessed texture from external other than AssetBundles ("external Resources folders") at the time, which is a Pro only feature.

    DXT are for load and usage, not for modification in any way, because they don't have pixel data you can modify "usefully" as Aras mentioned in the below quote too.
    You can't recompress DXT in realtime, nor even near realtime.

    So the answer is no, either you want realtime setable textures or compressed ones.
     
  4. freshcut

    freshcut

    Joined:
    Nov 17, 2008
    Posts:
    71
    I think you can just use Texture2D.LoadImage

    from the manual :
    here's what my test class looked like :

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. public class TextureLoader : MonoBehaviour {
    4.  
    5.     // Use this for initialization
    6.     void Start() {
    7.         StartCoroutine(LoadImage());
    8.        
    9.        
    10.     }
    11.  
    12.     IEnumerator LoadImage() {
    13.         WWW w = new WWW("http://forum.unity3d.com/templates/alexis/images/UnityLogo.png");
    14.         yield return w;
    15.         Debug.Log("image loaded");
    16.         Texture2D tex = new Texture2D(1,1);
    17.         tex.LoadImage(w.bytes);
    18.         gameObject.renderer.material.SetTexture("_MainTex", tex);
    19.     }
    and it worked fine and was compressed afterwards.

    hope this helps
     
  5. freshcut

    freshcut

    Joined:
    Nov 17, 2008
    Posts:
    71
    oops scrap that, file-new..

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. public class TextureLoader : MonoBehaviour {
    5.  
    6.     // Use this for initialization
    7.     void Start() {
    8.         StartCoroutine(LoadImage());
    9.        
    10.        
    11.     }
    12.  
    13.     IEnumerator LoadImage() {
    14.         WWW w = new WWW("http://icons.iconarchive.com/icons/artua/dragon-soft/User-512x512.png");
    15.         yield return w;
    16.         Debug.Log("image loaded");
    17.         Texture2D tex = new Texture2D(512,512, TextureFormat.DXT1, false);
    18.         w.LoadImageIntoTexture(tex);
    19.         gameObject.renderer.material.SetTexture("_MainTex", tex);
    20.         Debug.Log(gameObject.renderer.material.GetTexture("_MainTex").ToString());
    21.    
    22.     }
    23. }
    24.  
    25.  
    that's what I meant :)