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的用法的更多相关文章

  1. (OpenGL ES 2.0 Shading Language) attribute 、uniform 和 varying

    一:attribute .uniform 和 varying 都是glsl的变量的内存指示器(storage qualifiers),指明变量的内存特性 二:attribute attribute 是 ...

  2. HTML <meta> Attribute

    HTML <meta> Attribute http-equiv 定义和用法 The http-equiv attribute provides an HTTP header for th ...

  3. Python中flatten用法

    Python中flatten用法 原创 2014年04月16日 10:20:02 标签: Python / flatten 22667 一.用在数组 >>> a = [[1,3],[ ...

  4. Cesium原理篇:6 Render模块(3: Shader)

    在介绍Renderer的第一篇,我就提到WebGL1.0对应的是OpenGL ES2.0,也就是可编程渲染管线.之所以单独强调这一点,算是为本篇埋下一个伏笔.通过前两篇,我们介绍了VBO和Textur ...

  5. Cesium原理篇:6 Render模块(5: VAO&RenderState&Command)

    VAO VAO(Vertext Array Object),中文是顶点数组对象.之前在<Buffer>一文中,我们介绍了Cesium如何创建VBO的过程,而VAO可以简单的认为是基于VBO ...

  6. Web3D编程入门总结——WebGL与Three.js基础介绍

    /*在这里对这段时间学习的3D编程知识做个总结,以备再次出发.计划分成“webgl与three.js基础介绍”.“面向对象的基础3D场景框架编写”.“模型导入与简单3D游戏编写”三个部分,其他零散知识 ...

  7. Cocos2dx中的opengl使用(一)简单介绍

    引擎提供了CCGLProgram类来处理着色器相关操作,对当前绘图程序进行了封装,其中使用频率最高的应该是获取着色器程序的接口:const GLuint getProgram(); 该接口返回了当前着 ...

  8. GLSL Notes

    [GLSL Notes] API of shader: glCreateShader(), glShaderSource(), glCompileShader(), glGetShadrInfoLog ...

  9. 在 html 中用加色法混合颜色

    概要 本文通过解决一个假想的问题介绍了 css screen 混合模式,并介绍了如何用 svg 滤镜.canvas 2d.canvas webgl 实现相同的效果. 问题 下面的图片演示三种颜色光叠加 ...

随机推荐

  1. 快速读入fread

    struct FastIO { static const int S = 1e7; int wpos; char wbuf[S]; FastIO() : wpos(0) {} inline int x ...

  2. 第5章——使用 Razor(MVC框架视图引擎)

    Razor 是MVC框架视图引擎的名称. 本章提供 Razor 语法的快速教程,以使你能够识别 Razor 表达式. 本章不打算提供 Razor 的完整参考,而将其视为一个语法速成教程.在本书的后续内 ...

  3. ES profile 性能优化用——返回各个shard的耗时

    Profile API 都说要致富先修路,要调优当然需要先监控啦,elasticsearch在很多层面都提供了stats方便你来监控调优,但是还不够,其实很多情况下查询速度慢很大一部分原因是糟糕的查询 ...

  4. Java多线程的同步控制记录

    Java多线程的同步控制记录 一.重入锁 重入锁完全可以代替 synchronized 关键字.在JDK 1.5 早期版本,重入锁的性能优于 synchronized.JDK 1.6 开始,对于 sy ...

  5. PHP:第三章——PHP中嵌套函数和条件函数

    PHP中的嵌套函数: <?php header("Content-Type:text/html;charset=utf-8"); function A(){ echo &qu ...

  6. httpclient http状态管理

    HTTP状态管理 最初,Htt被设计成一个无状态的面向请求响应的协议,所以它不能再逻辑相关的http请求/响应中保持状态会话. 由于越来越多的系统使用http协议,其中包括http从来没有想支持的系统 ...

  7. vuex 简单理解

    废话不多说,直接上图!                 不懂的 参考 API

  8. Redis (一) 概念安装

    一.阿里云安装Redis 1.安装Redis yum -y install redis 2.启动Redis service redis start 或者(推荐使用) systemctl start  ...

  9. stringBuild置空方法

    参看连接:http://blog.csdn.net/roserose0002/article/details/6972391

  10. start with...connect by子句的浅用

    start with的用法,其基本语法如下: select … from tablename start with 条件1connect by 条件2where 条件3; 但是我在pl/sql中写入以 ...