That didn't answer my question. You're in a vertex shader. The gl_Position output needs to be the position of a vertex. Unless you're somehow making a vertex correspond to a ray intersection, your code doesn't make sense. And if you are making a vertex be a ray intersection, I'm pretty sure that doesn't work.

Not unless you're subdividing the screen into pixel-sized quads or something. But even then, I don't think that's a good way to go about ray-tracing with shaders.

My point is that I'm very confused about how what you're doing works as a ray tracer. Until I understand that, I can't really explain what it is you're looking for. What is the mesh you're rendering?

Alfonse, thanks but your not helping.
If you had READ my post you would see that I am doing a ray intersect near plane.
I have been shader programming for over 8 years. Please be smarter than me if your going to post here. Otherwise your just making noise on my thread. Again thanks, but your obviously not reading the question.
I am hoping to find the one person on planet earth that knows how to calculate gl_position.w without a perspective matrix.

If you had READ my post you would see that I am doing a ray intersect near plane.

That doesn't explain what you're doing. Are you intersecting the ray with the near plane? Are you firing a ray from the near plane into some kind of scene?

And the most important question of all is what does the vertex represent? How does the point of intersection translate to a rasterized position of some primitive? Are you rendering a field of GL_POINTS, where each point is an intersection with a scene? Are you trying to ray trace a scene, such that the ray intersections are rendered as vertices of a triangle (with the lighting computations done in the fragment shader)?

The answers to these questions greatly affect what gl_Position should be.

In short, I need to understand what you're doing more than "I am doing a ray intersect near plane". Without the answers to these questions, I can't help you.

Most GPU raytracing algorithms do the ray tracing in the fragment shader, where they have absolute control over everything. Yours is using vertex shaders, which is not exactly standard for GPU ray tracing. So it isn't clear what your algorithm is.

Or let me put it another way. The answer I want to give is "make W 1.0". But I can't give that answer because I have no idea what it means to interpolate between ray intersections. I've never heard of a ray tracing algorithm that interpolates between intersections. And it is the interpolation that's going to make your W do the wrong things.