Vulkan sampler doens't show correct border color

Viewed 244

I sample a texture (its format is vk::Format::eR8G8B8A8Unorm) beyond the image with "clamp to border" and set the border color to be opaque white. But the rendered border color I get is always black ,and I can't find why.

Here are the sampler settings that are relevant :

vk::SamplerCreateInfo samplerInfo = {};
samplerInfo.addressModeU  = vk::SamplerAddressMode::eClampToBorder;
samplerInfo.addressModeV  = vk::SamplerAddressMode::eClampToBorder;
samplerInfo.addressModeW  = vk::SamplerAddressMode::eClampToBorder;
samplerInfo.borderColor = vk::BorderColor::eIntOpaqueWhite;
  1. I checked with other type of addressing modes: vk::SamplerAddressMode::eRepeat, vk::SamplerAddressMode::eMirroredRepeat, and vk::SamplerAddressMode::eClampToEdge and they all work correctly.

  2. I replaced vk::BorderColor::eIntOpaqueWhite with vk::BorderColor::eFloatOpaqueWhite and then I got the white color - but it is strange, because if the texture format is vk::Format::eR8G8B8A8Unorm I would expect that the needed flag is the integer form - vk::BorderColor::eIntOpaqueWhite as explained here : https://vulkan-tutorial.com/Texture_mapping/Image_view_and_sampler ?

Thanks

1 Answers

Fixed-point formats like UNORM are converted to floats when read, and floats written to them are converted to normalized fixed-point values. Texel replacement (by the border color) happens after this conversion. So at that point, the format is treated as a floating-point format, not an integer one.

Indeed, fixed-point formats are pretty much always treated like floating-point formats, except in the specifics of how their data maps to memory.

Related