[World] Zillion triangle breakthrough

Daniel Phillips phillips at phunq.net
Sat May 19 19:22:27 PDT 2012


Goodbye to a nasty scaling bug

Today I sorted out an issue that prevented going beyond 220,000 or so faces 
per mesh part. As the mesh size increases past that, performance first falls of 
a cliff by orders of magnitude, then large parts of the mesh start flashing on 
and off, then the whole machine becomes unresponsive. Maybe some kind of 
massive memory leak in kernel. Fortunately, when I kill the world engine the 
machine comes back to life after a while. But this is a Bad Thing[tm] by any 
standard. Surely I am not the only one rendering element arrays of this size 
on the open source OpenGL stack? 

OK, maybe I am, or at least it is a small club. Anyway, this morning I finally 
succeeded in developing a workaround after fretting about this for the last 
few months. Conceptually the fix is simple: when I compile a half edge mesh 
into OpenGL drawarrays form, I now split the mesh into parts smaller than 4 
MB. This is a little messy because the splitting happens deep inside the 
triangle mesh compiler, which already qualifies as deeply arcane. But the patch 
came out small and the results are better than excellent. Now we can render 
multiple compiled meshes of well over a million triangles each and it's 
exceptionally efficient. I'm really excited about this.

Unicode character glyphs

Another goody landed this weekend: Unicode glyph glyph support. This opens up 
a wealth of beautiful character outlines to exercise the new triangulation 
code, and just be generally lovely. I rendered some Kanji characters for 
Hirofumi's entertainment:

    http://phunq.net/files/shiny85.png ('full year' kanji)     
    http://phunq.net/files/shiny86.png ('happy' kanji)

The second image is over 1.5 million triangles and renders at a solid 60 FPS 
on this low end, fanless GPU. I haven't yet determined how high this scales, 
but most probably a lot higher. So breakthrough is the word for it.

Now I am happy with baseline render performance and can put that aside for a 
while. To recap, high performance rendering is achieved with a mesh compiler 
that converts from halfedge mesh form to efficient triangle strips. First we 
model the mesh, including possibly subdividing it, then compile it for 3D 
viewing. Compiling is fast, about 1 microsecond per triangle, so a million 
triangle mesh takes about a second to compile, after which it renders smooth 
as silk.

Faster, better, bigger

Most of the mesh compile time is spent calculating vertex normals for smooth 
shading. There are some big optimizations possible here, without sacrificing 
accuracy, so down the road we may see a factor of four or more improvement at 
the cost of more down and dirty work on the mesh compiler. And way down the 
road, we might do this job on the GPU using hundreds of processors in 
parallel. With that, mesh compiling should be essentially instantaneous for 
meshes of the complexity we see here.

For now, tricks are needed to make  interactive editing operations seem fast, 
because even one second per frame is too slow for an artist to work 
comfortably . I'm starting to think now about what those tricks might be. 
Because editing these subdivision meshes interactively is not that far away, 
and that is the last major piece we need for a game designer to create a full 
suite of 3D mesh assets for a respectable simulation game. In an upcoming post 
I will talk more about the "loop modeling" approach I have in mind for organic 
meshes.

Regards,

Daniel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://phunq.net/pipermail/world/attachments/20120519/8bfa4296/attachment.html>


More information about the World mailing list