I'm trying to implement a GPU based height map the simplest (and fastest) way that I know how. I passed a (.png, D3DX11CreateShaderResourceViewFromFile()) texture into the shader, and I'm attempting to sample it for the current pixel value. Seeing a float4, I'm currently assigning a color value from a channel to offset the y value.

Texture2D colorMap : register(t0);
SamplerState colorSampler : register(s0);


VOut VShader(float4 position : POSITION, float2 Texture : TEXCOORD0, float3 Normal : NORMAL)
    VOut output;

    float4 colors = colorMap.SampleLevel(colorSampler, float4(position.x*0.001, position.z*0.001, 0,0 ),0);
    position.y = colors.x*128;

    output.position = mul(position, WVP);
    output.texture0 = Texture;
    output.normal = Normal;

    return output;

The texture is imported correctly, and I've inserted another texture and was able to successfully blend the texture with another texture (through multiplication of values), so I know that the float4 struct contains values of a sort capable of having arithmetic performed on it.

In the Vertex function, attempting to extract the values yields nothing on a grid: enter image description here

The concept seemed simple enough on paper...

  • \$\begingroup\$ SampleLevel requires UV coordinates => [0,1]. I don't know how big your grid is, but make sure position stays within that range, so you're sure you're sampling at the right location. Also, just to be sure: I assume the input image is a grey-scale image? \$\endgroup\$
    – Krienie
    Dec 3, 2014 at 23:56
  • \$\begingroup\$ To extend @Krienie's response, is there a reason you're not just using Texture as the coordinate you sample at? Presumably you're authoring the height map in the same coordinate space as the color map. Also, are you sure you've properly bound the height map texture view? Reading from an unbound texture slot results in all zeros. \$\endgroup\$
    – MooseBoys
    Dec 4, 2014 at 0:26
  • \$\begingroup\$ This question was answered here. \$\endgroup\$ Dec 4, 2014 at 19:43
  • \$\begingroup\$ @KrienieThe texture was mapped from 0 to 1 across the span of the grid. I did this so that the grid's resolution is independent of the texture resolution. (Which is created by a function that takes resolution as a parameter.) \$\endgroup\$ Dec 4, 2014 at 19:48
  • \$\begingroup\$ @MooseBoys You're right, the texture was only bound to the Pixel Shader. Because of this, no amount of scaling, change would create usable values. \$\endgroup\$ Dec 4, 2014 at 19:50

1 Answer 1


As described here, the texture wasn't bound to the Vertex shader.

Without this (@Mooseboys) The texture data was not presented to the Vertex Shader, causing NULL or zero values. Binding the texture resolved the problem.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .