MHeasell / rwe

Robot War Engine - Real-time strategy game engine compatible with Total Annihilation
https://www.robotwarengine.com/
GNU General Public License v3.0
115 stars 16 forks source link

Fix 3DO texture distortion #7

Open MHeasell opened 6 years ago

MHeasell commented 6 years ago

We triangulate 3do meshes before display. This causes texture distortion on quads that are trapezium shaped.

Some options:

  1. render GL_QUADS (deprecated) and hope they interpolate as expected
  2. subdivide the mesh
  3. consider if we can do some maths to compute the texture coordinate correctly
MHeasell commented 6 years ago

Maybe wait for #4 to give us more flexibility.

MHeasell commented 6 years ago

4 has made enough progress that it no longer blocks this. We can do this in shaders with appropriate inputs from the outside.

Some useful reading:

http://web.cs.ucdavis.edu/~amenta/s12/perspectiveCorrect.pdf http://www.reedbeta.com/blog/quadrilateral-interpolation-part-1/ http://www.reedbeta.com/blog/quadrilateral-interpolation-part-2/ https://stackoverflow.com/questions/14971282/applying-color-to-single-vertices-in-a-quad-in-opengl

In particular, the third and fourth links describe implementing bilinear interpolation across a quad (not projective interpolation), I think something like this would be most appropriate here.

MHeasell commented 6 years ago

I should note that implementation of the above is a bit more involved than I had hoped so this will likely be de-prioritised until the engine has more features.

MHeasell commented 3 years ago

The following article improves upon Nathan Reed's solution for bilinear interpolation by also considering perspective correction:

http://www.unchainedgeometry.com/blog-1.html