2

In 3d modeling, there is some "triangle count" which determines complexity. I am not sure but I think cubes have 12 triangles or somethong. But I see NONE. They have squares, no triangles! Can someone please help me understand what a triangle is? Where in the cube are these 12 "triangles" located?

  • 6
    A square can be made of two triangles. A cube can be made out of 12 triangles because it has 6 square faces, and you can decompose each into 2 triangles. Triangles are used in graphics because they are simple, have nice properties, and define a plane uniquely if not degenerate (all vertices lie on a line/in a single point). – lightxbulb Dec 28 '19 at 09:35
  • Seeing how hard it is to get this answered, it seems to me that its not so trivial to deduce the reasoning. Which means the qiestion is worth asking thus worth upvoting. – joojaa Jan 10 '20 at 06:26

2 Answers2

3

To expand on @Makogan and @lightxbulb's answers/comments:

There are several reasons for using triangles as the basic primitive.

  1. (Non-degenerate) triangles are guaranteed to be planar. This means that an individual single triangle cannot obscure itself (in terms of hidden surface removal) and thus cannot form an internal silhouette edge (when being rendered) nor, say, cast a shadow on itself.

    This is also means that when scan converting a triangle, for each pixel, each attribute (e.g. depth, texture coordinate, shading) can only take a 'single' value.
  2. They are guaranteed to be convex. Scan converting/filling convex polygons is far simpler than a general polygon filling algorithm

  3. An arbitrary polygonal mesh can always be easily decomposed into triangles
    [Update: As @joojaa pointed out, you could still use quads by either
    a) Noting that any triangle can be represented as 3 quads by the addition of four more vertices - one at the centre of the triangle and one on each edge). You need to be careful, though, not to introduce T-Junctions. or
    b) Using a degenerate quad to create a triangle - i.e. either collapse an edge by repeating a vertex or (but this may have other problems due to precision) making 3 of the vertices collinear Neither seems, to me at least, as particularly attractive].

If you are concerned about the 'cost' in vertices of supplying two triangles to represent your quad, remember that APIs (and HW) have triangle strips/fans/indexed representations which will, in most cases, eliminate the additional vertex overheads. There is thus little point in adding additional hardware to support 'fast' quad rendering as (a) it wouldn't get used much and (b) is extremely unlikely to be the bottleneck in rendering!

Having said all this, the original Series 1 PowerVR graphics chips (eg PCX1 and PCX2) used a lower-level primitive (the half plane) from which N-sided convex polygons (or in fact N-sided polyhedra - e.g an entire cube was, at most, 6 half-planes) could be constructed. IIRC the driver tried to detect if two consecutive triangles actually formed a planar quad and then replaced them with a more efficient representation. Further, for a quad to be "planar", not only did it need to be geometrically flat but the texture coordinates also had to be 'flat'.

Simon F
  • 4,241
  • 12
  • 30
1

A literal triangle, as in 3 vertices connected by 3 edges.

They are the basic building block for any other shape, any polygon can be represented with a set of triangles (called triangulation).

Makogan
  • 1,706
  • 12
  • 28
  • Why? Why break up a square into two triangles? –  Jan 08 '20 at 19:09
  • 1
    Because triangles are the 2D simplex. it;s the simplest possible shape in 2D. Having a universal shape that you use to do all your calculations allows for some very powerful assumptions that simplify your logic (and by extension GPU manufacturing) – Makogan Jan 08 '20 at 19:24
  • I understand that they can create everything, but why not use squares on square faces instead of two triangles? Why break it into triangles, and instead use the appropriate polygon? –  Jan 08 '20 at 19:38
  • I am explaining to you, because having a STANDARD shape simplifies computations. If you always have to deal with the same shape, you can simplify and accelerate the logic of projection, rasterization, coloring... which makes for really fast hardware / algorithms – Makogan Jan 08 '20 at 20:52
  • But then a "Triangle count" would be higher than a "polygon count" (by a lot). For examples, a cube could be 6 polygons, but 12 triangles. –  Jan 08 '20 at 21:14
  • It has nothing to do on the polygon count, 6 vertices are 6 vertices. Here, let's say you want to make an algorithm for rasterizing. If your algorithm is designed to always rasterize triangles, then you get your data, you know what to do. But what if you have to support squares as well? Now you need some kind of check, to determine if your data represents a triangle or a square. If you support 16 different shapes then you have to do 16 checks. If you support any aribtrary polygon now you have to deal with an infinite amount of problems that triangles don;t have. – Makogan Jan 08 '20 at 21:20
  • Is the polygon concave or convex? Does the polygon fit in memory? Is the polygon self intersecting? What is the topology? Is it a doughnut polygon? ... – Makogan Jan 08 '20 at 21:21
  • There are no 0 cost abstractions, a general polygon rasterization algorithm would be inherently slower than a triangle rasterization triangle, for no other reason than having to to deal with a broader problem space. – Makogan Jan 08 '20 at 21:23
  • What do you mean by does the pollygon fit in memory? –  Jan 08 '20 at 22:26
  • Imagine a polygon taking a quintillion vertices. That's a perfectly possible case scneario you need to take into account for handling any arbitrary polygon. – Makogan Jan 08 '20 at 22:52
  • Just like a polygon with a quintillion vertices is impossible to represent in the computer, but there is no point in triangles, as it would be impossible to represent them in triangles too. –  Jan 09 '20 at 01:27
  • You are wrong, a quintillion triangles doesn;t fit in ram at once, but it fits on disk, so you can render one triangle at a time until you get the final composition. – Makogan Jan 09 '20 at 01:45
  • If you render one at a time, it will still be stored in ram. I am talking about game graphics –  Jan 09 '20 at 05:06
  • One a t a time uses ram, but doesn;t use all of it at once. GPUS do more than render real time graphics, they are also used to render off line graphics.

    Regardless do you understand that picking a consistent data representation accelerates the speed of your program? This is generally true for any system.

    – Makogan Jan 09 '20 at 06:05
  • 1
    @Makogan the answer is essentially right. The problem with a any random polygon is that they have a ill defined shape if they are not flat. Since the object is manipulated by vertices there is no guarantee what the actual shape of a quadrangle is. So in practuce devices split quads to triangles on render. They strictly dont have to but do (there are exceptions). However, for the author its easier to show a compound polygon because he does not need to care if he does not want to – joojaa Jan 09 '20 at 12:36
  • I mean if you send info to a GPU you HAVE to split it into triangles, modern GPUS ca only handle triangles, lines and points. – Makogan Jan 09 '20 at 16:20
  • Well, you dont have to. You can implement the ngon rendering with shader code. So strictly speaking you dont have to, you just usually do. But if you for example you implement a raytacer then why not. – joojaa Jan 10 '20 at 06:23
  • @joojaa Ok, how are you calculating your ray / ngong intersection? if you use triangles then it;s just barycentric coordinates, but if you want to support arbitrary ngong ray intersection, I wish you good luck with that, it;s not going to be easy to implement. – Makogan Jan 13 '20 at 00:39
  • @Makogan i didn say its easy. Just that it has been done. Most notably pixars renderman used to work with microdiced quads. – joojaa Jan 13 '20 at 04:55
  • Wow that has a lot of comments –  Feb 09 '20 at 21:49
  • One issue with Quads is that they can be "bent" if all 4 vertices don't lie on the same plane. So there are a large range of invalid configurations for that primitive. Triangles/Facets have the property that they cannot be further divided and that they are always flat. Also triangles are simpler to interpolate values across. – PaulHK Feb 10 '20 at 06:47
  • In terms of 3D modeling, polygons are often supported, sometimes with user interfaces that constrain them to be coplanar and have nicely defined texture mapping. Mathematically we often talk about vertexes, edges and faces (not triangles) of polyhedra. But in terms of GPU rendering performance, as @Makogan has alluded to, GPUs have dedicated rasterization setup engines which (generally) handle triangles but no other polygons. Thus the number of triangles needed has been a good performance/complexity metric. –  Feb 12 '20 at 01:33