Search code examples
hlsldirect3d11

Can you look sample a texture in a vertex shader?


In shader model 3.0, I'm pretty sure this was a no but I want to ask this anyway,

In shader model 5.0, can you sample a texture in a vertex shader?

If I want to make large amounts of supplementary information available per-vertex, what are my options?

Edit: Apparently it is possible to do a Vertex Texture Fetch, as done here, but when I try it in my hlsl shader model 5 program, I get the error

error X4532: cannot map expression to vs_5_0 instruction set

Solution

  • Yes, sampling a texture from a vertex shader is very easily done in Shader Model 5.0, using operator[ unint2 ] on any Texture2D object.

    So for example, tex0 is a Texture2D object in a shader model 5 hlsl program:

    Texture2D tex0 : register( t0 );
    
    // in a vertex shader program
    uint2 pos_xy = { 0, 1 } ;
    texelColor = tex0[ pos_xy ] ;