3D 101 Fundamentals of 3D Renderers

[ 1 ] Comment
Share

Now that you’re familiar with the fundamentals of 3D (spaces, coordinates, projections, and rotations) it’s time to begin to learn how to write a quick and clean 3D renderer. But first, let’s talk about how 3D objects are defined.

1. Object Definitions

In 3D we define objects using vertices just like in any other space, for example a line is defined as an object having two vertices. Certain other objects require a different definition such as the sphere which is defined by a center vertex and a radius. There are also fundamental objects such as the triangle which can be used to form much more complex objects such as planes, spheres, hexagons and many many more.

Most of time objects are defined using the latter method, that is, using triangles to define more complex objects. Triangles are used because it’s a fundamental figure, the first that is a closed shape with minimum number of points (3).

Now imagine a complex polygon as shown on the following figure (left figure) that polygon can be represented using triangles only as it is shown in the right figure. The action of converting one polygon to a sequence of smaller objects which collectively can accurately represent the source polygon is known as tessellation.

Before we continue, there’s need to think about what a 3D renderer actually is. To make things simple it’s enough to say that “A 3D renderer performs rendering which in this context is drawing 3D objects in a 2D display with as much accuracy as possible.”

There are two basic types of renderers, real-time and non-real-time. Non-real-time renderers use mathematical equations to generate thousands of vertices and draw objects with great accuracy. This type of renderer is very very slow but has an amazing output image quality due to the incredible number of vertices generated. Non-real-time renderers are used in commercial applications such as movies and animated series.

Real-time renderers on the other hard are incredibly fast and efficient because they need to render an entire scene dynamically on demand in real time. These renderers lack of high detail because of the technique used, which uses less detailed approximations of the real object to make rendering time faster, that is the primary goal of real-time renderers, provide output as fast as possible with averagely good quality. Real-time renderers are used in games, software, interactive applications and more.

As shown on the figure above, the left side shows a generic triangle rendered as a one piece object which is usually how a real-time renderer would draw a triangle. The right side shows a tessellated triangle with 16 sub-pieces, this has a much higher detail when lights and reflections are rendered, this is how a non-real-time renderer would draw the triangle, although probably with more than just 16 sub-pieces, since non-real-time renderers use micro polygons which can be as small as 2 or 3 pixels each.

Nowadays real-time renderers are much more efficient than they were 18 years ago when Doom(Game, 1993, ID Software) blew our minds for the first time, this is due to the powerful help of 3D accelerated graphics cards which can render millions of polygons per second, allowing us to build highly detailed frames without worrying about speed.

2. Renderer Operations

As we mentioned before, a renderer has to take care of drawing objects appropriately in a 2D display, to do this there are several basic stages that we need to go through in order to achieve a correct output image. The following sections will describe these basic rendering stages. Note that a fully featured renderer may or may not implement more stages in this process, depending on the level of quality and methods used. In future lessons these processing stages will be written in code one by one.

2.1. Consumption of Object Data

In this stage the data of objects in the scene is sent to the renderer for further processing, these data is added to the object queue. By object data we refer to all the required information about an object that is required in order to draw it correctly, such as vertices, texture coordinates, shading method, light parameters, view model matrix, etc.

2.2. Vertex Lighting

In this stage a light modeling algorithm such as the phong reflection model is used along with the light sources defined in the scene to calculate the color and intensity of lights on the all the vertices of all objects in the object queue. Lighting is an optional stage at first and should be added only until the basic renderer is stable and produces correct results.

2.3. Camera Transformation

In this stage a camera view matrix is used to transform the entire world to make it look like it’s being viewed from point of view of the camera. This is commonly known as converting from world-coordinate-space to view-coordinate-space.

2.4. Fundamentals Generation

In this stage the renderer has to convert or tessellate objects (if necessary) to generate fundamental polygons (triangles). After this stage has finished the object queue will be composed only of fundamental polygons.

2.5. Polygon Culling

In this stage the renderer has to discard from the object queue all polygons that are either facing backwards (process known as backface culling) or those which are behind a non-translucent polygon (known as hidden surface removal), the result is a much smaller set of polygons which are always visible.

2.6. Clipping

In this stage all polygons in the object queue have to be checked to verify that they are in fact inside the view volume, all polygons outside it are removed. Sometimes a polygon lies partially outside the view volume, in which case the polygon is clipped against the view volume and this usually results in the generation of one or more smaller polygons that effectively lie inside the view volume. Clipping is essential to render frames correctly.

2.7. Projection Transformation

In this stage all polygons are projected to 2D space using a projection matrix. This is usually known as converting from view-coordinate-space to viewport-coordinate-space.

2.8. Viewport Clipping

In this stage the resulting points from the last stage are clipped against the viewport to make sure no polygon lies outside the valid rectangle viewport range.

2.9. Polygon Scan Conversion

In this stage all polygons are scan-converted to generate scanlines which can easily be drawn later by even the most basic graphics library.

2.10. Polygon Filling

In this final stage all polygons are drawn one by one simply by filling the scanlines with appropriate data using an specified shading method, such as a plain color (flat shading), a gradient (gouraud shading), an image (texturing) or even a simple wireframe.

All these stages are executed by hardware when 3D accelerated cards are available, to make use of these cards a hardware-enabled library such as OpenGL or DirectX should be used when developing 3D applications instead of a custom made library.

Despite of all the scary stages, there’s no reason to panic! A highly simplistic renderer can be developed with only four stages (2.1, 2.7, 2.9 and 2.10). Later on in future lessons we will develop a somewhat simple renderer with 6 to 7 stages.

Good programmer and digital technology inventor.
Passionate about 3D, Assembler, Processors, Mobile Tech, and everything that is one way or another programmable.

Jonathan Palencia

Related Posts:

One Response to 3D 101 Fundamentals of 3D Renderers

  1. Dave Doolin says:

    Jonathan, good start here. I did a medium size project a couple of years ago where meshing was important. There is a lot to it. Looking forward to more.
    Dave Doolin´s last [type] ..Irritation in a minor chord

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

CommentLuv badge