Pregunta

I'm developing a shader based terrain. Use VTF to fetch the height data in vertex shader. My problem is when I sample heightmap in vertex shader the returned value always is zero.

Texture2D texture;
SamplerState sampleType;
float height = texture.SampleLevel(sampleType, float4(input.tex, 0, 0), 0);

The texture loaded from BMP file (256x256x24bit) with D3DX11CreateShaderResourceViewFromFile(device, heightmap, NULL, NULL, &texture) function and passed to vertex shader with deviceContext->PSSetShaderResources(0, 1, &texture). Feature level is D3D_FEATURE_LEVEL_10_0 and shader profile is vs_4_0.

¿Fue útil?

Solución

You are calling deviceContext->PSSetShaderResources(0, 1, &texture),

which means you pass the texture to the pixel shader. You need to bind texture and sampler to the vertex shader instead, using

VSSetSamplers and VSSetShaderResources

instead.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top