Drawing a screen space rectangle with Graphics.DrawMeshNow


I want to draw a screen space rect based on a unity rect. Currently I do this :

        Vector3[] vertices = new Vector3[4];
        vertices[0] = new Vector3(testPos.xMin, testPos.yMin, Camera.current.nearClipPlane);
        vertices[1] = new Vector3(testPos.xMin, testPos.yMax, Camera.current.nearClipPlane);
        vertices[2] = new Vector3(testPos.xMax, testPos.yMax, Camera.current.nearClipPlane);
        vertices[3] = new Vector3(testPos.xMax, testPos.yMin, Camera.current.nearClipPlane);
        for (int i = 0; i < 4; i++)
            vertices _= Camera.current.ViewportToWorldPoint(vertices*);*_
 _*mesh.vertices = vertices;*_
 _*Graphics.DrawMeshNow(mesh, Matrix4x4.identity);*_
_*<p>This works as expected. However, I would prefer not to set the vertices each time, but rather set the world matrix of the object differently each frame.*_
_*That way I could create the mesh once and use it each time.*_
_*I don't understand exactly how to work it out. Can someone lend a hand?</p>*_

If your goal is to simply render the mesh in the same scale in front of the camera, I don't think you need the matrix at all. You should be able to draw the mesh using only this:

`Graphics.DrawMeshNow(mesh, Camera.current.transform.position, Camera.current.transform.rotation);`

If your mesh is initially positioned on the camera's nearClipPlane the way that you want it then it should work as intended. I believe this works because the scale is the extra dimension that the matrix is capable of handling but the constant z-value of the camera's plane negates the need for it. Let me know if my math is rusty or if it doesn't work the way you had in mind.