PDA

View Full Version : GLSL Shader File Extensions



Kip Warner
01-28-2010, 06:48 PM
What, if any, are the recommended file extensions for the shader, geometric, and fragment shaders? I've seen *.glslv and *.vert, to name a few, for the former.

Kip

Jan
01-28-2010, 07:17 PM
OpenGL shaders have no native file format, so there is no file extension, at all.

Some people put each shader into a single file and then call them ".vert" or ".frag", others put all shaders into a single file, seperated by some markers and call them ".glsl" or just ".shader". It's entirely up to you. There simply is no standard, at all.

Jan.

Kip Warner
01-28-2010, 07:46 PM
Thanks Jan. I realized there was no standard extension, assuming they wish to store it on disk as a standalone text file. I was just curious what common conventions people use when they do.

Do people typically have general purpose matrix transformation routines in another shader file, and then attach that to every shader program they use whenever their shaders need to perform things like translation, rotations, reset to identity matrix, etc? Or do they copy and paste general routines like these into every shader file manually? Or do people perhaps implement something like #include?

Jan
01-29-2010, 05:03 AM
Puh, i don't know what people "typically" do. Personally i implemented my own #include, but i think most people start with the most simple solution, which is to manually copy such functions into each shader, that needs it.

In a more complex engine, one can assume that something like #include is supported, but since every program needs to handle that on its own, most people won't go to such great lengths and have simpler, less powerful solutions.

Jan.

Kip Warner
01-29-2010, 12:19 PM
Interesting. Yes, I figured #include must come in at some point. One of my concerns was in trying to find compile time errors in shaders since the line numbers would be displaced from the text insertions. I imagine one can use the #line directive to work around that?

Jan
01-29-2010, 06:03 PM
Don't know about #line, but what i do, is to simply write out the entire shader, when an error is detected. So i append the text-files, compile the shader, and when an error appears, i log the whole shader, with line-numbers automatically inserted. That way people can easily see where the problem is. Also one should log the file-name of the main-source-file.

Jan.

pjcozzi
01-29-2010, 06:22 PM
I believe #line should work, or if its possible to implement #include by passing multiple strings to glShaderSource, you can leave the original shader string untouched. This is what I do when I make a set of constants available to all shaders.

Regards,
Patrick

Kip Warner
01-30-2010, 02:12 AM
Thanks you two. When the time comes, I will give the #line trick a shot.