Extending ofShader to handle preprocessor #include statements...?

Hey i’m currently trying to figure out the best way to get an ofShader to detect any #include statements at the top of my GLSL file so that I can include common used GLSL functions stored in separate shaders.

I found a fairly lengthy discussion about this on the Cinder forums here and was wondering if anyone in oF land had thought about doing something similar or has created their own adhoc method for doing something like this? https://forum.libcinder.org/topic/gl-glslprog-directives-preprocessor-include-define-extension

From my understanding GLSL has no concept of files so an #include myFile.glsl statement would have to find that file and stringily it to be included at the top of the shader… Is this correct?

I’m going through @patricio thebookofshaders.com site and there are a ton of awesome resources in there, specifically all the easings you could want and shaping functions and would love to store these in say a easings.frag and shapers.frag files that I could then include into other shaders. see here for easing function class -> http://patriciogonzalezvivo.com/2015/thebookofshaders/edit.html#06/easing.frag

I feel like i must not be the first to have the desire to do this around here so any advice on getting something like this to work would be appreciated.


Hi, that’s supported right now.

Put something like this in your shader to use it:

#pragma include "../../Common/ShaderHelpers.glslinc"



Wow, I cant believe this whole time I had no idea oF could already do this. haha. Thanks heaps, life is about to get a whole lot more fun now :slight_smile:

Boom! :smile: