Hello I recently send my RayTracer to render a .obj model (that has a corresponding .mtl and although a good part of the model seems to render correctly, also a significant part of it does not:
What I want is suggestions of how to find out the cause(s) of the artifacts seem above.
Some comments: As far as I know, these object models expect Phong shading model, but I am not using it, instead I am calculation only the diffuse color, copying the diffuse color components specified in the accompanying .mtl file
Perhaps my main obstacle here is the massive amount of triangles involved. If I had a couple hundred triangles, it would be very easy to keep deleting part of them until I figure out with ones are not rendered properly. But I have so many of them (more than 200000 on this case) that makes it completely impractical. Plus it takes so much to render them, that visual inspection is problematic (I did not implemented an acceleration structure yet)
Another observation is that there is a couple of duplicated materials in the .mtl file. Look at here:
#Max2Mtl Version 4.0 Mar 10th, 2001
#
newmtl darksilver
Ka 0.0 0.0 0.0
Kd 0.8 0.8 0.8
Ks 0.2 0.2 0.2
d 1.0
Ns 10.0
illum 2
#
newmtl red
Ka 0.0 0.0 0.0
Kd 0.4 0.1 0.1
Ks 0.5 0.5 0.5
d 1.0
Ns 10.0
illum 2
#
newmtl gold
Ka 0.0 0.0 0.0
Kd 0.6 0.5 0.1
Ks 0.5 0.5 0.5
d 1.0
Ns 10.0
illum 2
#
newmtl silver
Ka 0.0 0.0 0.0
Kd 0.8 0.8 0.8
Ks 0.2 0.2 0.2
d 1.0
Ns 10.0
illum 2
#
newmtl lambert1
Ka 0.4 0.4 0.4
Kd 0.4 0.4 0.4
Ks 1.0 1.0 1.0
d 1.0
Ns 4.8
illum 2
#
newmtl yellow
Ka 1.0 1.0 1.0
Kd 1.0 1.0 1.0
Ks 0.2 0.2 0.2
d 1.0
Ns 10.0
illum 2
#
newmtl black
Ka 0.0 0.0 0.0
Kd 0.8 0.8 0.8
Ks 0.2 0.2 0.2
d 1.0
Ns 10.0
illum 2
#
# Multi/Sub Material__91 (2) to come
#
newmtl red
Ka 0.0 0.0 0.0
Kd 0.4 0.1 0.1
Ks 0.5 0.5 0.5
d 1.0
Ns 10.0
illum 2
#
newmtl 14_-_Default
Ka 0.0 0.2 0.9
Kd 0.0 0.2 0.9
Ks 0.9 0.9 0.9
d 1.0
Ns 0.0
illum 2
#
# Multi/Sub Material__91 done
#
# Multi/Sub Material__58 (2) to come
#
newmtl red
Ka 0.0 0.0 0.0
Kd 0.4 0.1 0.1
Ks 0.5 0.5 0.5
d 1.0
Ns 10.0
illum 2
#
newmtl 14_-_Default
Ka 0.0 0.2 0.9
Kd 0.0 0.2 0.9
Ks 0.9 0.9 0.9
d 1.0
Ns 0.0
illum 2
#
# Multi/Sub Material__58 done
#
# EOF
As can be seen, the red and 14_-_Default appears three time in the file (no ideia as to why, but if anyone knows a possible explanation, I would like to hear it). Might be related to the problem(s) ?
Another possibility might be related to my triangulation algorithm. On two other files I noticed visual artifacts as can be seen in the bellow images:
Actually I am not even sure that the car image has artifacts. The reason I believe there might an artifact is the absence of the tires and a strange thing in the wheels. I realize the color is the same in nearly all the car, but this might be the result of nearly all the materials, including most of the transparent ones, having the same diffuse components.
The second image however, is not using a .mtl file and can be clearly seen a couple of unwanted triangles bellow the airplane, some small black spots in the fuselage (one being a visible black triangle) and a couple of "blue" holes on its back part.
So I decided to post my triangulation algorithm, that picks the multiple vertices faces and generates triangles from it:
int color;
int number=0;
cout << "mat_name: " << mat_name << endl;
for (int i=0; i<mtl_material_container.size(); i++)
if (mat_name==mtl_material_container[i].material_name)
color=i;
Vec3f tmp [faces.size()];
for (int i=0; i<faces.size(); i++)
tmp [i] = vertices [faces[i] -1];
Triangle triangle (tmp[0],tmp[1],tmp[2],color);
triangle_container.push_back (triangle);
for (int i=0; i<faces.size()-3; i++) {
//Triangle triangle (tmp[i],tmp[i+2],tmp[i+3],0);
Triangle triangle (tmp[i],tmp[i+2],tmp[i+3],color);
triangle_container.push_back (triangle);
}
Anyway, these were the things I could think until now. Eager to accept any debugging suggestions. Thanks for your time.