About

© 2010 Eduardo Poyart. About

June 30, 2010

Progressive LODs explained

In this post I present a brief explanation of the progressive LOD (Level Of Detail) algorithm I'm implementing in Crystal Space.

Overview

First, a high-level overview. We are trying to solve the problem of displaying an approximation of a mesh with less triangles, when this mesh is far away from the camera. This speeds up the rendering and allows more objects to be on the scene at the same time. The mesh approximations are precomputed for efficiency. The visualization method has an impact on the method used to precompute the meshes, so let's analyze it first.

There are several techniques to visualize progressive meshes. Using a discrete method, one can keep in memory a full-resolution mesh and several lower-resolution meshes. The correct mesh is selected depending on the distance. Each mesh is complete and independent, so there is duplication of information such as vertex positions and colors. In contrast, another approach is to use progressive meshes. In this case, there is only one mesh representation, and all the information to collapse triangles is embedded in this mesh. This allows for an almost continuous change in the level of detail: if the mesh goes a little bit further away from the camera, one single edge can be collapsed and the mesh rearranged so as to have less triangles. Since not too many triangles are rearranged, there are less visual "pops."

Besides the discrete vs. progressive aspect, multi-resolution meshes can also be view-dependent or view-independent. If your mesh is a large terrain that you are rendering and flying over, you want more detail close to the camera and less detail far away in the distance. The resulting mesh depends on the point of view. If your mesh is a relatively small object like a barrel or a table, it's not too important to have a view-dependent system. Making the system view-independent simplifies it and allows for speed gains.

In Crystal Space, I am implementing a view-independent progressive LOD method called Sliding Windows.

Sliding Windows


The Sliding Windows method is analyzed in [1] and compared with other methods. In summary, here's how it works. Let's look at the vertex buffer and index buffer of a regular mesh:



Vi are vertices. Each element contains the x, y, z position of the vertex and possibly other attributes. Ti are triangles. Each element contains 3 integers that point to the vertex table. For example, if T0 = (0, 1, 2), it represents the triangle formed by vertices V0, V1 and V2.

Our Sliding Window is a window over the index buffer, as displayed below. This window tells the engine to render only the triangles that it encompasses.



The preprocessing stage reorders the triangles in the index buffer so that the "less important" triangles are first. These are the triangles that will have the smallest impact on the overall shape of the mesh if they are removed or modified. I will talk about the preprocessing stage and how it figures out which triangles are "less important" in a future post. The preprocessing stage also adds new triangles to the end of the index buffer. If the original mesh has n triangles, the resulting index buffer has a size greater than n.

The sliding window starts by pointing to the first n triangles of the index buffer (from 0 to n-1) which represent the original mesh. If this mesh is rendered, the visual result is identical to the original, full-resolution mesh.

Let's say the distance to the camera increases and we need to display a simpler mesh. We do this by collapsing an edge. An edge collapse means removing all the triangles that share this edge, and adding a few new triangles in their place. So, at each LOD step, a few triangles have to be removed and a few have to be added. Let's say we have to remove 4 triangles and add 2. The trick is that the preprocessing stage puts the 4 removed triangles at the beginning of the index buffer and the 2 added triangles just outside the sliding window. So all we have to do is shift the beginning and the end of the window and we will have a consistent mesh at a lower resolution.


As mentioned before, the triangles are reordered such that the first ones are those that have less impact on the overall mesh appearance if they are modified. In effect, our edge collapse, which is usually a costly operation, comes for free just by sliding the window.

That's the basic idea of progressive meshes with sliding windows. There is an important detail to it: once a triangle is added, it can't be removed anymore, because the ordering will no longer be appropriate for a consistent removal (except if we're extremely lucky). So far, the described algorithm can only remove and replace triangles up to a certain point. Extending the algorithm further involves duplicating the index buffer at a certain point. The reader can refer to [1] for a more complete description.


[1] Forsyth, Tom, "Comparison of VIPM Methods," in Mark DeLoura, ed., Game Programming Gems 2, Charles River Media, pp. 363-376, 2001.

June 19, 2010

Psychedelic barrel art

Using Crystal Space.

Guess how I did it.

June 6, 2010

Undefined symbols: "vtable for ..."

When writing a Crystal Space application based on the tutorials, I had a class that inherits from Crystal Space's csApplicationFramework and csBaseEventHandler. Upon editing the code and compiling, I ended up getting the following error: (Lod is my class name)

Undefined symbols:
  "vtable for Lod", referenced from:
      Lod::~Lod()  in lod.o
      Lod::Lod()   in lod.o

This is caused by declaring a member prototype (for example) "bool OnKeyboard (iEvent&);" and not defining it on the cpp file. I'm not sure why the error points to the constructor and destructor and not to the member function, but if you run into that, check all your prototypes vs. defined functions.