https://github.com/mattdesl/lwjgl-basics/wiki/GLSL-Versions
GLSL Versions
OpenGL Version |
GLSL Version |
2.0 |
110 |
2.1 |
120 |
3.0 |
130 |
3.1 |
140 |
3.2 |
150 |
3.3 |
330 |
4.0 |
400 |
4.1 |
410 |
4.2 |
420 |
4.3 |
430 |
GLSL ES Versions (Android, iOS, WebGL)
OpenGL ES has its own Shading Language, and the versioning starts fresh. It is based on OpenGL Shading Language version 1.10.
OpenGL ES Version | GLSL ES Version |
2.0 | 100 |
3.0 | 300 |
So, for example, if a feature is available in GLSL 120, it probably won't be available in GLSL ES 100 unless the ES compiler specifically allows it.
Vertex shader:
uniform mat4 projTrans;
attribute vec2 Position;
attribute vec2 TexCoord;
varying vec2 vTexCoord;
void main() {
vTexCoord = TexCoord;
gl_Position = u_projView * vec4(Position, 0.0, 1.0);
}
Fragment shader:
uniform sampler2D tex0;
varying vec2 vTexCoord;
void main() {
vec4 color = texture2D(tex0, vTexCoord);
gl_FragColor = color;
}
As of GLSL 130+, in
and out
are used instead of attribute
and varying
. GLSL 330+ includes other features like layout qualifiers and changes texture2D
to texture
.
Vertex shader:
#version 330
uniform mat4 projTrans;
layout(location = 0) in vec2 Position;
layout(location = 1) in vec2 TexCoord;
out vec2 vTexCoord;
void main() {
vTexCoord = TexCoord;
gl_Position = u_projView * vec4(Position, 0, 1);
}
Fragment shader:
#version 330
uniform sampler2D tex0;
in vec2 vTexCoord;
//use your own output instead of gl_FragColor
out vec4 fragColor;
void main() {
//'texture' instead of 'texture2D'
fragColor = texture(tex0, vTexCoord);
}
float a[5] = float[5](3.4, 4.2, 5.0, 5.2, 1.1);
float b[5] = float[](3.4, 4.2, 5.0, 5.2, 1.1);
uniform float val = 1.0;
sin()
when setting a const
valuefloat f = 1.0; <-- valid
float g = 1; <-- only supported in GLSL 120
vec2 v = vec2(1, 2.0); <-- only supported in GLSL 120
f
to define a float: float f = 2.5f;
int
and uint
support (and bitwise operations with them)switch
statement supporttrunc()
, round()
, roundEven()
, isnan()
, isinf()
, modf()
in
and out
syntax instead of attribute
and varying
texture()
should now be used instead of texture2D()
layout(location = 2) in vec3 values[4];
ARB_explicit_attrib_location
extension