I have got a 2D texture, such as this one, which I am currently just dropping directly onto the terrain.
I am then rendering foliage on top of that texture.
I would like to (using the fragment shader), get the colour of the texture beneath the grass, and set the grass to be the colour of the texture beneath it.
To do this, I need to get the position of each grass vertex on the terrain relative to the texture.
I then need to get the colour of the texture corresponding the the location of the object, and blend it with the current grass colour (let's say I have red grass for demonstration purposes).
I am currently not sure how to start. I know I need to get the grasses' X and Z position in the world (which I currently do not have) through the shaders, but I then need to work out the corresponding texture pixel, which I currently do not know how to do.
Any advice to help solving this would be appreciated.
The main idea is that you pass position coordinates as texture coordinates.
You have a rectangle where the height map lays, let the position coordinates be relative to that. In this case, if your height map is NxM, and texture coordinates are 1x1, you may just normalise the positions to 0..1, and then you have got a texture coordinate.
With this texture coordinate now you can get the colour passing the texture as a uniform.
I hope it was clear and satisfies your question, but also I'm willing to see clarifications.