godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.28k stars 21.05k forks source link

3.x: Materials generated from .gltf file are too big in filesize #34641

Open ruki3 opened 4 years ago

ruki3 commented 4 years ago

Godot version: 3.1.2

OS/device including version: Windows 10 v1809

Issue description: When you import fully textured .gltf scenes Godot automatically generates .material files for you. Unfortunately there's a flaw in it, because, for example - a door material is 13 mb in size while all the textures are barely 300kb in size. Also, the exported gltf is only 2,6 mb in size. Something's totally not right here.

Steps to reproduce: Make a model in blender, make materials, export to gltf and finally import to godot. Minimal reproduction project:

material-bug.zip

here's a screenshot of all of the wooden floor material files - they're only 718 kb in file size, while the material is 9,2 mb (!) Screenshot_6

Calinou commented 4 years ago

Maybe .material files are embedding textures in uncompressed form. It probably shouldn't be doing that.

ruki3 commented 4 years ago

Is there any way to avoid that without running a custom build of Godot? I've tried messing with the model's import settings, but couldn't find anything related to texture compression.

Calinou commented 4 years ago

cc @fire, as he has some knowledge about the glTF 2.0 importer.

fire commented 4 years ago

Looking!

    "buffers" : [
        {
            "byteLength" : 1991968,
            "uri" : "data:application/octet-stream;base64,

You embedded something binary in the gltf2 file.

I would try exporting as scn to check file size. There was other comments about text formats for example base64'd png files encoded as base64 versions.

Calinou commented 4 years ago

Indeed, text formats like .tscn and .tres will encode binary data as Base64, which is at least 33% larger than the raw binary data.

ruki3 commented 4 years ago

I didn't embed anything in the gltf2 file, at least not on purpose. Could it be that some addons are causing the problem? I also tried disabling some functions that I don't need at the export stage (animations, skinning etc.) but it didn't reduce the size of the file. Thanks for the suggestion about the scn export, it doesn't include the textures inside the file like gltf, but at least I get to keep the size of my project small, as .dae didn't work for me aswell (I swear Godot hates me)

aaronfranke commented 4 years ago

Any update? I have a .material file which is 41.9 MB, but the image it contains is only 170.3 kB when saved as a .png file. This is ridiculously huge.

KoBeWi commented 4 years ago

Might be duplicate of #31632

Bleuzen commented 4 years ago

Is there any update on this? Would love to use gltf bin, but with this bug it is unusable. As a workaround for now we can use .dae or gltf separate formats.

Here are my tests so far in different formats (all exported from Blender and imported to Godot). I'm using this example: https://ln.sync.com/dl/41dc1c2b0/wxfm2fzf-w2ggnk53-i7eyv6zj-caq828di (from video https://www.youtube.com/watch?v=XMfiojwtuKo)

.DAE total size: 213 kb grafik

GLTF SEPARATE total size: 98 kb grafik

GLTF binary (and embedded) (only one generating the huge material): total size: 3.1 mb grafik

Calinou commented 4 years ago

@Bleuzen As far as I know, nobody found a solution to this yet. Given how Godot's import system works, I'm not sure if we can even fix this at all.

Maybe the textures embedded in the .glb could be written to external PNGs/JPEGs when importing (then referenced in the .material files), but then, you have to deal with stray files from old imports and stuff like that.

fire commented 4 years ago

For me using gltf where you export text gltf and the textures to a textures folder as png etc works the best.

abrasivetroop commented 1 year ago

@Calinou Any updates on this? My .material file sizes were too big. I realized it was the textures that were too big in size and I had to go through every file and change the texture compression mode to lossless compression. By default textures imported from .gltf material files are uncompressed. If textures were lossless compressed by default this wouldn't be a huge problem.

image

Doing this reduced file sizes by 10 Mbs which also reduced scene loading times. My project size reduced by 1GB too after doing this for every material file in my project. There is no way of changing this in Import Defaults too. Sorry if I am missing something.

KoBeWi commented 1 year ago

There is no way of changing this in Import Defaults too. Sorry if I am missing something.

Profile -> Set as Default in Import dock.

abrasivetroop commented 1 year ago

@KoBeWi I am sorry can't find the setting you are talking about

abrasivetroop commented 1 year ago

image @KoBeWi Are you talking about this? If so, you can't set a import default for materials that are imported with .gltf files from the import menu.

KoBeWi commented 1 year ago

You mean these textures ignore defaults? Do the defaults work correctly for regular textures?

abrasivetroop commented 1 year ago

Yes .gltf material files import texture with no compression and they ignore the import defaults for textures. I had to manually set the textures for each material to lossless compression and I will need to do this every time I import a gltf model with embedded textures. Unless there is a way to set an import default for this :/

fire commented 1 year ago

Work for this was being done in https://github.com/godotengine/godot/pull/62499

It's blocked on astc support being merged

abrasivetroop commented 1 year ago

@fire Awesome! When do you think this fix will be released?

Calinou commented 1 year ago

When do you think this fix will be released?

There is no ETA, but note that ASTC support will only be added in Godot 4 – it won't be backported to 3.x.

abrasivetroop commented 1 year ago

There is no ETA, but note that ASTC support will only be added in Godot 4 – it won't be backported to 3.x.

I see, Godot setting built-in gltf textures to lossless compression would be enough for now. It is just a hassle manually setting all of them :/

And thanks for everyone informing me about this!

lyuma commented 9 months ago

This issue was solved in time for the release of 4.0, by extracting textures from glb files. It still exists in 3.x