2

Model

I've got a model that I've loaded from a JSON file (stored as each tile /w lots of bools for height, slope, smooth, etc.). I've then computed face normals for all of it's faces and copied them to each of their verticies. What I now want to do (have been trying for days) is to smooth the vertex normals, in the simplest way possible. What I'm trying to do is set each vertex normal to a normalized sum of it's surrounding face normals. Now, my problem is this:

The two circled vertices should end up with perfectly mirrored normals. However, the one on the left has 2 light faces and 4 dark faces. The one on the right has 1 light face and 6 dark faces. As such, they both end up with completely different normals.

What I can't work out is how to do this properly. What faces should I be summing up? Or perhaps there is a completely different method I should be using? All of my attempts so far have come up with junk and / or consisted of hundreds of (almost certainly pointless) special cases.

Thanks for any advice, James

Edit: Actually, I just had a thought about what to try next. Would only adding a percentage of each triangle based on it's angle work (if that makes sense). I mean, for the left, clockwise: x1/8, x1/8, x1/4, x1/8, x1/8, x1/4 ??? And then not normalize it?

That solution worked wonderfully. Final result:smoothed

Jagoly
  • 939
  • 1
  • 8
  • 32
  • In my experience, it can be enormously helpful to add some debug drawing routines in order to visualize various aspects of your geometry. Try rendering your normals at each face and / or vertex and see if it helps point out the issue. – Lee Adams Jul 24 '14 at 05:21
  • 2
    You beat me to an answer with your edit. I was going to propose using the angle between the adjacent edges as the weight of each normal. 15 minutes isn't much time to let people read the question and come up with an answer. ;) – Reto Koradi Jul 24 '14 at 06:06
  • possible duplicate of [How to achieve smooth tangent space normals?](http://stackoverflow.com/questions/21766605/how-to-achieve-smooth-tangent-space-normals) – Spektre Jul 24 '14 at 06:24
  • Sorry, I thought of it while staring at the picture. It seems that doing scribbles like that is helpful :) – Jagoly Jul 24 '14 at 07:04
  • @Spektre: That's not a duplicate. The other question/answer is exactly what the OP tried, and that did not produce good results. The goal here is to find something that works better for this case. – Reto Koradi Jul 24 '14 at 07:16
  • @RetoKoradi yep you are right (close retracted) – Spektre Jul 24 '14 at 11:59

1 Answers1

0

Based on the image it looks like you might want to take the average of all unique normals of all adjacent faces. This avoids double counting faces with the same normal.

D Drmmr
  • 1,223
  • 8
  • 15
  • I did try to do that, but then I ended up with a humongous amount of special cases. Also, wouldn't using the angles give a smoother surface? – Jagoly Jul 24 '14 at 08:38
  • Two normal being "equal" sounds very fragile. They probably wouldn't be exactly equal due to floating point inaccuracy. You would need to compare them to be close enough within a certain tolerance. And choosing that tolerance would be kind of arbitrary. I think it would work for this special case, but I'm not convinced that it would be very robust in general. – Reto Koradi Jul 24 '14 at 15:11
  • @Jagoly What kind of "special cases"? Can you give some examples? – D Drmmr Jul 25 '14 at 06:54