Jump to content
  • Advertisement
Sign in to follow this  
x6itru

OpenGL Per triangle normals generating..

This topic is 1932 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement

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.

Share this post


Link to post
Share on other sites

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

Edited by x6itru

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!