Take the 2-minute tour ×

I'm learning glsl shading and I've come across different file formats. I've seen people giving their vertex and fragment shaders .vert and .frag extensions. But I've also seen .vsh and .fsh extensions, and even both shaders together in a single .glsl file. So I'm wondering if there is a standard file format, or which way is the 'correct' one?

share|improve this question
As far as I know, they don't have "correct" extensions, as OpenGL won't read them from disk anyways. –  zneak Jun 21 '11 at 22:37
Some people call them .vs and .fs (and .gs) to make explicit what's inside. But like zneak said, it really doesn't matter, there is no "correct" thing. –  Damon Jun 21 '11 at 22:39
GEdit uses .glslv and .glslf when choosing syntax highlighting. That's the only place I've seen where it matters. –  Banthar Jun 21 '11 at 22:44
add comment

3 Answers

up vote 25 down vote accepted

There is no standard file extension for GLSL shaders. The most common ones are probably .vert and .frag, as these are the extensions that 3D Labs used in some of their tools. But that's about it for any form of standard extension.

share|improve this answer
I don't think .vert|.frag are good extension names for shaders. The extension is something which identifies the general class of a file. They should have probably called them vertex.glsl and fragment.glsl. –  Sandeep Datta Oct 11 '13 at 14:39
I was surprised too, but isn't there a slight difference in syntax between vertex and fragment shaders, @SandeepDatta? In the same way that .h and .c might share a lot in common, but they're used in different ways. –  Joseph Humfrey Feb 4 at 14:21
add comment

Identifying file type by extension is a thing specific to Windows. All other operating systems use different approaches: MacOS X stores the file type in a special metadata structure in the file system entries. Most *nixes identify files by testing their internal structure against a database of known "magic bytes"; however text editors use the extension.

Anyway, GLSL sources are just like any other program source file: plain text, and that's their file type.

The extension you may choose as you wish. I use the following naming:

  • ts.glsl
  • gs.glsl
  • vs.glsl
  • fs.glsl

but that's my choice and technically my programs don't even enforce any naming or extension scheme. The naming is for humans to read and know what's in it; having a common major extension requires me to have an syntax highlighing rule for only one file extension set.

share|improve this answer
Downvoted because OS X has been primarily using the file extension for years. –  Frederik Slijkerman Nov 14 '12 at 11:47
@FrederikSlijkerman: No, it doesn't. MacOS X is a Unix at its core and file extensions were never used there for identifying thing. Yes, standard types get standard file extensions, but that's only a human readability thing. Maybe the Finder may rely on file extensions as heuristics for some types. But if it can identify a file solely by its header or some magic bytes, it will use that. Like any Unix based system does. –  datenwolf Nov 14 '12 at 12:14
+1 I name them as effect-name-fs.glsl or effect-name-vs.glsl. –  legends2k Feb 19 at 1:30
add comment

There are two ways of writing shaders

either u can store the vertex shader, frgment shader content in a char * varname type, variable and compile,link and attach a shader to a program.

othe way is to write the seperate vertex, fragment shader file with whatever extension u like and read it to compile,link and attach a shader to the program.

so the naming convention like .vert/.frag, .vsdr/.fsdr etc..etc.. al are valid till u know how to red it...

share|improve this answer
add comment

Your Answer


