Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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...

share|improve this question
    
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? –  Krienie Dec 3 '14 at 23:56
    
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. –  MooseBoys Dec 4 '14 at 0:26
    
This question was answered here. –  InfinityMachine Dec 4 '14 at 19:43
    
@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.) –  InfinityMachine Dec 4 '14 at 19:48
    
@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. –  InfinityMachine Dec 4 '14 at 19:50

1 Answer 1

up vote 0 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.