I've worked using maya for animation and more film orientated projects however I am also focusing on my studies on video game development (eventually want to be either programmer or some sort of TD with programming and 3D skills). Anyways, I was talking with one of my professor and we couldn't figure out why all game engines (that I know of) convert to triangles. Anyone happen to know why game engines convert to triangles compared to leaving the models as four sided polygons? Also what are the pros and cons (if any) of doing this?
|
|
The bottom line is Triangle Rasterization, which is how computers render objects to the screen. Though others say it more elquently than I:
Emphasis mine. Source: http://www.devmaster.net/articles/software-rendering/part3.php |
|||||||||||
|
|
Triangles have many properties that make them easier, and therefore faster, to draw. Four points or more may not be on the same plane, but three points always are (ignoring degenerate cases). This has the interesting property that scalar values vary linearly over the surface of the triangle. Even when the triangle is projected on the screen, scalar values still vary linearly respect to x'/z and y'/z. This, in turn, means most if not all of what's needed to shade, texture map, and depth filter a triangle can be calculated using linear interpolation which can be done extremely fast in specialized hardware. tl;dr: triangles are the simplest primitive, so algorithms dealing with triangles can be heavily optimized. |
|||||||||||
|
|
Three points (a triangle) ALWAYS define a flat plane. In other words, given any three points, you can always create a flat plane that can cut through all three points. However the same is not always true of four points. You can have four points all on a plane, but you can also have four points that aren't on a plane. |
|||||||||||||
|
|
It's not "game engines" that do this - all the 3D software you use does this. It just doesn't tell you about it, and your professor seems fairly under-qualified if he doesn't know this. They exist in the computer's memory even if the software is hiding them from you. All 3D programs have an option that will make the triangles visible. They will also have an option that splits them into editable edges, so you can play with them. But they were always there to begin with and it's naive of your proffessor to be teaching this subject and still wondering "what triangles are for". A triangle is the only way to arrange verts and guarantee a flat surface. When you have a quad, you can arrange the verts in a way that it must bend. But it's already made of triangles and it's those triangles that allow the bend. |
|||
|
|
|
There's only one way to triangulate a triangle vs. 'n - 2' ways for an n sided polygon. So, triangles are ultimately the least ambiguous way to define a polyhedral shape. Also, as other posters have indicated, there are lots of ways to accelerate triangle (rather than quad or higher) rasterization (constant z is one of my favourites). Also, it's easier to optimize ray-triangle intersection tests than it is for ray-arbitrary polygon intersection tests. In fact, many operations on n-sided polygons benefit from having a triangulated representation to hand. That isn't to say that n-sided polygon representations are 'bad' - they are very useful but ultimately, you're going to want to work with triangles for many mesh operations. |
|||
|
|
|
As long as the triangle is defined by three non-colinear vertices (read: none of the angles are exactly Pi), then the vertices define a unique plane. A quad is, of course defined by four vertices. It's perfectly possible for those vertices to be non-coplanar. In that case, your quad would really be two triangles divided by a diagonal on the quad. That's two planes, two sets of surface normals, etc. Every available modeling tool, every algorithm for texturing, lighting, etc all assume that a model is made of plane segments, and every formula we have (cross products for normal calculation is the first one we have) use the absolute minimum input dataset - three vertices define a plane, and the plane is what we need to do all of the fancy stuff. You could certainly write an engine to work with quads, but you'd find yourself ignoring the forth vertex in just about every case, except for when you (frequently) would need to make sure it's coplanar with the other three that define the quad. And, the most logical solution to the case where it is not coplanar would be to split the quad into two triangles. So, why not just do that to start with? What on earth would be the point of working with quads? If you want a quad, put two triangles together. |
||||
|
|
|
If we assume that getting 4 points to be co-planar is not a problem (it is, as the others have pointed out, but bear with me) then you find that rendering an arbitrary trapezium (which is what a quadrilateral will usually look like when transformed into screen space) is not particularly different from rendering a triangle - in fact, it pretty much works out the same once you perform clipping as that can introduce extra vertices. (At least in a software model - hardware may well have a simpler brute force way of doing the clipping.) The remaining issue therefore is one of representational efficiency. - you can easily represent a quad with 2 triangles, and without any extra vertices if you use a triangle strip (3 verts for the 1st triangle, then an extra vert for the 2nd triangle). On the other hand, if you try and represent a triangle with a quad, you need to use 4 vertices and have a degenerate one that is identical to another. This is not ideal in terms of efficiency. |
||||
|
|
|
A triangle is the simplest primitive that can be described in isolation because it has three points, fewer than which do not describe a surface in 3D. Because a triangle can be considered in isolation, it is possible to make a piece of code or silicon that is capable of rendering only a single triangle, which via the power of repetition can render any surface at all. Therefore, the first computer system which succeeded at rendering "any surface at all" naturally did so by rendering many triangles independently. If one thinks of triangles and quads as "primitives" (i.e. as completely isolated bits of geometry with no context) the triangle is the more primitive, and so it will tend to "win." However, once entertainment-grade computers exceeded a certain level of sophistication in the 1980s, the simplicity of considering "primitives" in isolation became less important. If graphics are to be mass-produced, then economies of scale favor processing groups of related vertices, much as they favor assembling a hundred near-identical cars at once. This is why in the 1980s, movies adopted the "quad," which is a misnomer because it refers to a 2D grid of vertices in 3D space, and not an isolated quadrilateral. The same shift from triangles to "quads" has not happened yet in the realm of interactive entertainment, but it is likely to happen, fairly soon, and for the same reasons it happened in the movie business. |
||||
|
|