Jump to content
  • Advertisement
Sign in to follow this  
zolwik

DX11 Sampling texture in vertex shader

This topic is 2341 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have trouble with sampling texture in vertex shader and I couldn't find much info on the web.

Loading texture:


D3DX11_IMAGE_LOAD_INFO info;
info.Format = DXGI_FORMAT_R16_UNORM ; // tried also DXGI_FORMAT_R32_FLOAT
info.MipLevels = 1;
D3DX11CreateShaderResourceViewFromFile(device, L"heightmap.png", &info, NULL,&pHeightMapSRV,NULL);


I use D3D11_FILTER_MIN_MAG_MIP_POINT sampler. I declare texture in VS as Texture2D<float>. It makes no difference whether I use
texture.SampleLevel( sampler, In.UV, 0 ), or texture.Load( float3( In.UV.x,In.UV.y,0 )) in vertex shader. Sampling just returns 0.
UVs and texture seems ok, as pixel shader samples without problems.

Any ideas what could be done wrong?

Share this post


Link to post
Share on other sites
Advertisement
Did you try texture.SampleLevel( sampler, In.UV, 1 ) instead? I've had some issues in the past with weird LOD conventions, especially when you mess around with LOD settings in DirectX. I believe if you don't need LOD, you should set info.MipLevels to zero instead of one.

PS: btw, Load uses discrete integer coordinates (with int3), so that Load returns 0 is correct behaviour with those parameters.

Share this post


Link to post
Share on other sites
Are you sure that the texture is even loading correctly? You don't seem to be checking the return result. Did you enable the DEBUG flag when creating the device, and link to the debug verison of D3DX? Are you sure that the texture is bound to the proper shader resource slot for the vertex shader stage?

Share this post


Link to post
Share on other sites
Well I do check errors, just stripped that here for clearer code. I use same texture and sampler in PS and I set them for both PS and VS. PS draws texture correctly, but VS just gives 0. I tried sampling at mipmap level 1, and scaling coordinates by texture size for Load. I tried also setting MipLevels for 0, but why would it help? Setting 0 just forces to generate whole chain of mipmaps. I have no idea what can cause it. Maybe there are some options that should, or shouldn't be set somewhere? But I don't think I made anything extraordinary.


[SOLVED]
Uff, why didn't I think earlier about drawing wireframes? Double bug in uv and positions caused texture to draw fine in PS, but sampled from bad coordinates in VS :D.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!