godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.14k stars 93 forks source link

Add ability to set a different noise source for each RGBA color channel in NoiseTexture2D and NoiseTexture3D #7246

Open vbettaque opened 1 year ago

vbettaque commented 1 year ago

Describe the project you are working on

A sky shader that creates clouds using ray-marching (see here). Multiple 3D noise textures are therefore needed in the shader to generate the shape of the clouds.

Describe the problem or limitation you are having in your project

Each NoiseTexture3D resource can only use one noise source to generate the texture, with each color channel of the texture therefore having the same noise values. This is redundant as only a single channel is required to read out the noise in the shader. Having to send a NoiseTexture3D to the GPU for each distinct noise therefore creates unnecessary overhead when a single such texture could hold up to 4 different noises of the same resolution. It also creates more clutter in the project itself.

All arguments also hold for NoiseTexture2D.

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

Being able to encode up to 4 different noises in a single NoiseTexture3D would decrease a lot of overhead since less information has to be sent from the CPU to the GPU, which is the primary bottleneck in modern computer architectures. It also allows one to only have to deal with less resource objects and therefore a less cluttered interface.

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

My proposal is to add a toggle to the NoiseTexture3D resource that allows the user to decide if they want the same noise for all color channels, or if they want to set an individual noise for each channel. Depending on the state of the toggle, the resource could then allow to set just 1 noise or 4 noises, with customizations like inversion or seamlessness for each individual one. Channels that don't have a noise assigned to them could simply output a default value of 1.

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

This can be worked around by creating a new resources extending Texture3D that takes four different noises and then internally generates the associated NoiseTexture3Ds. Each noise texture is then copied to a different color channel of the actual texture. This however still creates internal overhead due to the need of additional Texture3Ds, and is not as well integrated in the editor because texture previews don't work for custom Texture3Ds.

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

This is an extension of an existing core feature, offering it as an external add-on would therefore have the aforementioned overhead and a sub-par editor implementation.

Calinou commented 1 year ago

and is not as well integrated in the editor because texture previews don't work for custom Texture3Ds.

Out of curiosity, does this work for Texture2D? If it does, it sounds like the Texture3D preview plugin should be moved to a more general place, so that it works for all Texture3D-derived classes.

vbettaque commented 1 year ago

I haven't tried it for Texture2D so far, but feel free to. Here is my 3D implementation so you can at least check that one.