Jump to content

  • Log In with Google      Sign In   
  • Create Account

Per triangle normals generating..


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 x6itru   Members   -  Reputation: 149

Like
0Likes
Like

Posted 22 March 2013 - 05:20 PM

Hello there, i have small problem with normals for terrain generated from heightmap. I'm trying to generate normals for it, and its almost working, but i'm getting very strange result ( there are strange stripes everywhere ;f) : 

98867991.png

 

 

Code for generation normals :

glm::vec3 x6ngine::cHeightMap::computeNormal(glm::vec3 v0, glm::vec3 v1, glm::vec3 v2)
{
    return glm::normalize(glm::normalize(glm::cross(v2-v0,v1-v0)));
}

i dont know where's problem ;/ somewhere in opengl code?, or i'm just generating it wrong? Thanks for help. Regards x6itru.



Sponsor:

#2 wintertime   Members   -  Reputation: 1686

Like
3Likes
Like

Posted 23 March 2013 - 07:02 AM

Normalizing 2 times is useless. You need to calculate vertex normals by assigning them an average of all surface normals of adjacent quads to not have those sudden changes.



#3 x6itru   Members   -  Reputation: 149

Like
0Likes
Like

Posted 23 March 2013 - 08:02 AM

I've normalized it twice by accident tongue.png thanks for help, it should look smoother with per vertex normals.


Edited by x6itru, 29 March 2013 - 06:13 PM.


#4 x6itru   Members   -  Reputation: 149

Like
0Likes
Like

Posted 29 March 2013 - 06:13 PM

hello again ;/

I have really strange problem with vertex normals.

result :

61885384.png

code for compute vertex normal :

vertexnormals.png

Result is very strange ;/ There are strange small "holes" - ofc they're from normals, terrain grid is smooth, so normals should be smooth too. ;/


Edited by x6itru, 29 March 2013 - 06:14 PM.


#5 dpadam450   Members   -  Reputation: 921

Like
0Likes
Like

Posted 30 March 2013 - 12:18 AM

Looks about right. Terrain with smooth normals and not per-pixel normals will still not look perfectly smoothed.

you are setting sum to 0 somewhere else I assume? Math looks fine.



#6 x6itru   Members   -  Reputation: 149

Like
0Likes
Like

Posted 30 March 2013 - 03:22 AM

Yes of course i'm setting sum to 0, can you tell me something more about per-pixel normals(almost nothing in google about that) or any other way to make it smooth?



#7 Tournicoti   Prime Members   -  Reputation: 683

Like
0Likes
Like

Posted 05 April 2013 - 09:12 AM

Hello

 

f0 to f5 must be normalized before averaging them to get v0Normal.

 

Even if the points are aligned on x and z axes, the triangles have generally differents areas, so the norms of f0 to f5 are generally not the same.

( according to the cross product properties, the norm of f0 is 2x the area of the triangle (v0,v1,v2) )

 

f0=normalize(crossProduct(v1-v0,v2-v0))
.
.
.

v0Normal=(f0+f1+f2+f3+f4+f5)/6

should work better

 

I noticed a confusion between your formulas and your scheme, for example according to your scheme f0 should be the normal of the triangle (v0,v1,v6), not (v0,v1,v2). Hoping this is just wrong typo ?


Edited by Tournicoti, 05 April 2013 - 10:16 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS