Author Topic: Image file format and RAM consumption  (Read 1685 times)

2018-11-13, 20:31:18

romullus

  • Global Moderator
  • Active Users
  • ****
  • Posts: 6573
  • Let's move this topic, shall we?
    • View Profile
    • My Models
When talking about RAM consumption during rendering, does it matter what file format is used for textures? Will 5 MB JPEG texture take less memory than the same texture saved in 100 MB TIFF? Or they both will take roughly the same amount of RAM?
I'm not Corona Team member. Everything i say, is my personal opinion only.
My Models | My Videos | My Pictures

2018-11-14, 10:24:47
Reply #1

Ryuu

  • Corona Team
  • Active Users
  • ****
  • Posts: 612
  • Michal
    • View Profile
Corona stores the images in memory uncompressed, so this really depends on resolution and bit depth. An 8-bit 1024x1024 JPEG will take exactly the same amount of memory as an 8-bit 1024x1024 TIFF no matter what's their size on disk.

2018-11-14, 11:03:43
Reply #2

romullus

  • Global Moderator
  • Active Users
  • ****
  • Posts: 6573
  • Let's move this topic, shall we?
    • View Profile
    • My Models
Thank you for the answer! If i understand correctly, given the same image dimension and bit depth, the only thing that matters, is number of channels? So 1024x1024 8 bit texture will take 1 MB RAM if it's greyscale, 3 times as much if it's RGB and 4 times as much if it's RGBA?

I'm not Corona Team member. Everything i say, is my personal opinion only.
My Models | My Videos | My Pictures

2018-11-14, 11:19:55
Reply #3

romullus

  • Global Moderator
  • Active Users
  • ****
  • Posts: 6573
  • Let's move this topic, shall we?
    • View Profile
    • My Models
Also, what is the better option - to have 3 single channel textures, or 1 RGB texture, in terms of RAM consumption, scene parsing time?
I'm not Corona Team member. Everything i say, is my personal opinion only.
My Models | My Videos | My Pictures

2018-11-14, 13:08:12
Reply #4

Ryuu

  • Corona Team
  • Active Users
  • ****
  • Posts: 612
  • Michal
    • View Profile
Thank you for the answer! If i understand correctly, given the same image dimension and bit depth, the only thing that matters, is number of channels? So 1024x1024 8 bit texture will take 1 MB RAM if it's greyscale, 3 times as much if it's RGB and 4 times as much if it's RGBA?

Yes, that's correct.

Also, what is the better option - to have 3 single channel textures, or 1 RGB texture, in terms of RAM consumption, scene parsing time?

Good question. I never tried to measure it, but as long as we're talking about 3 files vs 1 file, there should not be any noticeable difference in memory consumption or parsing time. When we get to 3000 vs 1000, the difference might be a bit more noticeable in terms of parsing time as there is some small overhead with opening each file, etc.

The overhead is much higher when the texture files are stored in a network location, as there are higher latencies involved in opening the individual files, etc.

So, I would definitely not worry about this unless you have problems with the parsing times and have a reason to suspect that the texture loading might be the cause of those problems.

One of the key points of Corona philosophy has always been that users should not worry about technical details. So if you ever get to the point where 3 files vs 1 makes any noticeable difference, I would prefer to solve this by optimizing the texture loading code rather than forcing the users to store their assets in a certain way.

2018-11-14, 15:33:41
Reply #5

Juraj

  • Active Users
  • **
  • Posts: 4079
    • View Profile
    • studio website
Tangentially connected, but I had all sorts of issues with 3dsMax bitmap loader (not Corona connected!) with grey-scale image files. One is it can't load 32bit grey-scale files if they have attached color profile (found out by downloading 32bit float tiff files from TexturesXYZ and had to manually convert them all to .exrs without color profiles).
Regular integer 8&16bit files also gave me odd results here and there.

I need to test this again esp. since I use more and more 8k texture sets.
talcikdemovicova.com  Website and blog
be.net/jurajtalcik   Our studio Behance portfolio
Instagram   Our studio Instagram, managed by Veronika

2018-11-14, 15:55:06
Reply #6

karnak

  • Primary Certified Instructor
  • Active Users
  • ***
  • Posts: 65
    • View Profile
Interesting findings Juraj, thanks for sharing.

During a project early this year, I also found out something.
I was testing my project for performance and found out the following:

Code: [Select]
    CoronaBitmap    8bit image   38 sec
    CoronaBitmap   16bit image   46 sec <<<

(Default) Bitmap    8bit image   41 sec
(Default) Bitmap   16bit image   41 sec

This measure was taken (average of multiple measurements) by looking at the UHD cache precom time, the loaded images were in TIF format but I can't find in my notes how many channels. Corona was version 1.7.4.
Corona Academy (May 2017)

2018-11-14, 16:09:52
Reply #7

Juraj

  • Active Users
  • **
  • Posts: 4079
    • View Profile
    • studio website
I am not even using Corona Bitmap, unless it's for 360 HDRi. I don't see any point of that map, it doesn't carry any improvement. I hoped they would introduce better resampling, something that would yield superior sharp results at glance angles. But since it has no performance (not care much) or visual (this is what I would love) benefits, I don't see why to use it at all.
talcikdemovicova.com  Website and blog
be.net/jurajtalcik   Our studio Behance portfolio
Instagram   Our studio Instagram, managed by Veronika

2018-11-14, 21:05:52
Reply #8

romullus

  • Global Moderator
  • Active Users
  • ****
  • Posts: 6573
  • Let's move this topic, shall we?
    • View Profile
    • My Models
..

Thanks Ryuu, your answers helped me great deal! I'm working on a simple scene, but Corona was throwing low memory warnings even at lowest resolution renderings. I did few optimizations to some unnecessary heavy assets and now i can render at 4K without problems. That is quite an achievement for my 16 GB RAM! :]
I'm not Corona Team member. Everything i say, is my personal opinion only.
My Models | My Videos | My Pictures

2018-11-15, 07:23:24
Reply #9

pokoy

  • Active Users
  • **
  • Posts: 1507
    • View Profile
I'm pretty sure a greyscale tif will convert to RGB for rendering, not sure if you can save any memory here.

2018-11-15, 10:39:42
Reply #10

romullus

  • Global Moderator
  • Active Users
  • ****
  • Posts: 6573
  • Let's move this topic, shall we?
    • View Profile
    • My Models
But did you do any tests to confirm your claims? I took 5 8K RGB textures, which should take ~1006 MB RAM in rendering, converted them to greyscale (~335 MB), assigned both sets to 5 boxes and rendered both scenes. Scene with RGB textures took 2092 MB RAM and scene with greyscale - 1455 MB. Theoretical difference should be 671 MB, in practice it was 637 MB. I think results speaks for themselves, isn't? :]
I'm not Corona Team member. Everything i say, is my personal opinion only.
My Models | My Videos | My Pictures

2018-11-15, 11:17:40
Reply #11

Juraj

  • Active Users
  • **
  • Posts: 4079
    • View Profile
    • studio website
Just tested 32bit files again. 3dsMax has issue with reading grey-scale 32bit Tiffs, and in order to save them into .exr or .hdr, they need to be RGB. What is the solution to this ?

Instead of painfully re-saving something to grey-scale manually, is there something like in Unreal where I can read individual channels from bitmaps ?
If not, maybe Corona Bitmap could add such option.
talcikdemovicova.com  Website and blog
be.net/jurajtalcik   Our studio Behance portfolio
Instagram   Our studio Instagram, managed by Veronika

2018-11-15, 14:31:18
Reply #12

pokoy

  • Active Users
  • **
  • Posts: 1507
    • View Profile
But did you do any tests to confirm your claims? I took 5 8K RGB textures, which should take ~1006 MB RAM in rendering, converted them to greyscale (~335 MB), assigned both sets to 5 boxes and rendered both scenes. Scene with RGB textures took 2092 MB RAM and scene with greyscale - 1455 MB. Theoretical difference should be 671 MB, in practice it was 637 MB. I think results speaks for themselves, isn't? :]

No, I didn't but I remember asking the devs here and this was the answer, it also made sense since everything is done in RGB internally. Happy to learn it does make a difference.

2018-11-15, 15:03:32
Reply #13

romullus

  • Global Moderator
  • Active Users
  • ****
  • Posts: 6573
  • Let's move this topic, shall we?
    • View Profile
    • My Models
Instead of painfully re-saving something to grey-scale manually, is there something like in Unreal where I can read individual channels from bitmaps ?
If not, maybe Corona Bitmap could add such option.

Not sure if this is what you're after, but i'm using RGBTint map for this. Works fine.

No, I didn't but I remember asking the devs here and this was the answer, it also made sense since everything is done in RGB internally. Happy to learn it does make a difference.

Hm, maybe there was some miscommunication, or things indeed changed since then? Anyway, greyscale does make big difference and i couldn't be more happy about that. Every single megabyte counts :]
I'm not Corona Team member. Everything i say, is my personal opinion only.
My Models | My Videos | My Pictures

2018-11-15, 21:50:57
Reply #14

mraw

  • Active Users
  • **
  • Posts: 152
    • View Profile
I'm awfully sorry that I can't be more specific. But years(15+) ago I went the path of using greyscale-single-channel images to limit texture size in ram, but I ended up in all kind of weird, hard to track down errors. In Max and if I remember correctly in Maya as well. It's like there are kinds of scenarios developers don't expect the user to plug a single-channel-image in. I wouldn't use that technique in complex projects.