Problems with handling sharp edges


Problems with handling sharp edges
#1
So, continuing with my LDraw to xml converter grind, looks like I have managed to solve pretty much everything but one thing - handling sharp edges

I have tried multiple ways, but nothing seems to work. Generally, it seems I should not interpolating normals between faces that share sharp edge, but then arises problem of faces that share only 1 vertex. How this case should be approached?
Reply
RE: Problems with handling sharp edges
#2
(2023-04-10, 18:40)Max Murtazin Wrote: So, continuing with my LDraw to xml converter grind, looks like I have managed to solve pretty much everything but one thing - handling sharp edges

I have tried multiple ways, but nothing seems to work. Generally, it seems I should not interpolating normals between faces that share sharp edge, but then arises problem of faces that share only 1 vertex. How this case should be approached?

What techniques have you tried? The simple case is to smooth all normals by averaging the normal at each vertex by summing up the normals of adjacent faces and normalizing the result. Normals are interpolated between vertices when rendering, so you may need to index the vertices differently depending on the normals you calculate.

One approach I've seen is using conditional lines to average normals. I've found that averaging on conditional lines or at least edges that aren't marked sharp produces some artifacts when working with triangulated meshes. Applying the averaging before triangulating should give slightly better results. This seems to be the approach used by some older applications.

Another approach is to just average the normals using an angle threshold. For each vertex in each face, add the normal for any adjacent face that differs by at most some threshold. This is common in hard surface modeling and tends to work well for most parts. There's some example code online like the one here: https://gist.github.com/Ni55aN/90c017faf...8ab6566cfa.

In my Blender importer, I split the sharp edges as well as using an angle threshold. This seems to give better results. I'm still working on recreating this code to work outside of Blender.
Reply
RE: Problems with handling sharp edges
#3
(2023-04-14, 14:39)Jonathan N Wrote: What techniques have you tried? The simple case is to smooth all normals by averaging the normal at each vertex by summing up the normals of adjacent faces and normalizing the result. Normals are interpolated between vertices when rendering, so you may need to index the vertices differently depending on the normals you calculate.

One approach I've seen is using conditional lines to average normals. I've found that averaging on conditional lines or at least edges that aren't marked sharp produces some artifacts when working with triangulated meshes. Applying the averaging before triangulating should give slightly better results. This seems to be the approach used by some older applications.

Another approach is to just average the normals using an angle threshold. For each vertex in each face, add the normal for any adjacent face that differs by at most some threshold. This is common in hard surface modeling and tends to work well for most parts. There's some example code online like the one here: https://gist.github.com/Ni55aN/90c017faf...8ab6566cfa.

In my Blender importer, I split the sharp edges as well as using an angle threshold. This seems to give better results. I'm still working on recreating this code to work outside of Blender.

At this moment, I've already managed to do that
The way I'm doing it is taking edge lines (type 2) and using them to determine should I merge vertices or not (edge line - not merge, no edgeline - merge)

Gives fine results in most cases, tho it's not perfect. I was thinking to switch instead to using conditional lines instead, but it has it's downside of not being an option of models processed through Bricklink Part Designer - something I do want to factor in. Probably, best will be to use mix of both and also angle threshold - if edge is sharp enough, check for condline and smooth if there's none, and if it's nor sharp enough instead check for an edgeline

By the way, angle threshold is very easy to do - you just need to calculate angle between face normals of two faces you are thinking to smooth

Here's a render to show how current approach performs. Aside from chest, all artifacts are either due to rounding or Eyesight render doing some odd stuff:
[Image: Taahu.png]
Reply
RE: Problems with handling sharp edges
#4
Can you visualize the normals without eyesight? It looks like there are multiple light bounces and some sort of bevel being applied that make it hard to interpret.
Reply
RE: Problems with handling sharp edges
#5
(2023-04-14, 21:03)Jonathan N Wrote: Can you visualize the normals without eyesight? It looks like there are multiple light bounces and some sort of bevel being applied that make it hard to interpret.

Will this do?
[Image: tahu1.png]
Reply
RE: Problems with handling sharp edges
#6
(2023-04-14, 21:34)Max Murtazin Wrote: Will this do?
[Image: tahu1.png]

I would say that looks pretty good in terms of normals.
Reply
RE: Problems with handling sharp edges
#7
(2023-04-16, 16:50)Jonathan N Wrote: I would say that looks pretty good in terms of normals.

Chest has it's flaws. Also the notched axle 2 currently gets completely butchered
Reply
RE: Problems with handling sharp edges
#8
(2023-04-17, 9:07)Max Murtazin Wrote: Chest has it's flaws. Also the notched axle 2 currently gets completely butchered

The left foot also seems to have issues in the original picture (although that could just be the reflection map).
Reply
RE: Problems with handling sharp edges
#9
(2023-04-17, 20:25)Travis Cobbs Wrote: The left foot also seems to have issues in the original picture (although that could just be the reflection map).

There could be some due to rounding issues
Reply
RE: Problems with handling sharp edges
#10
(2023-04-17, 23:40)Max Murtazin Wrote: There could be some due to rounding issues

What do you mean by "rounding issues"? Are you using a suitable distance threshold when merging vertices?
Reply
RE: Problems with handling sharp edges
#11
(2023-04-18, 0:35)Jonathan N Wrote: What do you mean by "rounding issues"? Are you using a suitable distance threshold when merging vertices?

Yes. Threshold wasn't big enough at first and I've only noticed that after rendering
Reply
« Next Oldest | Next Newest »



Forum Jump:


Users browsing this thread: 1 Guest(s)