When I work such an issue I set the breakpoint where the trouble is and examine variables.
There's some variable that controls the output so that's what you look at.
You've posted a lot about ray-tracing and that's all good but setting breakpoints to see what's going on seems to be the challenge.