Share code between shaders

Hi guys,

is it possible to share static shader code between multiple shaders? I am aware of the #include<…> feature, but this only works for predefined shaders of the babylon library. Is it possible to use #include<…> for my own written files?

Example: I have a gpu-noise function and i want to use this in different fragment shaders. To do this, I have to copy the whole block of code all the time.


You can place your code in the shader manually so that include would work as well:

BABYLON.Effect.IncludesShadersStore["myfunctions"] = "..."

and then in your shader use



Cool, thank you!

dude waaaaaa… for real… holy crap. I feel like @sebavan just gave me a golden ticket. I wish this was talked about in the docs somewhere as it is extremely useful and powerful. Sometimes you just need somebody else to ask a question you were not thinking of… Thank you @treksn

1 Like

Fancy doing a PR for the doc ?

Got you fam


There’s that, finishing up the writeup now.

1 Like