gl attribute和uniform的用法
gl attribute和uniform的用法
http://blog.csdn.net/jackers679/article/details/6848085
attribute
attribute变量是只能在vertex shader中使用的变量。(它不能在fragment shader中声明attribute变量,也不能被fragment shader中使用)
一般用attribute变量来表示一些顶点的数据,如:顶点坐标,法线,纹理坐标,顶点颜色等
在application中,一般用函数glBindAttribLocation()来绑定每个attribute变量的位置,然后用函数glVertexAttribPointer()为每个attribute变量赋值。
glsl里面定义属性
Line 16: attribute vec3 aVertexPosition;
Line 22: gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
javascript使用属性
shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition");
Line 97: gl.enableVertexAttribArray(shaderProgram.vertexPositionAttribute);
Line 153: gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, triangleVertexPositionBuffer.itemSize, gl.FLOAT, false, 0, 0);
Line 160: gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, squareVertexPositionBuffer.itemSize, gl.FLOAT, false, 0, 0);
uniform
uniform变量就像是C语言里面的常量(const ),它不能被shader程序修改。(shader只能用,不能改)
如果uniform变量在vertex和fragment两者之间声明方式完全一样,则它可以在vertex和fragment共享使用。(相当于一个被vertex和fragment shader共享的全局变量)
uniform变量一般用来表示:变换矩阵,材质,光照参数和颜色等信息。
glsl里
Line 18: uniform mat4 uMVMatrix;
Line 22: gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
javascript里
Line 100: shaderProgram.mvMatrixUniform = gl.getUniformLocation(shaderProgram, "uMVMatrix");
Line 109: gl.uniformMatrix4fv(shaderProgram.mvMatrixUniform, false, mvMatrix);
3.varying变量
varying变量是vertex和fragment shader之间做数据传递用的。一般vertex shader修改varying变量的值,然后fragment shader使用该varying变量的值。因此varying变量在vertex和fragment shader二者之间的声明必须是一致的。application不能使用此变量。
gl attribute和uniform的用法的更多相关文章
- (OpenGL ES 2.0 Shading Language) attribute 、uniform 和 varying
一:attribute .uniform 和 varying 都是glsl的变量的内存指示器(storage qualifiers),指明变量的内存特性 二:attribute attribute 是 ...
- HTML <meta> Attribute
HTML <meta> Attribute http-equiv 定义和用法 The http-equiv attribute provides an HTTP header for th ...
- Python中flatten用法
Python中flatten用法 原创 2014年04月16日 10:20:02 标签: Python / flatten 22667 一.用在数组 >>> a = [[1,3],[ ...
- Cesium原理篇:6 Render模块(3: Shader)
在介绍Renderer的第一篇,我就提到WebGL1.0对应的是OpenGL ES2.0,也就是可编程渲染管线.之所以单独强调这一点,算是为本篇埋下一个伏笔.通过前两篇,我们介绍了VBO和Textur ...
- Cesium原理篇:6 Render模块(5: VAO&RenderState&Command)
VAO VAO(Vertext Array Object),中文是顶点数组对象.之前在<Buffer>一文中,我们介绍了Cesium如何创建VBO的过程,而VAO可以简单的认为是基于VBO ...
- Web3D编程入门总结——WebGL与Three.js基础介绍
/*在这里对这段时间学习的3D编程知识做个总结,以备再次出发.计划分成“webgl与three.js基础介绍”.“面向对象的基础3D场景框架编写”.“模型导入与简单3D游戏编写”三个部分,其他零散知识 ...
- Cocos2dx中的opengl使用(一)简单介绍
引擎提供了CCGLProgram类来处理着色器相关操作,对当前绘图程序进行了封装,其中使用频率最高的应该是获取着色器程序的接口:const GLuint getProgram(); 该接口返回了当前着 ...
- GLSL Notes
[GLSL Notes] API of shader: glCreateShader(), glShaderSource(), glCompileShader(), glGetShadrInfoLog ...
- 在 html 中用加色法混合颜色
概要 本文通过解决一个假想的问题介绍了 css screen 混合模式,并介绍了如何用 svg 滤镜.canvas 2d.canvas webgl 实现相同的效果. 问题 下面的图片演示三种颜色光叠加 ...
随机推荐
- ural Ambitious Experiment 树状数组
During several decades, scientists from planet Nibiru are working to create an engine that would all ...
- thinkphp3.2导出
public function test() { set_time_limit(0); ini_set('memory_limit', '500M'); //导入PHPExcel类库,因为PHPExc ...
- (转)使用UTL_SMTP包发送邮件
使用UTL_SMTP包发送邮件 参考文档 Email From Oracle PL/SQL (UTL_SMTP) UTL_SMTP Oracle 存储过程中发送邮件,并支持用户验证.中文标题和内容
- UA 列表
设备 系统 浏览器 User-Agent iPhone IOS QQ浏览器 Mozilla/5.0 (iPhone 84; CPU iPhone OS 10_3_3 like Mac OS X) Ap ...
- ajax 函数的相关介绍
函数serialize serialize() 是jquery对象的一个方法,其作用是将对象的包含的值序列化为一个字符串,常用在get请求中. exp: $('#formname').serializ ...
- javascript开发HTML5游戏--斗地主(单机模式part2)
最近学习使用了一款HTML5游戏引擎(青瓷引擎),并用它尝试做了一个斗地主的游戏,简单实现了单机对战和网络对战,代码可已放到github上,在此谈谈自己如何通过引擎来开发这款游戏的. 客户端代码 服务 ...
- (C#基础)Linq学习理解
一遍学习基础,一遍练习打字,很多乐趣. 代码 using System; using System.Collections.Generic; using System.Linq; using Syst ...
- CentOS 7 Crontab
Crontab默认每分钟读取 /etc/crontab 文件./etc/cron.d/目录和/var/spool/cron/目录一次,3者对应任务的建立格式是一致的,只是/var/spool/cron ...
- DevExpress v18.1新版亮点——ASP.NET篇(一)
用户界面套包DevExpress v18.1日前终于正式发布,本站将以连载的形式为大家介绍各版本新增内容.本文将介绍了DevExpress ASP.NET v18.1 的新功能,快来下载试用新版本!点 ...
- mybatis之sql执行有数据但返回结果为null
最近在使用mybatis查询数据库时,发现在pl/sql中单独执行sql时结果是有值的,但是在程序中拿到的却是null,相关配置如下: (1) <resultMap type="mon ...