godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.17k stars 98 forks source link

Implement support for caching NoiseTextures to disk #7023

Open mrjustaguy opened 1 year ago

mrjustaguy commented 1 year ago

Describe the project you are working on

A Game heavily using Noise Textures created in Godot using the builtin FastNoise

Describe the problem or limitation you are having in your project

Long Loading times as it's Creating Noise Textures

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Having the option to Cache Noise Textures into images after they're created in the editor and using the cache would resolve this issue.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Add per NoiseTexture cache option If toggled, save generated texture onto the hard, and open the cache instead of regenerating the texture This has the added side benefit of allowing VRAM compression to be used, as right now NoiseTextures seem to be Uncompressed

If this enhancement will not be used often, can it be worked around with a few lines of script?

It can be worked around by exporting the scene into gltf which saves the texture, and using that texture instead of the NoiseTexture, which is a time consuming and doesn't allow for changing the NoiseTexture after the fact without redoing it again.

Is there a reason why this should be core and not an add-on in the asset library?

NoiseTexture is core, and this affects performance

Calinou commented 1 year ago

We'll need to find a way to match NoiseTexture parameters to a unique hash, which can then be featured in the filename. The path can be something like CACHE_DIR/noise_textures/HASH.res. When generating a NoiseTexture, its parameters should be hashed and the filesystem should be checked for a texture already in cache.

I suggest only caching textures when not running in the editor, so that cached textures are not continuously created when playing around with parameters in the editor.

mrjustaguy commented 1 year ago

A possibility I considered was to have a button to tell it "Ok Done with this texture for now, go Cache it!" for the editor, while just auto running cache outside of the editor

passivestar commented 3 months ago

Faced this problem too, even a few noise textures can take significant time to generate, sometimes up to several seconds depending on how many there are and how big they are. When I made a water material it used several different noises - for normals, refraction, caustics, etc, and the delay was very noticeable even with a single material in the scene

I suggest only caching textures when not running in the editor, so that cached textures are not continuously created when playing around with parameters in the editor

I think a checkbox would be better because all the wait time while testing the game in editor can add up to minutes or even hours over hundreds of game restarts. Once you're done with a texture you should be able to click the cache checkbox like the proposal suggests and load from disk even when running from the editor