Merging vertex shader in fragment shader

Hi,
Is it possible to merge vertex shader into a fragment shader file ?

Best,
Hamdi

Yes. Have done that. And it definitely simplifies maintenance.
Do something like this:


#ifdef VERTEX_SHADER
...
#endif

#ifdef FRAGMENT_SHADER
...
#endif

Now in your program after you load this file before you compile it, simply prepend a short preamble with the #version and the #define to indicate which shader you’re compiling. For example:


#version 300

#define VERTEX_SHADER

before you throw this at glCompileShader. You can do that either by manually prepending this string to the loaded shader source before feeding it to glShaderSource, or you can just feed these in as separate strings to glShaderSource and let the GLSL compiler do this internally.

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