godotengine / godot

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

VRAM compressed textures are not rendered in the web when the import mode is high quality. #95721

Open phantomdesvin opened 3 weeks ago

phantomdesvin commented 3 weeks ago

Tested versions

Reproducible in Godot 4.3 stable, windows 10, chrome browser. Also in Godot 4.2.

System information

windows 10, Godot 4.3 stable, chrome browser, RX 580, compatibility mode, web export with default settings

Issue description

My game is a web 2D game with lots of animation that benefit greatly from VRAM compressed import of images, as without it the VRAM consumption is close to 10GiB and the load times are high. The game is working perfectly when I run it normally in the editor, however in the browser the VRAM compressed textures are not rendered while all the rest are rendered normally.

Steps to reproduce

Reimport the godot icon as vram compressed and try to render it on the web. It won't show. Reimport it as lossless or lossy and it will render normally.

Minimal reproduction project (MRP)

vram-compressed-textures-not-rendered-in-web.zip

Calinou commented 3 weeks ago

project.zip

This MRP is not runnable or exportable to the web as-is, as it contains binary files and not the project source files. Please ZIP up the source project including its project.godot file (not project.binary).

fire commented 3 weeks ago

The problem on the web is that there is a divide between BPTC(like dxt5 and bc7) based pc platforms and ASTC/ETC based phones for storing textures.

We added basisu for storing textures as it can runtime convert between the two but it's not a common format.

Hope that helps

phantomdesvin commented 3 weeks ago

project.zip

This MRP is not runnable or exportable to the web as-is, as it contains binary files and not the project source files. Please ZIP up the source project including its project.godot file (not project.binary).

Sorry, file updated. Is this the correct one? I closed this issue accidentally.

phantomdesvin commented 3 weeks ago

The problem on the web is that there is a divide between BPTC(like dxt5 and bc7) based pc platforms and ASTC/ETC based phones for storing textures.

We added basisu for storing textures as it can runtime convert between the two but it's not a common format.

Hope that helps

Sorry I'm not sure if I understood you, I'm still learning. Does that mean this is not a bug? VRAM compressed import mode is not supposed to render in web?

Yes it helps a lot. Basis U looks perfect in the web, and it's as light as VRAM compressed in the VRAM.

The big downside for my use case is that being a web game and having to load resources in a single thread to avoid the known problems with the SharedArrayBuffer, these animations take much longer to load with BasisU than with VRAMComp, and the game freezes while loading.

Sorry if this is a little bit of topic, but there is no way to achieve background loading (or more technically fake it) in single thread mode in Godot 4.3, right? I found an explanation using ResourceLoader.load_interactive and polling each frame loading a fraction of the resource and pausing the loading so the game doesn't freeze but those methods don't seem to exist in Godot 4.3.

Calinou commented 3 weeks ago

Did VRAM-compressed textures render correctly in 4.2, or in 3.5?

They should be able to work but support across platforms is not guaranteed, which is why you should check both VRAM compression settings in the Web export preset if you intend the project to run on mobile platforms as well.

phantomdesvin commented 3 weeks ago

Did VRAM-compressed textures render correctly in 4.2, or in 3.5?

They should be able to work but support across platforms is not guaranteed, which is why you should check both VRAM compression settings in the Web export preset if you intend the project to run on mobile platforms as well.

I checked 4.2, and VRAM-compressed didn't render in high quality mode, however with high quality off it was rendered. The behaviour is the same in 4.3, so I edited the issue tittle to be more precise.

If this is the intended behaviour or a known current limitation, I guess it should be made clear in the "high quality" hovering hint that the mode doesn't work in the web.

If having VRAM compressed with high quality working in the web is achievable, then I think it would be a useful proposal, because precisely on the web, where single threading is most common and consecuently loading times, the much faster loading times of VRAM compressed would be very useful and the quality is excellent.

Calinou commented 3 weeks ago

If this is the intended behaviour or a known current limitation, I guess it should be made clear in the "high quality" hovering hint that the mode doesn't work in the web.

Yes, I don't expect that one to work on the web as BPTC (which is used for high-quality VRAM compression) is not part of WebGL 2.0.

fire commented 3 weeks ago

There are extensions for webgl2 since the list of supported vram format in babylonjs is more than we expected. https://doc.babylonjs.com/features/featuresDeepDive/materials/advanced/mutliPlatTextures

fire commented 3 weeks ago

Quoted from Babylon.js

Here is a chart of all the current formats possible for WebGL, listed in the order chosen when hardware supports multiple formats (tie breakers):

Format Extension Description Alpha Capable
ASTC *-astc.ktx Newly approved for WebGL, most powerful, cross-platform. Implemented in many newer processors, but not exposed by any browsers yet. Always
DXT *-dxt.ktx Direct X, available primarily on Desktop Operating Systems. Yes
PVRTC *-pvrtc.ktx Proprietary. Power VR chips (includes all Apple iOS processors). Must be square. Yes
ETC2 *-etc2.ktx ETC1 + alpha capable. Required by WebGL 2 (or at least OpenGL ES 3, on which WebGL 2 is based). Yes
ATC *-atc.ktx Format originating at AMD. No encoder which supports .KTX found at this time. Yes
ETC1 *-etc1.ktx Wide support among older mobile devices. Need to fall back to images for .PNG files. No
BlueCube3310 commented 2 weeks ago

Unsupported texture formats are decompressed at runtime, it looks like CVTT and/or astcenc are excluded from release builds.