Shader基础知识

  • 1、It is expected that graphics hardware will have a small number of fixed vector locations for passing vertex inputs. Therefore, the OpenGL Shading language defines each non-matrix input variable as taking up one such vector location. There is an implementation dependent limit on the number of locations that can be used, and if this is exceeded it will cause a link error. (Declared input variables that are not statically used do not count against this limit.) A  scalar input counts the same amount against this limit as a vec4, so applications may want to consider packing groups of four unrelated float inputs together into a vector to better utilize the capabilities of the underlying hardware.  A matrix input will use up multiple locations.
    The number of locations used will equal the number of columns in the matrix.

    大致意思:顶点渲染程序所传入的(attribute)参数是有个数限制的,非矩阵的参数将占据一个向量位置。超过限制将会导致链接出错,所有最后将float型变量打包成向量传入。

 

  • There is an implementation dependent limit on the amount of storage for uniforms that can be used for each type of shader and if this is exceeded it will cause a compile-time or link-time error. Uniform variables that are declared but not used do not count against this limit. The number of user-defined uniform variables and the number of built-in uniform variables that are used within a shader are added together to determine whether available uniform storage has been exceeded.  (Uniform 变量数量)

     

  • Shader的自定义结构体如果没有定义其实例名称,则结构体内部声明的变量名称将处于全局命名空间中。在shader文件之外(如opengl API程序中),将使用结构体的名称加 “.” 来标示,而不是结构体实例名。如下所示:
  1. out Vertex {
        vec4 Position;  // API transform/feedback will use “Vertex.Position”
        vec2 Texture;
    } Coords;           // shader will use “Coords.Position”
    out Vertex2 {
        vec4 Color;     // API will use “Color”
    };
  • Each of these qualifiers may appear at most once.  If index is specified, location must also be specified.  If index is not specified, the value 0 is used.  For example, in a fragment shader,

  1. layout(location = 3) out vec4 color;


will establish that the fragment shader output color is assigned to fragment color 3 as the first (index zero) input to the blend equation.  

什么意思?

  • vertShader和geomShader之间的参数传递:名字不相同(geomShader多个“[ ]"数组符号),类型相同,修饰符相同(smooth,flat,noperspective)(geomShader中多”in“标示符)

    geomShader和fragShader之间的参数传递:名字相同,类型相同,修饰符相同,(geomShader中多“out”标示符,且无法使用inout)

 

  • geomShader的输入类型和输出类型:
  1.      /**    

  2.      * Geometry Shader Input Type:
         * GL_POINTS, GL_LINES, GL_LineStrip,GL_LineLoop,GL_TRIANGLES, GL_Triangles_Strip,GL_Triangle_Fan
         * ARBGeometryShader4.GL_LINES_ADJACENCY_ARB, ARBGeometryShader4.GL_LINE_STRIP_ADJACENCY_ARB,
         * ARBGeometryShader4.GL_TRIANGLES_ADJACENCY_ARB, ARBGeometryShader4.GL_TRIANGLE_STRIP_ADJACENCY_ARB,
         */

  3.     /**
         * Geometry Shader Output Type:
         * GL_POINTS, GL_LINE_STRIP, GL_TRIANGLE_STRIP
         */
  • Transform Feedback.
    (If a geometry shader is active, its output primtive type is used instead of the <mode> parameter passed to Begin for the purposes of this error check.)
意思是:如果geometry shader启用,那么为了不至于出现INVALID_OPERATION错误,Transform Feedback的输出图元类型将采用geometry shader的输出图元类型,而不是在Begin函数中所
输入的图元类型??
  1. CapturePrimitiveMode               allowed render primitive modes
          ----------------------      ---------------------------------
          POINTS                      POINTS
          LINES                       LINES, LINE_LOOP, and LINE_STRIP
          TRIANGLES                   TRIANGLES, TRIANGLE_STRIP,
                                      TRIANGLE_FAN, QUADS, QUAD_STRIP,
                                      and POLYGON
    

This article was written in springnote.

posted @ 2012-02-06 11:38  ActionFG  阅读(581)  评论(0编辑  收藏  举报