OpenGL 与 GLSL 版本
来源:互联网 发布:淘宝双十一红包活动 编辑:程序博客网 时间:2024/06/11 13:18
来自:https://github.com/mattdesl/lwjgl-basics/wiki/GLSL-Versions
You can use the #version
command as the first line of your shader to specify GLSL version:
#version 120void 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 VersionGLSL Version2.01102.11203.01303.11403.21503.33304.04004.14104.24204.3430GLSL 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 VersionGLSL ES Version2.01003.0300So, 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 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+, 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 330uniform 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 330uniform 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 aconst
value - Integers are implicitly converted to floats when necessary, for example:
float f = 1.0; <-- validfloat g = 1; <-- only supported in GLSL 120vec2 v = vec2(1, 2.0); <-- only supported in GLSL 120
- You can use
f
to define a float:float f = 2.5f;
GLSL 130 Additions
int
anduint
support (and bitwise operations with them)switch
statement support- New built-ins:
trunc()
,round()
,roundEven()
,isnan()
,isinf()
,modf()
- Fragment output can be user-defined
- Input and output is declared with
in
andout
syntax instead ofattribute
andvarying
GLSL 150 Additions
texture()
should now be used instead oftexture2D()
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_location
extension
- OpenGL 与 GLSL 版本
- OpenGL 与 GLSL 版本
- OpenGL 版本与GLSL版本
- OpenGL支持的GLSL Versions 版本对应
- Opengl 和 GLSL版本对应关系
- OpenGL GLSL
- OpenGL与GLSL之间变量的传递
- OpenGL版本与扩展
- glsl 与固管并存的 早期OpenGL
- opengl glsl 深度计算
- OpenGL GLSL uniform variable
- OpenGL GLSL Blocks
- OpenGL GLSL Blocks example
- OpenGL GLSL Shader Subroutines
- OpenGL GLSL访问纹理
- OpenGL GLSL 丢弃片段
- OpenGL着色语言GLSL
- OpenGL 例子 glsl
- 混杂设备驱动程序
- python安装easy_insall工具
- latex中使用proof证明时如何去掉QED(结尾的方括号)
- 写在元宵节以后
- git笔记--出现问题总结
- OpenGL 与 GLSL 版本
- LeetCode--Reorder List
- SQL UNION的用法
- library array demo
- 灰度图像--图像分割 阈值处理之迭代均值阈值
- TextView中设置不同的字体风格
- stemwin的汉字显示
- tinyxml操作实例
- URAL 1581. Teamwork