Search code examples
glslvulkan

What is the difference between sampler2Drect and sampler2d?


as the glsl spec said

gvec4 texture(  gsampler2D sampler,
    vec2 P,
    [float bias]);
gvec4 texture(  gsampler2DRect sampler,
    vec2 P);

and i tested this two condition in vulkan. I bind the same image data and give the same coordinate. The results are same. So what is the difference between them. Can i construct the condition which sampler2D and sampler2DRect have different result?


Solution

  • The most important difference between a 2D texture and a rectangle texture is that 2D textures actually work in Vulkan while rectangle textures don't.

    Rectangle textures are an old vestige of OpenGL, one that Vulkan does not use. For OpenGL, a rectangle texture is a special texture type (distinct from a 2D texture) that has exactly one mipmap and whose texture coordinates are not normalized, but you can still have filtering. The unnormalized texture coordinates are a particular feature of rectangle textures.

    In Vulkan and SPIR-V, whether texture coordinates are normalized or not is a part of the sampler, not of the texture type. So you can get the same effect of a rectangle texture by setting the appropriate parameter in the sampler and using textureLod in your GLSL shader (and sampler2D as the sampler type). You need to use textureLod because texture relies on implicit LOD computations, which Vulkan doesn't allow on unnormalized coordinates.