Calling other shaders (functions) from a shader

I’d like an overview of including a shader from another one. A complete explanation would be pretty damn good as it is.



The thing is, I’m generating several things procedurally and I often call noise4D but right now I’ve got to copy that function in each shader. Not good. I know there’s a way to do that by using #include or something like that, but I’m unsure how it works exactly.



Honestly I prefer asking than spending hours trying to figure it all out.



Thanks. :smiley:

http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=267327

0.2 Seconds of google.



GLSL does not seem to have it.

I didn’t search Google because i doubt any solution applying to Unity 3D, or any other engine for that matter, would to jME.

@madjack, you can place common shader functions in a .glsllib file. Then you can import those function with #import Shaders/MyFancyShaderLib.glsllib



Look at the JME-core shaders, there are some examples of this pattern :slight_smile:

1 Like

Nice thanks.



Huh. I thought there was more to it than that. :smiley:

I have 2 follow up questions on the GLSL libraries:

Is this #import statement a feature of jME or LWJGL?

And is it possible to #import a shader library from within another shader library?

@cmur2 said:
I have 2 follow up questions on the GLSL libraries:
Is this #import statement a feature of jME or LWJGL?

No, there's support for that in the GLSL specification, but I don't have the details.


And is it possible to #import a shader library from within another shader library?

Yes, I know that can be done as long as your path is right in the #import. At least I think that's how it works.

@cmur2, @madjack The import statement is in jME, there is no such thing in GLSL. :slight_smile:

2 Likes

I stand corrected.

Thank you both for the enlightenment! - nested shader libraries sound like a cool idea :slight_smile: