GLSL Versions和GLSL ES Versions 对比
You can use the #version
command 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 |
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 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 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 aconst
value - 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
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
GLSL Versions和GLSL ES Versions 对比的更多相关文章
- MySQL、HBase、ES的对比
hbase是列数据库,是kv结构的,ES的基于Lucene的搜索引擎的面向文档数据库吧 ES是搜索引擎,主要的优势在于快速搜索,HBase是数据库,优势在于存储数据,侧重点不同 MySQL:关系型数据 ...
- OpenGL 与 GLSL 版本号
来自:https://github.com/mattdesl/lwjgl-basics/wiki/GLSL-Versions You can use the #version command as t ...
- 着色器语言 GLSL (opengl-shader-language)入门大全
基本类型: 类型 说明 void 空类型,即不返回任何值 bool 布尔类型 true,false int 带符号的整数 signed integer float 带符号的浮点数 floating s ...
- GLSL in ShaderLab
[Syntax] However, use of raw GLSL is only recommended for testing, or when you know you will only ta ...
- GLSL 着色器程序
除了使用Cg/HSL 着色器程序以外, OpenGL 着色器语言(GLSL)着色器可以直接书写shader. 然而,使用原生的GLSL只推荐作为测试使用,或者你清晰的知道你的目标平台是 Mac OS ...
- OpenGL 4.5 Core Profile管线(GLSL与应用程序接口详解)【未完成】
之前写过一篇博客,OpenGL管线(用经典管线代说着色器内部),说的主要是OpenGL的经典管线.大家都知道,现代OpenGL已经弃用(从OpenGL 3.0开始)经典管线功能(glBegin,变换矩 ...
- 查找EBS中各种文件版本(Finding File Versions in the Oracle Applications EBusiness Suite - Checking the $HEADER)
Finding File Versions in the Oracle Applications EBusiness Suite - Checking the $HEADER (文档 ID 85895 ...
- webgl glsl
GLSL是什么? GLSL是运行在GPU上的着色器语言 GLSL有自己的语法,跟js有些不同. GLSL是一个强类型的语言,所以在写着器语言时,必须要用强类型,强类型,强类型,强类型 GLSL是着色器 ...
- 【OpenGL4.0】GLSL渲染语言入门与VBO、VAO使用:绘制一个三角形 【转】
http://blog.csdn.net/xiajun07061225/article/details/7628146 以前都是用Cg的,现在改用GLSL,又要重新学,不过两种语言很多都是相通的. 下 ...
随机推荐
- c语言 第二次实验报告
一·实验题目,设计思路,实现方法 11-7 找鞍点 一个矩阵元素的"鞍点"是指该位置上的元素值在该行上最大.在该列上最小. 本题要求编写程序,求一个给定的n阶方阵的鞍点. 利用双重 ...
- AJAX跨域问题总结
跨域是什么? 首先说下同源,同源策略是浏览器的一种安全策略,所谓同源是指,域名,协议,端口完全相同.而跨域就是不同源 ! 能够进行跨域的请求 一般a,img,link[rel=stylesheet], ...
- Python爬虫 股票数据爬取
前一篇提到了与股票数据相关的可能几种数据情况,本篇接着上篇,介绍一下多个网页的数据爬取.目标抓取平安银行(000001)从1989年~2017年的全部财务数据. 数据源分析 地址分析 http://m ...
- as版本切换导致项目损坏,无法启动。环境依赖混乱
以下方法都不管用, 新建一个项目setting的 把main拷过去就行了!!!! Error:(5, 0) Gradle DSL method not found: 'google()'Possibl ...
- AC自动机模板3【洛谷3796】
AC自动机的第三个模板 其实,个人觉得,目前我写的这三个不同的模板完全是可以合并在一起求解的. 只是,在这两个无关联的OJ上,同一个AC自动机都可以完成的问题被拆成了三道题而已. 因此,代码只需要略加 ...
- [HDU5663]Hillan and the girl
题面戳我(题面很鬼畜建议阅读一下) 题意:给出n,m,求 \[\sum_{i=1}^{n}\sum_{j=1}^{m}[gcd(i,j)\mbox{不是完全平方数}]\] 多组数据,\(n,m\le1 ...
- 如何使用Git以及GitHub
Git在程序的版本控制上有着极大的优势,下面是简单对其的简介 Git 的特点: 1 Snapshots, Not Differences 直接记录快照而非差异对比. 传统的版本控制系统(version ...
- Cassandra配置多节点集群以及使用雅虎YCSB压测Cassandra 3.11
这几天在搭Cassandra集群以及对Cassandra的性能测试,步骤还挺多,记录一下. 关于Caaandra在服务器上配置多节点集群,可以参考一下文章: http://blog.csdn.net/ ...
- OSI模型和TCP/IP协议族(三)
TCP/IP协议族 TCP/IP协议族的开发要比OSI模型更早,因此TCP/IP协议族的分层结构无法准确地与OSI模型一一对应.原始的TCP/IP协议族定义为建立再硬件基础上的四个软件层,不通过目前T ...
- WordPress文章中插入qq表情
看见一些博客中使用了QQ表情,这个效果还是很不错的,可以让文章看起来更爽,那么这个是怎么实现的呢? 下面我就来说说方法. 工具:QQ表情包,下载地址:http://yunpan.cn/cLw6UhwB ...