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 GPU-based geometry clipmapping and have problems to apply a simple heightmap to my terrain. For the heightmap I use a simple texture with the surface format "single". I've taken the texture from Catalinz's XNA blog.

What I'm trying to do is just getting the single float value from the texture at the vertex world coordinate and apply the value to the Y-Value of the Vertex. I'm applying the heightmap through the shader, because there is no fixed grid in-code it could be applied on. What I've tried so far was using the tex2Dlod function, but there seems to be no output or an output of 0. The Direct X vertex shader's code looks like this:

float4 worldPos = mul(float4(pos.x,0.0f,pos.y, 1.0f), worldMatrix);
float elevation = tex2Dlod(HeightmapSampler, float4(worldPos.x, worldPos.z,0,0));
worldPos.y = elevation * 128;

Where HeightmapSampler is a point-mirror sampler of the heightmap texture. Here is the output, I actually get no elevation:

Screenshot

And here's the heightmap I'm using:

Heightmap

share|improve this question
    
You need to provide less code, and more details. What have you tried so far? What isn't working exactly? If you want to get an answer, try to ask a good question, check the FAQ for infos. –  Laurent Couvidou Sep 1 '12 at 21:43
    
I've updated my question to be more precise. –  CShark Sep 2 '12 at 11:47
    
is this a vertex or fragment shader (whatever they are called in directx)? Can you post a screen-shot of what you are getting, and what you are expecting to get? –  Will Sep 2 '12 at 11:56
    
I expect at least some elevation characteristics. The camera is at height 40 and the maximum elevation is by 128, so I shall see something... The center of the grid is in the center of the window. –  CShark Sep 2 '12 at 13:10
    
Thank you for implementing the pictures... I wasn't able to do it because of my reputation level <10 –  CShark Sep 2 '12 at 17:39

1 Answer 1

up vote 2 down vote accepted

What's the resolution of your terrain mesh? You're sampling the texture directly with the worldPos x & z vals: if you have a vertex every 1 unit, you'd get the same texture value each time as it's only the fractional part that's used. See if dividing the vals has any difference, e.g.:

float elevation = tex2Dlod(HeightmapSampler, float4(worldPos.x*0.001, worldPos.z*0.001,0,0));
share|improve this answer
    
I'd never thought of Texture dimensions in texels... I'll try it out. –  CShark Sep 3 '12 at 11:54

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.