Tutorial 1: Triangle Setup

Introduction

Modern graphics hardware is optomized for 1 type of primitive: triangles. Triangles can be seen as a linear approximation of any surface that you'd want to render. No matter what surface representation we choose to use in our Application, subdivision surfaces, bezier patches; we will eventually have to convert from that representation to a bunch of triangles approximating that surface. We call the representation that the hardware gets a Triangle Mesh.

Geometry and Connectivity

Presenting a Triangle Mesh to the hardware involves two things. Presenting the hardware with a list of vertices or geometry and presenting the hardware with a list of faces or connectivity. In modern programmable pipelines, data for the vertices are passed through Vertex Shaders that take the data that we present to the graphics hardware and allow specialized programs to adjust the data before the hardware begins to rasterize (convert our mathematical representation of triangles to pixels in the framebuffer) our triangles.

Sending the connectivity to the hardware has its own set of concerns. Sending the connectivity can either be explicit or implicit. In explicit connectity we send a vertex buffer and an index buffer to the graphics hardware. The index buffer contains all the connectivity, and the vertex buffer contains all the geometry. In implicit schemes we only send the vertex buffer, and the order that the vertices are presented in vertex buffer determines the connectivity.

The simplest way to send connectivity to the graphics hardware is the so-called triangle list. This is where we define a triangle as three indepedent vertices. The problem with triangle lists is that it takes three indices to define each new face. Other schemes such as triangle strips and triangle fans can define a new triangle using only one new index. In addition, graphics hardware has vertex caches, so if we respect spatial and temporial locality in our triangle meshes, we can get considerable boosts in performance. Triangle strips and triangle fans tend to be conducive to cache performance, triangle lists tend not to.

We will examine Vertex Shaders in more depth in a later tutorial. Right now, we will limit ourselves to the fixed-function pipeline.

Transformations

In the fixed function pipeline, we concern ourselves with three matrices. The first matrix is the projection matrix, this matrix takes triangles and projects them to the screen. We also have a model and a view matrix. The model matrix is used for local transforms to the triangle mesh, and the view matrix represents our camera in the scene.

Shading

When triangles are presented to the hardware, we have to tell the hardware how to interpolate attributes to each pixel. For modern hardware, Gouraud shading is almost always appropriate.

Links