To a pixel shader of a 2D game, I'm passing a 1-row heightmap that holds the height in UV coordinates of evenly distributed points throughout the texture I'm drawing, but as for n points there will obviously be n-1 lines connecting consecutive ones, I can't make these lines as wide as they should be.
For example, filling the pixels below the lines of a heightmap that holds 3 values ({0f, 1f, .5f}) should result in something like:

but instead, it looks like this:

It is visible that the correct result lies on the first 2/3 of the second one, and the last 1/3 comes from clamping the heightmap.
Here is a simpler version of the pixel shader code.
float4 PixelShaderFunction(float4 texCoords:TEXCOORD0):COLOR0
{
float verticesCount = 3;
float verticesFrequency = 1/verticesCount;
float lastHeight = tex2D(heightMapSampler, float2(texCoords.x, 0));
float nextHeight = tex2D(heightMapSampler, float2(texCoords.x + verticesFrequency, 0));
float delta = (texCoords.x % verticesFrequency)/verticesFrequency;
float height = lerp(lastHeight, nextHeight, delta);
if(texCoords.y > height)
return float4(1, 0, 0, 1);
return float4(0, 0, 0, 1);
}
I tried multiplying the texture coordinates by (verticesCount-1)/verticesCount but that didn't seem to do the job. Thank you!
texCoords.xby(verticesCount-1)/verticesCountat the top should really do the trick, I'd think. What goes wrong for you in that case? Can you post a screenshot of the result? \$\endgroup\$