Any GLSL pre-processor that can help reuse my code?

hi there,

can anyone suggest a way to reuse glsl code? Right now I need to copy-past my phong shading function every time I write a new shader.


There is GL_ARB_shading_language_include. For the specific case of a function that you want to reuse, you can compile that function as a shader object (which only defines the function and has no “main()”) and link it into the program objects where you need it.

can anyone suggest a way to reuse glsl code?

Have you considered putting that code in a function, which is then used from several shaders? Shader compilation allows you to use multiple strings for a reason, after all.

Thank you, can you give a small example how it is used?

thank you, I’ll try that.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.