0 votes

Hi,
I'm trying to save a noise shader I made in order to import it in other shaders.
I saw that it was possible using a sampler2D with a noise texture, but the only one available is the OpenSimplexNoise, whereas I'm trying to use a custom noise (for exemple cellular noise).
Can this be done ? How can I save a shader in a form that would be reusable in this case ?
Thanks.

asked May 19 in Engine by Maloherve (12 points)

Have you looked at the menus for saving a shader, i.e. select the node, then go to Inspector -> Material -> Shader and selecting "Save" from the dropdown menu?

I have but none of the available save types allow to be imported into a sampler2D in my new shader.

1 Answer

0 votes

I saw that it was possible using a sampler2D with a noise texture

A shader is not a texture. You cannot assign a shader as parameter of another shader in this way. You can make your shader render to a viewport and then assign the ViewportTexture.

How can I save a shader in a form that would be reusable in this case ?

Unfortunately it is not possible to use functions from another shader inside a new shader. This is sometimes supported in other engines by using a form of #include so the same code can be re-used (like a fancy copy/paste), which was proposed but never added so far ( https://github.com/godotengine/godot/pull/17797 ).
At the moment the only way is to move your code into functions and copy them across all shaders where you want to use them.

answered May 20 by Zylann (26,131 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.