GLSL coding style
Where applicable, also use the above C++ style for coding GLSL shader programs.
General file structure
Met.3D uses the glfx framework. glfx unifies vertex, geometry and fragment
shader programs in a single source file, a .glsl
file.
Use the same license and copyright header as for the C++ files. Following the
header, the general structure of the .glsl
files in Met.3D is:
1/****************************************************************************
2*** CONSTANTS ***
3*****************************************************************************/
4
5// Use the `const` datatype instead of `#define`.
6const float MISSING_VALUE = -999.E9;
7
8
9/****************************************************************************
10*** INTERFACES ***
11*****************************************************************************/
12
13// Interfaces connect different shader stages.
14interface GStoFS
15{
16 smooth vec4 colour;
17};
18
19
20/****************************************************************************
21*** UNIFORMS ***
22*****************************************************************************/
23
24// Definition of uniform variables common to all shader stages.
25uniform mat4 mvpMatrix;
26
27
28/****************************************************************************
29*** INCLUDES ***
30*****************************************************************************/
31
32// Include files.
33#include "filename.glsl"
34
35/****************************************************************************
36*** VERTEX SHADER ***
37*****************************************************************************/
38
39shader VSmain(in vec2 worldXY, out vec3 worldPos)
40{
41 // .. some code ..
42}
43
44
45/****************************************************************************
46*** GEOMETRY SHADER ***
47*****************************************************************************/
48
49shader GSmain(in vec3 worldPos[], out GStoFS output)
50{
51 // .. some code ..
52}
53
54
55/****************************************************************************
56*** FRAGMENT SHADER ***
57*****************************************************************************/
58
59shader FSmain(in GStoFS input, out vec4 fragColor)
60{
61 // .. some code ..
62}
63
64
65/****************************************************************************
66*** PROGRAMS ***
67*****************************************************************************/
68
69// You can define multiple shader programs using the following syntax:
70// vs(number_of_gl_version)=functionName();
71// gs(number_of_gl_version)=functionName() : in(geom_in), out(geom_out, max_vertices=max, stream=num)
72// fs(number_of_gl_version)=functionName();
73
74program SomeFancyOpenGlShader
75{
76 vs(420)=VSmain();
77 gs(420)=GSmain() : in(points), out(line_strip, max_vertices = 4);
78 fs(420)=FSmain();
79};
Comments
Since there are no header files in GLSL, please put Doxygen-style comments for a function above the function definition.