About

© 2010 Eduardo Poyart. About

August 14, 2010

Video

Here's a video of my final results.

http://www.youtube.com/watch?v=dyMPjVtLIKM



August 13, 2010

Wrapping it up

Here are the latest improvements to the LOD system:


  • Handling meshes with coincident vertices

The algorithm is able to collapse edges whose vertices are both single vertices (only one vertex in one position), as well as one single and one double (two coincident vertices), as long as the single vertex is the origin of the collapse. As it is now, the tool is fully able to preserve texture and normal boundaries. An in-memory data structure stores pointers to coincident vertices, which will allow a future implementation of full collapse of vertices of order 2 -- still preserving textures and normals. 

  • Fast local error metric
This new error metric only analyzes triangles in a local area around the last collapse. It is approximately linear on the number of triangles, instead of quadratic. I used a sampling approach in which a number of points are selected in triangles of the original mesh, and I measure the distance between these points and triangles of the simplified mesh. The error metric is an average of these distances.

  • Artist-defined distances for multiple meshes
Modellers need to be able to define minimum and maximum LOD distances per-mesh in their modeling tool. This is important because different meshes have different LOD requirements. A modeller may want to make a small mesh enter its LODs quicker, while a larger mesh should be at a greater distance before entering its LODs. They can also take into account the polygon count, surface complexity and relative importance of the mesh, and set appropriate distances.

When multiple meshes are processed at once from a zip file, the system reads in each file to check if it has preset LOD distance parameters. If they are set in the original file, those distances override the command-line specified distances. A "-force" flag was added to the command line to make the command line distances override the file distances.

    Eye Candy


    I haven't posted pictures or videos in a while, so here is some eye candy.

    900 teapots: Before = 17 fps

    900 teapots: After = 66 fps

    The first picture shows a scene where 900 teapots are rendered at full resolution. The frame rate is 17fps. The second picture shows the same 900 teapots rendered with progressive LODs. The frame rate is 66 fps. The distances used were mindist=10 and maxdist=30.

    Now I'm going to have some tea to celebrate.

    July 22, 2010

    Non-welded meshes

    Dealing with non-welded meshes (meshes that have coincident vertices) is proving to be very tricky. Consider the case below.



    In mesh A, the original mesh, vertices V1 and V2 are very close together, maybe even coincident, but they are not the same vertex. The same is true for pairs V3-V4 and V5-V6.

    Let's assume the algorithm decides to collapse V3 to V5, for example. To get correct results, the result of that collapse should be mesh B. V4 has to collapse to V6 as well. If V4 doesn't collapse to V6, there will be a hole on the mesh.

    With an usual mesh representation with vertices and triangles, aided by edges (pairs of vertices) and a list of incident triangles at each vertex, there's no information that tells us to collapse V4 to V6 when we collapse V3 to V5.

    What extra information do we need?

    In addition to our per-vertex list of incident triangles, we probably need a per-vertex list of other coincident vertices. When doing a collapse, we not only follow the list of incident triangles and work with them. We also need to follow the list of incident triangles from the coincident vertices.

    Is that enough? Not yet, probably. We know our source and destination vertices, V3 and V5. When we jump to V4 and process it, we need to know that we need to collapse V4 to V6, not V4 to V5.

    What else do we need? What if V5 is coincident with V6 and a third vertex, V7? How do we know we need V6 and not V7?

    I leave the answer as an exercise to the reader. I don't know it myself, at this point.

    Ah, the joys of computational geometry!

    July 21, 2010

    Crystal Space fixes for Mac OS X 10.6

    I've ran into several compatibility problems between Crystal Space and Mac OS X 10.6. Thankfully I've figured out workarounds for the most critical ones. Investigating these problems is a slight diversion from my main focus on GSOC, but I believe it's perfectly valid since it helps the Crystal Space community as a whole. I'll summarize the problems and fixes on this post.

    "-bundle" error when building

    To build Crystal Space on OS X 10.6, you have to remove the string "-bundle" from several places on the following files:

    configure
    cs-config-1.9
    scripts/cs-config/makevar.macosx
    mk/jam/macosx.jam

    Universal binary and relaytool errors

    Your "./configure" line must include "--disable-universal-binary --disable-relaytool".

    Cg error

    Remove "-Wl,--no-as-needed" from the section in the configure file where it tests for Cg (starting around line 53940).

    CEGUI error

    The configure script can't find the CEGUI framework. I haven't looked much into that one, but it seems like configure's test can't find the CEGUI.h header file. This happens even if you have the CEGUI framework correctly installed.

    All of these problems will probably be fixed soon by the amazing CS folks (Eric Sunshine being the amazing Mac OS X maintainer), but this should at least help some people for now.

    July 3, 2010

    First Video

    Here's a video with the results of my work so far.



    http://www.youtube.com/watch?v=TMpYdAUkUuo

    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.

    May 29, 2010

    Mac OS X equivalent of LD_LIBRARY_PATH:

    DYLD_LIBRARY_PATH.
    Use "man dyld" for more info.

    Hello world

    How are you doing, world?