Difference between revisions of "Polygons"
(more accurate name) |
(wip warning) |
||
Line 2: | Line 2: | ||
<!-- ## page was renamed from Subtractive Color Model --> | <!-- ## page was renamed from Subtractive Color Model --> | ||
<!-- ## page ported from http://www.ericchadwick.com/portfolio/glossary/examples/polygons.html. I'm wondering how accurate a lot of this is still? --> | <!-- ## page ported from http://www.ericchadwick.com/portfolio/glossary/examples/polygons.html. I'm wondering how accurate a lot of this is still? --> | ||
+ | |||
+ | |||
+ | <pre><nowiki>#!wiki red/solid | ||
+ | Page is currently under construction. Some of this information is out of date. | ||
+ | </nowiki></pre> | ||
+ | |||
+ | |||
= Polygons = | = Polygons = | ||
Revision as of 13:37, 10 August 2010
#!wiki red/solid Page is currently under construction. Some of this information is out of date.
Polygons
Polygon Storage Methods
File:Polygons$tri quad hexagon.gif
A triangle, a quad, and an n-gon.
Almost all real-time 3D engines support triangles. Some of these support quads and/or n-gons, but all polygonal engines convert them down to triangles at render time. The rare non-polygonal engines use other methods to create objects, like voxels.
With a triangle-only engine, you can still use polygons with more than three sides, but the engine always sees them as tris. For each triangle, it stores three vertices to "remember" the shape.
However, if you are able to use quads, the engine is then able to store them as only four vertices apiece, instead of the six that would be required to store the two triangles that make up the square shape. Engines that support quads usually support plain old triangles as well, for those difficult shapes where quads won't work. Quads save on the size of the geometry file, which saves memory, and it saves on the amount of calculations the engine has to do to transform the quads before rendering, which can ultimately speed up your frame rate. Every little bit helps.
The same holds true for n-gons, except they can save even more vertices. The hexagon, for example, is stored as only six vertices, instead of the twelve verts needed for plain triangles to describe the same shape. Remember, your engine must support quads or n-gons for this to work, and there are some restrictions-- see below.
The term "n-gon" does not always mean a polygon stored in this special vertex-saving way. There really isn't a specific term for this. You just have to spell it out anytime you refer to these special polygons. Which really isn't all that often, as most engines do not support them.
There are many ways to reduce vertex counts, like using strips and fans.
Non-Coplanar Quads
File:Polygons$ridge valley.gif
These two quads illustrate a problem that some engines have when a quad's vertices are not coplanar (on the same plane). Each quad has their vertices in the same shape. I put the quads inside grayed-out bounding boxes to make the perspective easier to see.
Some engines do not allow non-coplanar quads to exist-- instead they are automatically converted to triangles. But other engines allow them, like VRML. If so, the problem can occur. Both quads have their vertices in the same layout, but the engine has to convert the quads to triangles before rendering. The problem is that it does not know how you want the quad divided, so it arbitrarily decides where to put that interior edge. The quad could either be a ridge (left) or a valley (right).
This leads to some ugly artifacts, like a character's shoulder looking cut-into instead of muscled. Another problem happens if you are animating the quad's vertices, like with morphing-- the engine converts the quad into triangles, and on each frame it arbitrarily decides where to put that interior edge, so it ends up constantly flashing between ridge and valley. Fubar.
If your engine supports quads, make sure your quads' vertices are coplanar.
Concave Quads
These are two quads that illustrate another problem, similar to the Non-Coplanar Quad. Each quad has their vertices in the same shape. The red lines are the interior edges between the two triangles that make up each quad. The darker triangle in the quad on the right is overlapping the quad's other triangle, which is larger.
The vertices of these two quads are actually coplanar-- the problem is that they form a concave shape, but the engine still has to make the quad into two triangles at render time. It doesn't know that you want it to look like the one on the left, so it may create the one on the right.
What's so bad about that? Since the two triangles overlap in the same plane, the engine doesn't know which to draw in front of the other, so it flashes from one triangle to the other from frame to frame. Not very professional looking. If you need this shape, it's better to go with plain triangles.