Can you look sample a texture in a vertex shader?

拟墨画扇 提交于 2019-12-24 02:13:10

问题


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

回答1:


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 ] ;



回答2:


YES, but you must use SampleLevel to sample. You can also load values directly from the texture using mytexture[xy_coord] or texture.Load(...) which provides values without 'sampling' (e.g. bilinear interpolation).

You can sample a texture in a vertex shader using the SampleLevel function, where you must also specify the mip-mapping level that you want to sample at. You can imagine that the Sample function uses the SampleLevel function internally, with the added benefit that the mip-mapping level is selected for you automatically by taking local derivatives of the texture coordinate lookup in screen space (this allows the GPU to select which mip level to use).

https://msdn.microsoft.com/en-us/library/windows/desktop/bb509699(v=vs.85).aspx



来源:https://stackoverflow.com/questions/8514695/can-you-look-sample-a-texture-in-a-vertex-shader

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!