Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a problem with rendering rectangular textures on non-rectangular surfaces. While googling, I found a thread with person having a pretty similar problem:

But in my case, I cannot be sure about surface's exact properties. It's not regular trapezoid, it can be slightly bent. Which means, that I cannot just calculate correct texture matrix, or at least I don't know how.

I've tried to render triangle fan-like shape, but it just changed the characteristics of final distortion.

share|improve this question
up vote 1 down vote accepted

Depends on what you are trying to achieve, you could define your figure in 3D space to make the distortion as suggested in the link.

If it's not 3D you are looking for then an applicable hack is to use a polygon "net", split the figure into a suitable number of small squares and you can do the transformation as you see fit. For some simple transformations it may be sufficient to stripe the figure using triangles that span the full figure in one direction but are thin in the other.

I suppose you could also use a custom pixel shader to achieve the same result.

share|improve this answer
My figure is already in 3D space, I can't really change it's corner coordinates. Tesselation idea is my last resort, it's not absolutely correct from mathematics point of view, but maybe it will be good-enough approximation. – ionoy Jul 11 '11 at 18:51

You're going to have to recreate your shape as a 3D mesh and run it through a software renderer to get any decent output that isn't a single-purpose hack like the texture matrix solution. If you attempt this in 2D you don't have enough information, like you've noticed.

Let me introduce you to a great article on perspective texture mapping in software: tutorial on 3D software rendering

share|improve this answer
As I already commented, my shape is already in 3D space, I cannot change it's corner coordinates. But thank you for the link. – ionoy Jul 11 '11 at 18:52
Though probably software texture mapping would solve my issue, I don't know if I have that much time for implementation. Seems like I will stick with tesselation idea. – ionoy Jul 12 '11 at 7:26

There is no easy solution to your problem. In common 3D graphics surfaces are composed out of triangles for a reasons (easy to use, always planar, etc..). Even when you order to draw quads GPU renders them as pairs of triangles.

Your problem comes from the fact, that it is impossible to properly split quad into triangles when they are not planar and/or their sides are not equal. It is clearly visible on your linked forum post pictures.

The only solution I could think of is tessellation. It can be done on different stages though:

  • On modeling stage, you could ask your artists to use finer grid and manually split bent quads/trapezoids into triangles
  • On uploading objects to GPU, you could split quads/trapezoids into number of smaller quads to reduce the distortion effect
  • Also you could use GPU tessellation functions

The choice depends on your actual project.

share|improve this answer
Thanks, seems like I will have to try tesselation, because other solutions are either to complex (software mapping) or not suitable in my case. – ionoy Jul 12 '11 at 7:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.