+1 vote

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.

in Engine by (13 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

+1 vote

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.

by (29,120 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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.