glsl/es version number
2016-01-08 15:51
260 查看
https://github.com/mattdesl/lwjgl-basics/wiki/GLSL-Versions
You can use the
GLSL versions are released alongside GL versions. See the following charts to decide which version you would like to target.
OpenGL ES has its own Shading Language, and the versioning starts fresh. It is based on OpenGL Shading Language version 1.10.
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.
Differences between (desktop) GLSL versions.
Vertex shader:
Fragment shader:
As of GLSL 130+,
used instead of
GLSL 330+ includes other features like layout qualifiers and changes
Vertex shader:
Fragment shader:
You can initialize arrays within a shader, like so:
However, the above is not supported on Mac OSX Snow Leopard, even with GLSL 120. (1)
You can initialize uniforms in a shader, and the value will be set at link time:
You can use built-ins like
Integers are implicitly converted to floats when necessary, for example:
You can use
(and bitwise operations with them)
New built-ins:
Fragment output can be user-defined
Input and output is declared with
instead of
Layout qualifiers can declare the location of vertex shader inputs and fragment shader outputs, eg:
Formally this was only possible with
You can use the
#versioncommand as the first line of your shader to specify GLSL version:
#version 120 void main() { gl_FragColor = vec4(1.0); }
GLSL versions are released alongside GL versions. See the following charts to decide which version you would like to target.
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 |
Differences
at a Glance
Differences between (desktop) GLSL versions.
Version
100
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; }
Version
330
As of GLSL 130+, inand
outare
used instead of
attributeand
varying.
GLSL 330+ includes other features like layout qualifiers and changes
texture2Dto
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); }
Other
Significant Changes
GLSL
120 Additions
You can initialize arrays within a shader, like so: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);
However, the above is not supported on Mac OSX Snow Leopard, even with GLSL 120. (1)
You can initialize uniforms in a shader, and the value will be set at link time:
uniform float val = 1.0;
You can use built-ins like
sin()when setting a
constvalue
Integers are implicitly converted to floats when necessary, for example:
float f = 1.0; <-- valid float g = 1; <-- only supported in GLSL 120 vec2 v = vec2(1, 2.0); <-- only supported in GLSL 120
You can use
fto define a float:
float f = 2.5f;
GLSL
130 Additions
intand
uintsupport
(and bitwise operations with them)
switchstatement support
New built-ins:
trunc(),
round(),
roundEven(),
isnan(),
isinf(),
modf()
Fragment output can be user-defined
Input and output is declared with
inand
outsyntax
instead of
attributeand
varying
GLSL
150 Additions
texture()should now be used instead of
texture2D()
GLSL
330 Additions
Layout qualifiers can declare the location of vertex shader inputs and fragment shader outputs, eg:layout(location = 2) in vec3 values[4];
Formally this was only possible with
ARB_explicit_attrib_locationextension
相关文章推荐
- Maven导入Servlet和JSP jar包
- C# 启动停止SQLServer数据库服务器
- IOS 银行卡每输入4位自动加空格
- PDF转PPT方法
- The run destination "设备名称" is not valid for Running the scheme '项目名称'.
- 引入框架报_OBJC_CLASS_$_CTTelephonyNetworkInfo错误,需要引入CoreTelephony.framework框架
- 用800行代码做个行为树(Behavior Tree)的库(1)
- python3.5之mysql扩展
- 视频音量控制器UISlider
- Failed to sync Gradle Project "xxx"解决方案
- Redis学习记录之配置文件(三)
- <四> H264解码输出yuv文件
- 使用curl进行s3服务操作
- centos下搭建svn服务器端/客户端
- 页面无刷新ajax上传文件--模拟iframe,超简单
- 关于使用WKWebViewJavascriptBridge报错的问题
- 如何杀掉(kill)Oracle中的会话(Session)
- rsync+inotify实现实时同步案例
- python 字典(Directionary)
- 关于Android EditText密码显示隐藏切换