Hacker News new | ask | show | jobs
by Narann 2226 days ago
Quads are used as geometric data primitives because they allow consistent subdivision. But quads are not good as a rendering primitive compared to triangles. Triangles are rasterizer-friendly because they are composed of two edges and its quick to know if you are inside or outside two edges.
2 comments

> Triangles are rasterizer-friendly because they are composed of two edges

Huh? Can you elaborate on how a triangle has 2 edges opposed to 3?

I assume they mean for scanline rendering where you trace two edges at a time while drawing the scanline between them.

Basically, the way it works is that you arrange the 3 vertices of a triangle from top to bottom, then take the middle vertex and split the triangle along the scanline from that vertex to the opposite edge. Each "half" of the triangle can be rendered by simply drawing a scanline between the two edge positions, stepping down to the next line, advancing the two edge positions, and repeating. (See "Bresenham's line algorithm" and "Digital differential analyzer" on wikipedia for efficient ways to compute the edge positions.) Note that if the middle vertex shares a scanline with another vertex, the other "half" of the triangle in this algorithm has a height of zero lines, and can just be ignored.

It's a simple, straightforward way to rasterize a triangle that can be implemented efficiently.

For any span of pixels, you render from one edge to another because your y-coordinate is fixed. You only have to consider 2 edges at a time during rasterization. You can subdivide a quad easily, though, so it's not that much of an advantage.
You can't compute a normals from a quad, which makes shading algorithms not work.