- Home /
Projetion Mapping on Unity
Hi! I'm trying to do a perspective transformation from a render texture to a real world plane but so far unsuccessfully. This is what I have now using Image Warp from asset store:
This tool distorts the image (mesh), but perspective transformation is not equal to distortion as the following image shows. 
The question is, how can I make a perspective transformation for projection mapping? Opencv have this kind of tools, Unity have projection Matrix, but documentation says nothing about that..
Answer by OliverUmbrella · Nov 25, 2019 at 02:24 PM
There was a site with an algorithm. But it is available on webarchive: https://web.archive.org/web/20160402083111/http://www.bitlush.com/posts/arbitrary-quadrilaterals-in-opengl-es-2-0
Calculate the q value for each vertex (when you move the screen coordinates of one vertex, you have to recaluclate the q values) as described on the page
Create a list of Vector4 texture coordinates
strqfor each vertexstrq.x = s * q, where s is the ordinary s texture coordinatestrq.y = t * q, where t is the ordinary t texture coordinatestrq.zis not usedstrq.w = qPass the list of the Vector4 texture coords via
Mesh#SetUVs(int channel, List uvs)In the fragment shader calc:
u = texcoord.x / texcoord.w; v = texcoord.y / texcoord.wreturn
tex2D(_MainTex, float2(u, v))
Your answer