Hi guys,
i’m creating a comic book using Unity3D, i’ve almost finished.
When verifying the build, the iOSapp is 325Mo!
I think it’s coming from images compression. 98 files in 320x240 and 98 in 1024x768. But the only way to avoid artefacts compression that are really visible, is to use GUI format. Is there a way to have something more jpg100% like ?
See if 16 bit is sufficient for your art instead of 32 bit. Make sure that you’re not including an alpha channel if you don’t need it. You could also include the jpgs as raw data instead of textures and load them into a texture on demand, then you can compress however you like.
How can i include jpg as raw data instead of textures ? Is there any tutorial for this ? Actually I put all my images in a resource folder, and load those I need. But unity automatically set them as texture, and as the compression artifacts are really visible, I converted all to gui
I’ve no experience with it, but you can give your images the .bytes extension and import them as TextAsset. Just run an AppleScript or use Automator or something to change or add the extension to all images in your Resources folder. That way Unity doesn’t do any conversion and just loads the raw image data. See the example in the docs.
You could also try to store the images in the xcode project and load them using WWW, but the above approach is probably faster and more convenient.
Hi Jasper, your methodology seems interesting but i’m experiencing a problem with the resources function :
I put all my images in a ressources folder.
To load a specific image i use the function Resources.Load(langue+CurrentEpisode+“Grizzly”+NbCases+textureSize,Texture)
I have an arror trying Resources.LoadImage(langue+CurrentEpisode+“Grizzly”+NbCases+textureSize,TextAsset)
It seems that tex.LoadImage(imageTextAsset.bytes) has to be used by dragging bytes file in the inspector, that seems incompatible with loading specific file in a folder.
the problem is that i use GUI.DrawTexture, to draw the image, and scrolling the image became really slow on mac, and on ipad it crashes.
I did not have this problem using guitextures. it cames with bytes format.
First, it’s not a good idea to try and load all image data into an array at once. Load the image data on demand and get rid of it as soon as it’s no longer needed.
Second, you’re loading each image twice in the while loop you posted, once to check whether it exists and yet again to actually use it. The easiest fix is to declare imageTex before the loop and assign it in the while condition. Whether you like that style is up to you. But I wouldn’t use that loop anyway.
GUITexture isn’t a Texture format at all, it is a GUIElement, which needs a texture assigned. You can load image data into the texture used by a GUITexture component instead of using GUI.DrawTexture. It might be faster. However, I must say I have no experience with Unity’s GUI stuff, both new and old.
Keep in mind that you’re loading the jpg data as well as converting it into texture data, having both in memory at the same time. If you’re not showing multiple images at once, don’t create a new Texture2D instance but load into the existing one, overriding the previous image. Also, get rid of the jpg data after it’s no longer needed.
Beyond that, I’m afraid I can’t offer much more help.
I’m not sure GUI s not a format, cause when you import a texture as asset and set it to GUI texture, Unity gives image compression information in the inspector. 4Mb for not GUI 1024x768 loaded as 1024x1024 24b texture, and 2Mb for same as 1024x768 GUI texture. But the only way to set it as GUI is in the inspector. Anyway thanks for trying helping me.
I submitted my problem as a bug
Anyone else ?
In fact I can have at least 2 images at the same time, when scrolling from one to another, as iPhone photo library. I have to get in memory the image displayed, the one before and the one after. But as I said before, even with one image it’s slow with .bytes displayed as GUI
The GUI choice for the Texture Type import setting is simply a convenient preconfigured bunch of settings. If you choose Advanced, you can set it to the same stuff by hand (ARGB, no mipmaps, no power-2 rescale, etcetera). It is irrelevant for loading textures through code.
It might be that a texture generated through LoadImage is slower than a static import, but if you’re not updating it all the time it probably shouldn’t be that bad. You’re not doing something like loading textures every update, are you?
I don’t know if this is relevant, but the images cannot be compressed if they aren’t square. At least with the ios PVCRT compression. I believe if you compress it that way, in the editor, then you can load it to the graphics card and it stays compressed. Loads faster and takes less memory. /shrug.