In Us WebGL project,we use static font texture for our Text,
In Unity Editor Windows it shows 4MB memory size (2048 * 2048 Alpha8)
But in WebGL Runtime,we capture memory with memory profiler,it takes 16MB!
we try some unity version,all has this BUG!
2021.3.16f1LTS
2022.2
Font Texture : 16MB!
SY-Normal-Mini Atlas:TMP font Texture also 10MB!
webgl2.0
16MB is so huge for WebGL product!we want unity team can fix this BUG!thanks
test project is attached,just download project and open samplescene,build wenbgl and run,it‘s easy to re-produce。
2048x2048 equals 4 MB times the number of color/alpha channels (RGBA = 4) makes for 16 MB uncompressed. Totally expected.
Font atlas textures are NOT compressed because you would easily notice the compression artifacts in text. The texture file may be smaller because that file can be compressed, like PNG is. But when you need to render the texture in memory and upload it to the GPU, it needs to be uncompressed in memory.
If Unity Editor Windows means the asset preview window: the size given there is the flies size on disk, not the size to be expected in RAM on the target hardware.
The reason it’s taking 16MB in memory instead of 4MB is because WebGL does not support the Alpha8 format, and does not support texture swizzling, so it has to be converted to an RGBA8 texture for the GPU…4x the size of the source A8 texture.
You missed the part where the texture is one A8 channel and jumped to conclusions.
With the exception of when using crunch compression and when the target platform doesn’t support the compression type (which means it gets converted to uncompressed), isn’t size on disk the same as size in ram after Unity has compressed / converted the texture to something appropriate for the platform? (especially when the user here seems to use uncompressed?)
That sounds correct and makes sense, thanks for the info!
No, it being uncompressed or the target format not being supported is one factor, midmaps and read/write enabled 2 more. Of the top of my head I’m not sure if there are more but I also wouldn’t bet against there being more.
In the project attached, I build it using WebGL 1.0 and WebGL 2.0 separately, and then used Unity Profiler to view the memory occupied by the Font Texture. The memory of the two builds is not the same.
In WebGL 1.0, a 2048x2048 font texture takes 4MB, which is consistent with the 4MB A8 Compression displayed in the Editor.
In WebGL 2.0, a 2048x2048 font texture takes 16MB, which is significantly different from the 4MB A8 Compression displayed in the Editor.
why the Font Texture memory takes 4MB in WebGL 1.0 and takes 16MB in WebGL 2.0, IF WebGL does not support A8 texture compression.
I use Unity’s API SystemInfo.SupportsTextureFormat to check if WebGL support TextureFormat.Alpha8 ,the result is true.
bool supportAlpha8 = SystemInfo.SupportsTextureFormat(TextureFormat.Alpha8); return true,it means WebGL support TextureFormat.Alpha8 Compression?
Thanks!!!
our team is using Unity Build WebGL Content on Mobile platform,Memory usage is so sensitivity for WebGL,it takes a lot efforts to optimize memory usage in webgl.
In our Projects,TMP font texture and unity’s static font texture maybe should be 4M+4MB = 8MB usage,it‘s fine for us,but 16MB+10MB = 26MB is so large for webgl platform。
@tinyant I think you’re on to something, it looks like we regressed from WebGL1 to WebGL2 support for the A8 texture format. I should be able to get that support enabled for WebGL2, to at least work in the same way WebGL1 did. I’m on the case.
I have A8 textures working for WebGL2 now and am seeing the reduced texture memory. I’ll work on getting the change added to the active Unity versions.
So great!!!
we are waitting for A8 textures for webgl2.0 added to active unity versions!!!
by the way, active unity versions means Unity’s LTS versions inlucde 2021.3.16LTS and other 2021LTS versions?