【问题标题】:Specifying Binding for Texture Arrays in glsl在 glsl 中指定纹理数组的绑定
【发布时间】:2020-05-26 20:54:46
【问题描述】:

在 glsl 420 中添加了在着色器中指定绑定的功能,而不必调用 glUniform1i。例如:

layout(binding = 0) uniform sampler2D u_Texture;

但是对于数组如何做到这一点呢?

layout(binding ?) uniform sampler2D u_Textures[16];

我希望绑定为 0,1,2,...,15。如果没有任何glUniform 电话,我就无法在 glsl 中执行此操作吗?

【问题讨论】:

    标签: opengl glsl shader


    【解决方案1】:

    OpenGL Shading Language 4.60 Specification - 4.4.5. Uniform and Shader Storage Block Layout Qualifiers:

    与 OpenGL 一起使用时,如果绑定限定符与作为数组实例化的统一块或着色器存储块一起使用,数组的第一个元素采用指定的块绑定,每个后续元素采用下一个连续绑定点

    这意味着您只需指定数组中第一个采样器的绑定点:

    layout(binding = 0) uniform sampler2D u_Textures[16];
    

    但请注意,当采样器在着色器中聚合成数组时,这些类型只能使用dynamically uniform expression 进行索引,否则纹理查找将导致未定义的值。

    我建议使用sampler2DArray(请参阅Sampler)而不是sampler2D 的数组。

    另见:
    Why are Uniform variables not working in GLSL?
    In a fragment shader, why can't I use a flat input integer to index a uniform array of sampler2D?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-13
      • 1970-01-01
      • 2021-01-05
      • 1970-01-01
      • 2011-07-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多