Advertisement

smoothing

Started by January 24, 2002 07:23 AM
3 comments, last by Martas 23 years, 1 month ago
I try do smooth objects by meaning normal but it''s VERY slow, can somebody help me?
You may not compute the normals on-the-fly at each frame : you may compute the normals at the beginning of your program, and store the results in an array.
Then at each draw you''ll only call the elements in the list, you won''t compute the meaning stuff again.
Advertisement
quote:
Original post by vincoof
You may not compute the normals on-the-fly at each frame : you may compute the normals at the beginning of your program, and store the results in an array.
Then at each draw you''ll only call the elements in the list, you won''t compute the meaning stuff again.


Tanks for answer,
I comute it on start, but if I use profesional editor 3dexplorer
it load it i second, my compute takes 30 for 2 teapots.



Well, you *just* have to optimize your code

First of all, avoid computing the same value twice.
Because you "mean" the normals, I think you talk about meaning the normals of neighbour polygons for each vertex.
One way could be :

for each vertex
{
create an empty list of normals;
get the list of polygons neighbour to this vertex;
for each of those polygons
{
compute the normal of this polygon, using a cross product;
append this new normal to the list of normals;
}
compute a "mean" normal from normals in the list;
store this "mean" normal as the vertex normal;
}

I would recommend NOT to compute the polygon normal with a cross product for each vertex, like the method above.
You''d better pre-compute the normals for each polygon :

add a field "normal" for all polygons
for each polygon
{
compute the normal of this polygon, using a cross product;
store this normal in the field "normal" of this polygon;
}

Then, when you go through your vertexes, do this instead :
for each vertex
{
create an empty list of normals;
get the list of polygons neighbour to this vertex;
for each of those polygons
{
get the normal of this polygon, using his field "normal";
append this new normal to the list of normals;
}
compute a "mean" normal from normals in the list;
store this "mean" normal as the vertex normal;
}


Another thing I would recommend is using floats instead of doubles. You''ll lose some precision, but it will be faster to compute, it will use less memory, and you will se almost no difference in the quality of the rendering.


And a last thing I''d say : optimize your function calls, especially the cross product.
if you compute the cross product in a function, set this function "inline" (in C++) :
  // compute a cross product between v1 and v2inline cross_product(float *result, const float *v1, const float *v2){ result[0]=v1[1]*v2[2]-v1[2]*v2[1]; result[1]=v1[2]*v2[0]-v1[0]*v2[2]; result[2]=v1[0]*v2[1]-v1[1]*v2[0];}  
Thanks a lot i''ll make it

This topic is closed to new replies.

Advertisement