Fast Perspective Correction of textured Trapezoids .. and Array Textures on a Mesh
Posted: Tue Nov 30, 2021 12:17 pm
Hi there, while developing my Pseudo3D racing game with polygonal 2D segments, I discovered someting. For Trapezoids with at least 2 parallel lines, you can get perspective correction on the GPU for free. Without fancy calculations or real 3D. No more affine texture mapping.
You can simply use the widths of the mesh as the W value for the vertex and pixelshader. In the Vertex shader you simply multiply the UV coords with W and in the Pixel shader you divide the UVs by W.
I've written a quick and dirty demo, with perspective correction and the use of an array texture on a mesh
I know it's nothing fancy, but hey, maybe someone finds it useful.
You can simply use the widths of the mesh as the W value for the vertex and pixelshader. In the Vertex shader you simply multiply the UV coords with W and in the Pixel shader you divide the UVs by W.
I've written a quick and dirty demo, with perspective correction and the use of an array texture on a mesh
I know it's nothing fancy, but hey, maybe someone finds it useful.