Search code examples
glsltexturesvulkansampling

Is there a sample-less cubemaps in vulkan?


In my game-engine all the static textures are bounded on an one big descriptor set(I using dynamic indexing for that), and now i also want to bind a cube-texture at orbitrary index inside this descriptors array. All my textures bounded saperatly without any sampler(I am using glsl-extention named "GL_EXT_samplerless_texture_functions" for that).

Is there a way in vulkan-glsl to implement a cube-sampling of sample-less texture?

Sorry about my English.


Solution

  • The texelFetch functions are intended for accessing a specific texel from a given mipmap level and layer of the image. The texture coordinates are explicitly in "texel space", not any other space. No translation is needed, not even denormalization.

    By contrast, accessing a cubemap from a 3D direction requires work. The 3D direction must be converted into a 2D XY texel coordinate and a face within the cubemap.

    Not doing translations of this sort is the entire point of texelFetch. This is what it means to access a texture without a sampler. So it doesn't make sense to ever texelFetch a cubemap (and only the texelFetch functions are available for accessing a texture without a sampler).

    So if you want to access a cubemap, you want one of two things:

    1. You want to pass a 3D direction, which gets converted into a 2D coordinate and face index.

      You need a sampler for that. Period.

    2. You have a 2D coordinate in texture space and a face index, and you want to access that texel from the texture.

      In this case, you're not accessing a cubemap; you're accessing a 2D array texture. Indeed, there is no such thing in Vulkan as a "cubemap image"; there is merely a 2D array image which has a flag set on it that allows it to be associated with cubemap image views. That is, a "cubemap" is a special way of accessing a 2D array. But you can just as easily create a 2D array view of the same image and bind that to the descriptor.

      So do that.