Question

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

Était-ce utile?

La solution

Forgot that Texture coordinates are in Texels, so multiplying it with the texels fixed it.

float elevation = tex2Dlod(HeightmapSampler, float4(worldPos.x*texel, worldPos.z*texel,0,0));
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top