Correct computation of ray direction when performing ray marching

This question is not explictly JMonkey-related, but since I’m using JME3 at the moment, I hope this isn’t the wrong place to put it :wink:

I’m implementing single-pass ray-marching in object-space. I’m rendering the faces of a box to invoke the shader. I noticed strange artifacts when looking at specific, sharp angles, which I believe are caused by a wrong computation of the ray direction.

I’ve read several articles while looking for hints on how to compute the ray direction correctly. They all computed this direction in more or less similar ways, always involving the field of view or the focal length.

But what I don’t understand, i.e. my actual question: Why can’t I just pick the object-space eye-to-vertex vector within the vertex shader, denoted as dotted lines on the picture below, pass these vectors to the fragment shader and normalize it there? Wouldn’t this give me the fragment-dependent directional vectors that are denoted as arrows on the picture below? If yes, than aren’t these the also the correct ray directions?

Since I’m not sure what your marched rays are doing, do they need to march on a grid?

No, they don’t. They are sampling perlin noise.

Well, I suspect we can’t help debug the issue without knowing more about what they are for and maybe pictures of the artifacts you mentioned. I suppose they could just be floating point errors accumulating… depending on how you are marching the vectors.

This is well understandable. But this also isn’t what I asked for :wink:

I asked whether (and why if yes) my computation of the ray direction is wrong.

Well, we don’t know what right is… so sure. Maybe. Maybe not. “I’m driving my car. I think I see things I don’t recognize. Am I going to the right place?”

I don’t understand. How is the information I gave insufficient to tell whether it’s right or not? What have I missed?