Archived

This topic is now archived and is closed to further replies.

Bad lookin shading

This topic is 5374 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

hi ppl i got a new problem with my app i have a 3d model and im tryin to light it nicely but i dont know how to calculate normals for each vertex i only calculate them for an entire face so it looks quite bad. if u got any ideeas pls reply /*ilici*/

Share this post


Link to post
Share on other sites
Here is the trick:

void Normalize(float *coords_src,float *coords_dest)
{
float m = (float)sqrt(coords_src[0] * coords_src[0] +
coords_src[1] * coords_src[1] +
coords_src[2] * coords_src[2]);

//Avoid dividing by 0
if(!m)
{
memset(coords_dest,0,sizeof(float) * 3);
return;
}

coords_dest[0] = coords_src[0] / m;
coords_dest[1] = coords_src[1] / m;
coords_dest[2] = coords_src[2] / m;
}

and now coords_dest will hold the normals for the vertex pointed by coords_src.

Hope this helps!

The PAIN is coming...this summer!!!In cinemas everywhere.

Share this post


Link to post
Share on other sites
quote:
Original post by Mihail121
Here is the trick:

void Normalize(float *coords_src,float *coords_dest)
{
float m = (float)sqrt(coords_src[0] * coords_src[0] +
coords_src[1] * coords_src[1] +
coords_src[2] * coords_src[2]);

//Avoid dividing by 0
if(!m)
{
memset(coords_dest,0,sizeof(float) * 3);
return;
}

coords_dest[0] = coords_src[0] / m;
coords_dest[1] = coords_src[1] / m;
coords_dest[2] = coords_src[2] / m;
}

and now coords_dest will hold the normals for the vertex pointed by coords_src.

Hope this helps!

The PAIN is coming...this summer!!!In cinemas everywhere.



Normalizing a vector, is not calculating the normal of a vertex !

Share this post


Link to post
Share on other sites
The best way todo it is to go through every vertex for every face in the model and check if its a neighbour by these conditions.

- The triangle contains a vertex that has the same location
- The angle between the normals of the triangle that the vertex belongs and the triangle that you are calculating is more than 90
(*or what ever angle you want)

This will make sharp edges (eg side of a cube) remain sharp and curved objects remain curved...

You then add the Normal of the Vertex''s triangle that you are comparing to the Vertex''s normal...

once you have gone through the whole model you normalize the vector

Share this post


Link to post
Share on other sites