Matching perspective of raster and raymarched render?

Hey, I have a raymarching setup rendering some metaballs.

[code] //interpolate eye position from billboard fragment coordinates
vec2 position = -1.0+2.0*gl_FragCoord.xy/resolution.xy;
position.x *= resolution.x/resolution.y;

//define camera position and target
vec3 camera = vec3(0, 0, 5);
vec3 target = vec3(position,0.0) + vec3(0.0,0.0,1.5);	

vec3 ray = normalize(target-camera);[/code]

Now I want to combine that render with a traditional raster based rendering (either as 2 passes and later using z-composite, or if possible all in one setup). So for starters, the question would be how I could match the perspective of both setups? Ideally I’d like to grab the transform/rotate/viewing-angle info from the main camera and somehow apply it to above raymarcher setup. Any ideas?

To take a pixel coordinate and find it’s position in eye space you would do

vec2 position = -1.0+2.0*gl_FragCoord.xy/resolution.xy;

// Z depth is the non linear (-1,1) depth (-1 being the near plane and 1 being the far plane)
vec4 p = vec4(position, zDepth, 1);

vec4 viewSpaceCoord = gl_ProjectionMatrixInverse * p;
viewSpaceCoord /= viewSpaceCoord.w;

So now you are in the same space as:

vec4 v = gl_ModelViewMatrix * gl_Vertex;

gives you.

Maybe you can elaborate more on what your raymarching is doing, if my answer doesn’t make sense.