Hello Guest

Vulkan sampler coordinates

  • 4 Replies
  • 336 Views
Vulkan sampler coordinates
« on: December 11, 2018, 06:28:32 »
Hi

Vulkan uses U,V,W as sampler coordinates and opengl uses R,S,T. Would I be correct in saying the translation from one to the other is?

S -> U
T -> V
R - W

*

Offline KaiHH

  • ***
  • 176
Re: Vulkan sampler coordinates
« Reply #1 on: December 11, 2018, 08:01:18 »
Vulkan itself has no notion of how the texture coordinates are called/named/accessed. Even SPIR-V does not have names for the texture coordinates components.
See for example: https://www.khronos.org/registry/spir-v/specs/1.0/SPIRV.html#OpImageSampleImplicitLod
It is just a vector where the first component is the x dimension (however you'd like to call that dimension) and the second the y dimension and any further components depending on whether a 2D/3D or array texture is accessed and whether explicit LOD is used.
How the coordinates are actually named is specified via the frontend language you define your shaders in. If you use GLSL (which you can use for both OpenGL and SPIR-V/Vulkan) then you can use either xyzw or stpq or even rgba, it does not matter. They are all translated to the first, second, third and fourth vector component and just alias themselves.

Re: Vulkan sampler coordinates
« Reply #2 on: December 12, 2018, 06:33:48 »
Kai

Thanks for the reply, I am not sure I made myself clear though as it wasn't the answer I was looking for.

In opengl I set the wrap mode as follows

Code: [Select]
            GL33.glSamplerParameteri(samplerId, GL12.GL_TEXTURE_WRAP_R, GL12.GL_CLAMP_TO_EDGE);
            GL33.glSamplerParameteri(samplerId, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT;);
            GL33.glSamplerParameteri(samplerId, GL11.GL_TEXTURE_WRAP_T, GL13.GL_CLAMP_TO_BORDER);

in vulkan there is an equivilent part of the creation process

Code: [Select]
                 VkSamplerCreateInfo createInfoSampler = VkSamplerCreateInfo.calloc()
                     .sType(VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO)
                     .addressModeU(getWrapMode(VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE)
                     .addressModeV(getWrapMode(VK_SAMPLER_ADDRESS_MODE_REPEAT)
                     .addressModeW(getWrapMode(VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER)

My question is how do I map the 2 so they are equivilent. I haven't applied any logical mappings in my examples above except for putting them in the same order which is arbitary.

*

Offline KaiHH

  • ***
  • 176
Re: Vulkan sampler coordinates
« Reply #3 on: December 12, 2018, 13:16:52 »
Oh, I see. Yeah, OpenGL's S (first component), T (second component) and R (third component) maps to Vulkan's U (first component), V (second component), W (third component).

Re: Vulkan sampler coordinates
« Reply #4 on: December 13, 2018, 14:03:54 »
Thanks, this is exactly what I needed