1
\$\begingroup\$

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

\$\endgroup\$
5
  • \$\begingroup\$ 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. \$\endgroup\$ Sep 1, 2012 at 21:43
  • \$\begingroup\$ I've updated my question to be more precise. \$\endgroup\$
    – CShark
    Sep 2, 2012 at 11:47
  • \$\begingroup\$ 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? \$\endgroup\$
    – Will
    Sep 2, 2012 at 11:56
  • \$\begingroup\$ 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. \$\endgroup\$
    – CShark
    Sep 2, 2012 at 13:10
  • \$\begingroup\$ Thank you for implementing the pictures... I wasn't able to do it because of my reputation level <10 \$\endgroup\$
    – CShark
    Sep 2, 2012 at 17:39

1 Answer 1

2
\$\begingroup\$

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));
\$\endgroup\$
1
  • \$\begingroup\$ I'd never thought of Texture dimensions in texels... I'll try it out. \$\endgroup\$
    – CShark
    Sep 3, 2012 at 11:54

You must log in to answer this question.

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