TL;DR I need to switch from a vertex array passed to the pixel shader with a real vertex shader approach.
In my prototype, the terrain is procedurally generated and I have the following result:
The terrain vertices are passed directly to the pixel shader through an array:
//Number of vertices in terrain array
static const int verticesCount = 20;
//The vertices array, in pixel coordinates
float2 terrain[verticesCount];
//A fixed distance between neighbor vertices
float fixedDistance;
float4 PixelShaderFunction(float2 pixelCoords : VPOS,
float2 textureCoords :TEXCOORD0) : COLOR0
{
float4 color = tex2D(s0, textureCoords);
int i = pixelCoords.x / fixedDistance;
float delta = (pixelCoords.x - terrain[i].x)/(terrain[i+1].x - terrain[i].x);
if(smoothInterpolate(terrain[i].y, terrain[i+1].y, delta) >= pixelCoords.y)
{
color.rgba = 0;
}
return color;
}
As you can see I just interpolate between the vertices and mask the texture to the terrain.
Now I need a different approach because I'm using a view matrix for the camera and it does not affect these vertices that do not go through the vertex shader, how can I replace the terrain array with a vertex shader to get a similar result?
All suggestions are welcome!