smoothing
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.
Then at each draw you''ll only call the elements in the list, you won''t compute the meaning stuff again.
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++) :

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++) :
|
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement