zoukankan      html  css  js  c++  java
  • Vertex shader Attributes


           在VertexShader 中,和顶点相关的数据如Position、Normal、Color等等均称为Attribute,为了给VertexShader传入这些数据,必须首先知道相关Attribute在Shader中位置。在layout尚未出现之间有两种设定Attribute 位置的方法。 方法一OpenGL允许我们显示的设定Attribute的位置,方法二OpenGL帮我们设定好Attribute的位置,然后我们在程序中查询Attribute的位置。方法一要特别注意:设定Attribute的位置必须在Link Program 之前,如果在Link之后才设定Attribute的位置,需要重新Link program.

            对于下面的VertexShader:

    1 #version 330
    2  
    3 in vec3 position;
    4 in vec3 normal;
    5 in vec2 texCoord;
    6 ...

            设定Attribute位置的函数glBindAttribLocation如下:

    void glBindAttribLocation( GLuint program, GLuint index, const GLchar *name);
    Params:
    
    program: the program object handle
    index: the index to bind the attribute to
    name: the name of the vertex attribute
    

     对于上面shader中的

     

     

         

     

     

    Mismatched Attributes and Programs

    You may be wondering what happens if there is a mis-match between the attributes provided by a VAO and the vertex shader inputs. For example, we could use the position-only vertex shader with a mesh that provides attributes 0 and 1, with 0 being the position and 1 being the color.

    OpenGL is actually very lenient about this sort of thing. It also goes through some effort to fully define what information the vertex shader gets in the event of a mismatch.

    A VAO can provide attributes that a vertex shader does not use without penalty. Well, there may be a performance penalty for reading unused information, but it will still render correctly.

    If a vertex shader takes attributes that the VAO does not provide, then the value the vertex shader gets will be a vector of (0, 0, 0, 1). If the vertex shader input vector has fewer than 4 elements, then it fills them in in that order. A vec3 input that is not provided by the VAO will be (0, 0, 0).

    Speaking of which, if a VAO provides more components of an attribute vector than the vertex shader expects (the VAO provides 4 elements, but the vertex shader input is a vec2), then the vertex shader input will be filled in as much as it can be. If the reverse is true, if the VAO does not provide enough components of the vector, then the unfilled values are always filled in from the (0, 0, 0, 1) vector.

     

    reference:

    [1] http://www.arcsynthesis.org/gltut/Positioning/Tut07%20Shared%20Uniforms.html

    [2]http://www.opengl.org/wiki/Uniform_Buffer_Object

    --------------------------------------------------------------------天道酬勤!
  • 相关阅读:
    Win7 vs2017 WDK 1803 1809 驱动开发 出错 KMDF
    http 请求 post get 长度限制
    IO模式和IO多路复用(阻塞IO、非阻塞IO、同步IO、异步IO等概念)
    select/poll 和 epoll 比较
    centos查看端口被哪个应用端口占用命令
    mysql索引知识简单记录
    Spring钩子方法和钩子接口的使用详解
    mysql使用自增Id为什么存储比较快
    分布式Id教程
    如何配置JVM系统属性及获取方式System.getProperty("pname")
  • 原文地址:https://www.cnblogs.com/graph/p/2778931.html
Copyright © 2011-2022 走看看