0
\$\begingroup\$

I want to do some texture samples in the vertex shader, but it seems this cannot be done in the same was as when using the Pixel shader.

The code is basically..

Texture2DArray   gTexture;

VS()
{
    gTexture.Sample(samPoint, float3(x, y, z)
}

PS()
{
    gTexture.Sample(samPoint, float3(x, y, z)
}

technique11 main
{
   pass P0
   {
      SetVertexShader(CompileShader(vs_4_0, VS()));
      SetGeometryShader(NULL);
      SetPixelShader(CompileShader(ps_4_0, PS()));
   }
}

The PS() will compile and work fine but I also need to do this sort of thing in VS().

When putting this code in the VS() I get: Error X4532 cannot map expression to vs_4_0 instruction set ....

I have done some googling and it looks like you can sample a texture in the VS but I cant get enough detail together to make this work.

Any help on this would be good.

Just for reference: I am using DirectX11 VS2015

\$\endgroup\$
2
\$\begingroup\$

You can not Sample a texture in vertex shader with regular sampling. You should use SampleLevel and sample a specific mip level of the texture with it. This is because you don't have screen space derivatives (ddx and ddy) in the vertex shader. In the pixel shader those are used to determine the mip level. You can also use texture.Load.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.