Offset Each Vertex according to texture in Material.


So i am looking for a fast way to update a flat mesh with a height map.
Generating and adjusting the vertices each frame takes too long, so I thought of letting the GPU do the work by offsetting them in the materials.
So i want to have e.g. a plane consisting of 2 triangles, thus consisting of 2x2 vertices.
Then i want to have a 2x2 pixel texture, and have the material read the values from that file, and adjust the vertices acordingly.
My question is, how would I know which vertex is currently being processed, and how would i get a sibngle pixel value from a texture?


Just read sample from texture and append that with 0,0 constant2. Then output that to Wordlposition offset. Depending how you want to map uv’s with texture it’s either automatic.(mesh contain proper uv’s) or you can calculate them from worldposition.

Thanks for your reply, but I don’t understand what you are saying.
Could you maybe give me a simpler answer?


It’s this simple.


Thanks that does the job!
But I am still interested in knowing, how i could get a single pixel froma texture at specified location?

The vertex shader looks up the texture sample value for a vertex based on the UV value of that vertex. If the vertex UV coordinate is at 0,0 it will look up the top-left corner of the texture. 1,1 is the bottom right. That way you can define how the vertices are displaced.