Quad warp, 4-point corner pin perspective correction using homography matrix

I’ve spent the last two days trying to implement this: http://forum.openframeworks.cc/index.php/topic,3121.msg23803.html#msg23803
inside of Unity. I’ve got it so I’m 99% sure I’m calculating the homography matrix correctly for my quad transform. My issue is that my homography matrix does not seem to be affecting the object properly- it skews my object improperly.

edit: made it work. winning code as follows. just need to figure out how to pass my transformedMatrix into a shader, while still doing the LoadPixelMatrix equivalent in a shader…

edit: to do the same thing as GL.MultMatrix in GLSL , if i have an ortho camera and my quad is setup to be positioned at the 4 corners of my screen, i can pass my homography matrix (WarpMatrix) in to my vertex program, and do
gl_Position = gl_ModelViewProjectionMatrix * WarpMatrix * gl_Vertex;
that was easy!

GL.PushMatrix();
mat.SetPass(0);
GL.Color(new Color(1,1,1,1));
GL.LoadPixelMatrix();
GL.MultMatrix(transformedMatrix);
GL.Begin (GL.QUADS);
GL.TexCoord (new Vector3(0, 0, 0)); GL.Vertex3 (src[0].x, src[0].y, 0);
GL.TexCoord (new Vector3(0, 1, 0)); GL.Vertex3 (src[1].x, src[1].y, 0);
GL.TexCoord (new Vector3(1, 1, 0)); GL.Vertex3 (src[2].x, src[2].y, 0);
GL.TexCoord (new Vector3(1, 0, 0));GL.Vertex3 (src[3].x, src[3].y, 0);

GL.End ();
GL.PopMatrix();

Hello there,

I was attempting something pretty much similar to what you achieved here, and I appreciate the information you’ve shared here.

However, I am new to shader programming and scoured the forums and the internet on ways to pass a matrix to the vertex shader. I am performing the homography calculation in a separate C# script that returns a float[16] matrix. While most resources speak of having something called a uniform mat4 within the vertex shader, I haven’t quite managed to succeed at passing the matrix through. I would be thankful if you could provide a little more information on how it is done…

Thanks,
Chirag

Would you mind sharing the code to compute the homography matrix? :slight_smile:
I’d have a use for it :stuck_out_tongue: