How to apply a texture to a quad

Consider a mesh given by two triangles that form a trapezoidal quad in world space. The UV space covers the quad completely.

How do we apply a material to the mesh such that we get the result on the right?

The material has to make use of the UV coords and the vertex coordinates somehow.

Note: In my case the quad is generated procedurally at runtime.

(post deleted by author)

I tried to do the reverse of this but without success.

there are same of UV in them,but you want different textures