Splitting shader source files

Hello,

Is it possible to split a big vertex/fragment
Source program to small vertex/fragment source
Program files?
let say I have big.vert & big.frag that contain


main(){


f1();
f2();
f3();
f4();


}
f1() - f4() … - implementation

and I want to split/move f1()-f4() to different
source file (f1.vert,f1.frag,f2.vert,f2.frag…)

Thanks
Amir

Should be no problem. Just load all the files you need and pass multiple strings to glShaderSourceARB().

In GLSL every fragment/vertex program can be made of multiple fragment/vertex shader objects.
Each one of such shader objects would represent one source file.

Thanks!.
Thanks!.
Do you know if it’s possible to combine different
vertex/vertex program (made of different vertex/fragment object, taken from different source file) in the same rendering pass?
say i have my own lighting shader program (made from different shader/fragment object/source)
and i want to add another vertex/fragment program that operates on this shader program results.

No, you can’t combine program objects directly, but you could render first pass to texture and use this texture in second pass when rendering to screen.
But what you probably need is something like this:
Fragment program 1:
-fragment shader 1 - main() - calls f1()
-fragment shader 2 - f1()

Fragment program 2:
-fragment shader 3 - main() - calls f2()
-fragment shader 4 - f2()

Combined fragment program:
-fragment shader 5 - main() - calls f1() and f2()
-fragment shader 2 - f1()
-fragment shader 4 - f2()

So, create new main() function for new shader and call the same functions that other shaders.

Note that you could also do something like this:

Fragment program 1:
-fragment shader 1 - main() - calls f1() and f2()
-fragment shader 2 - f1()
-fragment shader 3 - empty f2()

Fragment program 2:
-fragment shader 1 - main() - calls f1() and f2()
-fragment shader 2 - f1()
-fragment shader 4 - f2()

This way your main() function is always the same, but you just link different combinations of fragment shaders with functions f1() and f2(). So, program 1 has only one effect enabled and program 2 has both effects enabled.

I’ll give it a try
Thanks!

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