C++: Non-deterministic behaviour in Ray Tracer output

94 views Asked by At

I'm writing a ray tracer and have already been able to render spheres and planes with Phong shading.

However I am getting very strange behaviour with my triangles. Whenever I run the program, the Triangle seems to take an arbitrary colour (even without recompiling). I am new to C++, and I have no idea what could be causing this at all as the other objects are fine, and they all inherit the same method to compute their colours.

The triangle will most frequently be black, but occasionally be as single shade of blue, red or pink (there may be other colors but not sure). What I noticed is that each shade is consistent, likely with the RGB values being 1 or 0, I would guess that the blue for example be (0,0,1) based off of my observation.

My question is, what could be a possible cause for this strange non-determinism? It kind of baffles me, but then again I am new to C++. Is this an issue common to ray tracing? Could it be an object orientation, or pointer/reference issue?

I can provide more details if needed, I just don't have a clue why this would be happening.

Thanks for the help!

1

There are 1 answers

0
Alexander V On

The likeliest cause of non-determinism is an uninitialized but used variable in your code.