0

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:

iron-main-512.jpg

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:

car-2700_X-1000_Y-3000_Z.jpg cesna2.jpg

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.

user2752471
  • 444
  • 1
  • 6
  • 14

1 Answers1

0

Here some hints what to do:

To be sure you should render your mesh normally using lines or triangles instead of ray tracing just to locate if the problem is in mesh loader or ray tracing itself. It will be useful later too. As when you got the ability to render geometry normaly too you can render test rays to check for correctness of your ray tracing (to check of placemnet and size of objects, to check for refraction and reflections etc). Look here how mine ray tracer and debug render screenshots looks like (for some inspiration):

The indices in obj are starting from 1 instead of 0 which many rookies forget about but it looks like you are handling it correctly. Just make sure you are not correcting this on two places in the code (like in pushing the vertexes into point table too).

I am doing the triangulation slightly differently:

for (i=2;i<pos.num;i++) obj.addface(pos[0],pos[i-1],pos[i]);

Its less code and more straightforward (its like GL_TRIANGLE_FAN). I am not convinced your triangulation method is correct for faces above 4 points but too lazy sketch it on a paper to verify. Either use mine approach or render only 3 point faces and see if the buggy triangles disappears.

Anyway you can compare with my Wavefront obj C++ loader in here:

I do not think this is a material problem (unless the triangles are encoding some lighting effect or particle directions or whatever) Why not render only single material triangles to see if a specific materials contains only bugged triangles and rest are OK ? If the case may be the mtl properties of infected materials could be identified so you could ignore them automatically latter.

Spektre
  • 49,595
  • 11
  • 110
  • 380
  • Thanks @Spektre. I tried the other triangulation algorithm and it did not change anything. Started to try one material by time (and one combo) and these are the results: red: https://postimg.cc/image/5y7ubq2dd/ gold: https://postimg.cc/image/eghag33r5/ yellow: https://postimg.cc/image/z0m4em98h/394b5e0c/ darksilver: https://postimg.cc/image/m97y84ew1/ lambert1: https://postimg.cc/image/sa5n57onl/ 14_-_Default: https://postimg.cc/image/smx1bheo1/ black: https://postimg.cc/image/l6xrprqzl/ red+gold: https://postimg.cc/image/hakftst5d/ – user2752471 Aug 28 '18 at 23:34
  • A better quality of the 14_Default: https://postimg.cc/image/a8mi76pf5/. Anyway, I find odd, because there seems to be parts that seems to be rendered in different colors. I still have to try combinations to reproduce the artifacts. The red+gold seems fairly ok. Can you note anything @Spektre? I think I need a reference renderer to compare it. Your first comment mentioned something similar, but I currently do not have code to do it. – user2752471 Aug 28 '18 at 23:40
  • @user2752471 was away for a few days. I do not see the artifacts from images in your question in the selected material images. That might suggest your code has problem with either material switching or handling big meshes (many faces possibly some bug during reallocation of growing list)... – Spektre Aug 31 '18 at 13:27
  • I keep expanding the if (mat_name != "red" && mat_name != "gold") clause that I placed right before the code that I posted above until I was able to get this: https://postimg.cc/image/hithke15p/. Sounds pretty flawless for me. Guess how many materials I left behind to be able to generate this? NONE!. I believe there is something odd in the .obj file, perhaps triangles with a material that are not described in the .mtl file, because with the if clause including all the materials described in the .mtl, the result shall be identical. What do you think? – user2752471 Sep 02 '18 at 13:30
  • Forgot to add: @Spektre – user2752471 Sep 02 '18 at 13:30
  • @user2752471 might be ... or the faces in questions are encoded differently (for example with color like most 3D scanners generate) and your loader handles them wrongly – Spektre Sep 02 '18 at 14:57