- Home /
Perspective Correction with Render Texture
Hello
I am working on a project that involves some basic perspective distortion correction. I am having some trouble getting it to work. Specifically, I'm having trouble mapping the Render Texture to my "correction plane" so that the perspective distortion is eliminated. Some help and feedback would be greatly appreciated. Let me explain my setup:
My scene is simple, I have a vertical plane with some simple objects (shelves) on the surface. The plane and shelves are going to be projected (mapped) onto a wall. The trick is, the projector will be ceiling mounted and pointed about 15 degrees downward. This means I have to compensate for the projector angle in Unity. This is done by adding a virtual camera where the projector would be in virtual space. THEN, I have to correct the perspective distortion of that virtual camera so the end projection fills the entire wall with proper proportions.
My workflow for solving the problem is to recreate the space in Unity. First, the modeled wall and shelves are created in proportions that will match the real wall and shelves. Next, a virtual camera is placed at the same location as the real projector and with the same angle. That camera image is then sent to a render texture, which is then applied to a second wall (basically a duplicate with the exact size and placement as the original wall but on a different render layer). A second camera (Main Camera) is placed directly in front of the textured wall, perpendicular, and set to orthographic mode. The idea is to correct the perspective distortion by stretching the texture to exactly fit the textured plane.
Here is the perspective correction signal flow: Camera 1 (perspective) --> RenderTexture --> plane with renderTexture applied --> main Camera (orthographic) --> out
An image illustrating the setup:
What I have so far:
I cant seem to get the texture mapped correctly to the plane that has the Render Texture applied. If you look at the below image you can see the texture does not match the plane exactly, it still has the perspective distortion. I think the way to solve this problem is to map the uv coordinates so that the texture is mapped correctly to the plane, but I'm not sure how to do this. I did not see much support for uv placement through scripting either. I also tried modeling a single-face plane with the correct dimensions and importing that instead of using plane in Unity.
Main camera output, you can see the texture placement issue here:
I am really stuck on this problem and need to figure out a solution to this. Any help on the subject would be much appreciated!
I thought most modern projectors had functionality for fixing this kind of thing with clever lensing? Am I misunderstanding the problem here?
As far as I know, perspective distortion should probably be done with clever manipulation of the camera's projection matrix. Could you explain why? I think I can see what, but it's sometimes difficult to know what the proper solution is without fully understanding the background of a problem.
No its more complicated than that. Imagine you have a grid painted on the wall that you will be projecting onto, 10cm x 10cm grid. And you want to project the exact same grid pattern onto the wall, using a wall with a grid you created in Unity. If your camera in Unity is simply perpendicular to the modeled wall, and then you project that at an angle, your projected grid will not match with the real grid. Simple $$anonymous$$eystone correction within the projector will not fix that problem.
I am going to be projecting onto a wall with objects on it. Simple projection mapping. If the perspective distortion is not corrected, is simply will not match up. A good intro to the topic can be found here: http://vvvv.org/documentation/how-to-project-on-3d-geometry#projection-on-a-flat-surface
I'll post this project also because it is doing similar things (but more complicated). What is most relevant I think is that he distorted the camera output in a similar way that I describe, without using custom shaders. I think he did it only with uv texture mapping with his surface. http://paulbourke.net/papers/cgat09b/ http://paulbourke.net/miscellaneous/domefisheye/unity3d/
Your answer
![](https://koobas.hobune.stream/wayback/20220613071248im_/https://answers.unity.com/themes/thub/images/avi.jpg)