Per triangle normals generating..

Started by
5 comments, last by Adaline 11 years ago

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.

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.

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

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. ;/

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.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

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?

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 ?

This topic is closed to new replies.

Advertisement