Page MenuHome

[WIP] Freestyle contour mesh tessellation
Open, NormalPublic


I've implementeted the first tessellation part of the paper "Computing Smooth Surface Contours With Accurate Topology ( ) as a modifier in blender.

Here is a video of the current progress. I've set freestyle to render contours and borders with line width starting at 1 and ending at 5:

Note that this might be a best case scenario.

The code is hosted on github at:
(Look in "source/blender/modifiers/intern/MOD_mybesh.c")
You need opensubdiv 2.6.x to run it.

What is left to do is:

  • Port the code to the latest opensubdiv version
  • Lots of clean up in the code
  • Optimize (the code is currently single threaded)
  • Implement the second part of the paper.

Currently the code doesn't produce nice results for more complex meshes (like on suzanne). Because the opensubdiv version I use has a lot of bugs, (you can't subdivide a torus and there are errors in the computed limit surface on suzanne) I can't yet tell if it's a problem on my side or the opensubdiv side.

This is why I felt like this would be a good time to request help with porting the modifier to blender trunk.
Because this is my first blender project I have a strong feeling that I have done a lot of things overly complicated.

The help I specifically request is how and what functions I should use to call opensubdiv from blender proper. The old functions that I used previously has be removed from 3.x.x (IIRC). I'm a bit lost on how to do this with the new API to be honest...

I realize that this is quite a huge code dump and I will gladly answer any questions that might come up.
I would really like to have this included upstream (when it's ready) because I think that the improvments the paper does to the freestyle line chaining is needed if you want to use it in animation.



Event Timeline

Sebastian Parborg (zeddb) set Type to Patch.
Sebastian Parborg (zeddb) created this task.
Sebastian Parborg (zeddb) raised the priority of this task from to Needs Triage by Developer.

Campbell requested some examples with characters so I took some from BBB:

Please note that the result could be better than this.

Firstly because this is a two part paper (I've only implemented the first part).
Secondly there are currently some issues with the tesselation that I don't know if it's a bug with my code or if it's just the way it is. The paper mentions that there will be tesselation errors (or problems might be a better word) that can't be fixed.

The second point is why I posted this here. I feel like I need to get some outside input on some things to be able to either solve the problems or decide that it's not feasible to try to solve them.

Just a quick heads up. I've managed to get the code to run in blender master and with opensubdiv 3.0.x

I will just spend quite a bit of time on bugfixing now. The result will hopefully be a lot better than the one I posted when I'm done.

I have uploaded the ported code to:

However I noticed that I run into a segfault in glibc:

#0  0x00007ffff222d4bf in __ieee754_log_fma4 () from /lib64/
#1  0x000000000276c94a in sqrt3f (f=3.66065979) at /home/zed/programmering/new_blender/blender/source/blender/blenlib/intern/math_base_inline.c:72
#2  0x00000000027736ae in get_k_r (eval=0x7fffd340e128, face_index=2551, u=0.311174393, v=0.67027092, cam_loc=0x7fffd747c290)
    at /home/zed/programmering/new_blender/blender/source/blender/modifiers/intern/MOD_mybmesh.c:581
#3  0x000000000277fbce in k_r_sign_cross (u=0x7fffd6c7f930, v=0x7fffd6c7f940)

I updated to glibc 2.23 (from 2.22) and it sadly didn't fix the issue.
@Campbell Barton (campbellbarton) @Sergey Sharybin (sergey) is this a know issue with sqrt3f/glibc?

A quick update. I've worked with the GSoC student YimingWu so see if my work would be useful with his LANPR solution (and it seems to be!).

I've ported my code to blender 2.8 and hosted it here:

I'm glad to say that is seems to work nicely and improves the results of both the offline LANPR and real time LANPR renders.

YimingWu reported it here:
But I'll upload images of offline and realtime here also.

Offline improvement (monkey to the right is with tesselation):

Realtime (white lines is the tesselated mesh):

I just wanted to post an other update. Now I feel like the result of my modifier should have the same mesh output as the one in the original paper.
However, there are still some illogical linebreaks in the freestyle output. The mesh tesselation in those areas look fine, so I guess that to solve those we need to implement the second part of the paper where they modify freestyle.

I've also noticed that the thing that seriously slows down my code is the OSD mesh creation. On the squirrel (17 106 quads) OSD creation takes 4.346086 sec while the rest of my modifier code takes 3.414331. I'll try to multi thread a part of my code. If that goes well then I might push the time down to around 1 sec for the non OSD creation stuff.

Edit: Managed to multi thread the most expensive step (split ff bb edges) so now my modifer code has around 1sec execution time as I expected!