GLSL, Array of textures of differing size

后端 未结 2 1021
不思量自难忘°
不思量自难忘° 2020-12-13 22:04

When doing multitexturing in GLSL, is there anyway to have an indexable array of samplers where each texture is a different size? This syntax isn\'t valid:

u         


        
2条回答
  •  悲&欢浪女
    2020-12-13 22:39

    This syntax isn't valid:

    Says who? Arrays of samplers most certainly are valid (depending on the version). How you use them is a different matter.

    GLSL 1.20 and below do not allow sampler arrays.

    In GLSL 1.30 to 3.30, you can have sampler arrays, but with severe restrictions on the index. The index must be an integral constant expression. Thus, while you can declare a sampler array, you can't loop over it.

    GLSL 4.00 and above allow the index to be a "dynamically uniform integral expression". That term basically means that all instantiations of the shader (within the same draw call) must get the same values.

    So you can loop over a constant range in GLSL 4.00+, and index a sampler array with the loop counter. You can even get the index from a uniform variable. What you can't do is have the index depend on an input to the shader stage (unless that value is the same across all instances caused by the rendering command), or come from a value derived from a texture access (unless that value is the same across all instances caused by the rendering command), or something.

    The only requirement on the textures placed in arrays of samplers is that they match the sampler type. So you have to use a GL_TEXTURE_2D on all the elements of a sampler2D array. Beyond that, the textures can have any number of differences, including size. The array exists to make coding easier; it doesn't change the semantics of what is there.

    And remember: each individual element in the sampler array needs to be bound to its own texture image unit.

提交回复
热议问题