这意味着float顶点属性占用的插槽与vec2,vec3或vec4相同.并且大于vec4的类型占用多个插槽. mat4顶点属性占用4 x vec4个存储单位. dvec4(双精度向量)顶点属性为2 x vec4.由于实现仅需要提供16个唯一的顶点属性槽,因此,如果您天真地使用单个float属性,则可以轻松耗尽所有可用的存储空间,仅用于存储4x4矩阵.没有解决方法.与制服不同(标量GPU可能比vec4更有效地存储float制服),属性始终绑定到4分量数据类型.因此,对于顶点属性,将属性打包到向量中非常重要.我更新了答案,以指出GL和GLSL规范的相关摘录: OpenGL 4.4核心配置文件规范- 10.2.1当前的通用属性-第307页 顶点着色器(请参见 11.1 节)访问4成分通用顶点数组 属性.该数组的第一个插槽编号为零,数组的大小为 由与实现相关的常量 GL_MAX_VERTEX_ATTRIBS 指定. GLSL 4.40规范- 4.4.1输入布局资格赛-第60页 如果顶点着色器输入是任何标量或矢量类型,它将占用一个位置.如果非顶点着色器输入是 dvec3 或 dvec4 以外的标量或矢量类型,则它将使用单个位置,而类型为 dvec3 或 dvec4 将占用两个连续的位置.在所有阶段,类型为 double 和 dvec2 的输入将仅占用一个位置.诚然,针对dvec4所述的行为略有不同.在 GL_ARB_vertex_attrib_64bit 格式中,双精度类型可能会消耗两倍的时间存储为浮点数,这样dvec3或dvec4可能会占用两个属性插槽.当它被提升为核心时,这种行为发生了变化……他们只是被假定为在顶点阶段消耗了1个位置,在其他任何阶段都可能消耗了更多位置.双精度向量类型的原始(扩展)行为: 名称 ARB_vertex_attrib_64bit [...] 此外,一些顶点着色器输入使用更宽的64位组件 可能会因实施相关的数量限制而增加一倍 着色器属性向量集. 64位标量或两个分量 向量仅消耗单个通用顶点属性;三和 四部分长"可能算作两个.这种方法类似于 当前GL中使用的一种,其中矩阵属性消耗多个 属性. I have a question about resource consumption of attribute float in glsl. Does it take as many resources as vec4, or no?I ask this, because uniforms takes https://stackoverflow.com/a/20775024/1559666 (at least, they could)If it is not, then does it makes any sense to pack 4 float's into one vec4 attribute? 解决方案 Yes, all vertex attributes require some multiple of a 4-component vector for storage.This means that a float vertex attribute takes 1 slot the same as a vec2, vec3 or vec4 would. And types larger than vec4 take multiple slots. A mat4 vertex attribute takes 4 x vec4 many units of storage. A dvec4 (double-precision vector) vertex attribute takes 2 x vec4. Since implementations are only required to offer 16 unique vertex attribute slots, if you naively used single float attributes, you could easily exhaust all available storage just to store a 4x4 matrix.There is no getting around this. Unlike uniforms (scalar GPUs may be able to store float uniforms more efficiently than vec4), attributes are always tied to a 4-component data type. So for vertex attributes, packing attributes into vectors is quite important.I have updated my answer to point out relevant excerpts from the GL and GLSL specifications:OpenGL 4.4 Core Profile Specification - 10.2.1 Current Generic Attributes - pp. 307 Vertex shaders (see section 11.1) access an array of 4-component generic vertex attributes. The first slot of this array is numbered zero, and the size of the array is specified by the implementation-dependent constant GL_MAX_VERTEX_ATTRIBS.GLSL 4.40 Specification - 4.4.1 Input Layout Qualifiers - pp. 60 If a vertex shader input is any scalar or vector type, it will consume a single location. If a non-vertex shader input is a scalar or vector type other than dvec3 or dvec4, it will consume a single location, while types dvec3 or dvec4 will consume two consecutive locations. Inputs of type double and dvec2 will consume only a single location, in all stages.Admittedly, the behavior described for dvec4 differs slightly. In GL_ARB_vertex_attrib_64bit form, double-precision types may consume twice as much storage as floating-point, such that a dvec3 or dvec4 may consume two attribute slots. When it was promoted to core, that behavior changed... they are only supposed to consume 1 location in the vertex stage, potentially more in any other stage.Original (extension) behaviour of double-precision vector types: Name ARB_vertex_attrib_64bit [...] Additionally, some vertex shader inputs using the wider 64-bit components may count double against the implementation-dependent limit on the number of vertex shader attribute vectors. A 64-bit scalar or a two-component vector consumes only a single generic vertex attribute; three- and four-component "long" may count as two. This approach is similar to the one used in the current GL where matrix attributes consume multiple attributes. 这篇关于GLSL将4个float属性打包到vec4中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-19 00:49