Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

Oblique Depth Projection troubles...

Started by _mark_ Nov 14, 2007 at 8:25 PM 0 replies 1.7k views
Original Post
_mark_
_mark_
I am trying to use the Oblique Depth Projection code at http://www.terathon.com/code/oblique.php , but am having problems (using OpenGL). I am trying to render reflections in a Y=0 plane. I get the same problem whether I use Render to Texture, or just draw directly; I get the same issue with or without shaders. The clipping doesn't behave as expected - it clips objects partly in a -ve Y direction (i.e., objects towards the bottom of the screen are clipped away, which is opposite to what I want). Also it isn't fixed in world space, but moves with the camera (I am specifying the plane in camera space), and the plane appears to be tilted forward, so that objects nearer the camera are clipped first. This problem occurs both on NVIDIA 8600GT and Intel GMA 950. Everything works fine if I use the OpenGL user clip planes. Also, the z-ordering appears to be reversed - objects further away are drawn in front of those nearer. This seems to be due to my use of glScale3f(0,-1,0) for the reflection - if I don't reflect the objects, this issue is fixed, but the clipping still doesn't work properly (the reflection scale works fine with user clip planes). The code is:

        // Calculate the clip-space corner point opposite the clipping plane
        // as (sgn(clipPlane.x), sgn(clipPlane.y), 1, 1) and
        // transform it into camera space by multiplying it
        // by the inverse of the projection matrix
        float q_x = (sgn(pl[0]) + matrix[8]) / matrix[0];
        float q_y = (sgn(pl[1]) + matrix[9]) / matrix[5];
        float q_z = -1.0F;
        float q_w = (1.0F + matrix[10]) / matrix[14];

        // Calculate the scaled plane vector
        //Vector4D c = clipPlane * (2.0F / Dot(clipPlane, q));
        float dot = q_x * pl[0] + q_y * pl[1] + q_z * pl[2] + q_w * pl[3];
        float scale = 2.0 / dot;

        // Replace the third row of the projection matrix
        matrix[2] = pl[0] * scale;
        matrix[6] = pl[1] * scale;
        matrix[10] = pl[2] * scale + 1.0F;
        matrix[14] = pl[3] * scale;
Here are the details of my data: Plane in world space: (x,y,z,d) = (0, -1, 0, 0) [Is that oriented the right way? I want to clip away everything being drawn above the y=0 plane for the reflections; if I reverse the sign, then I don't get any reflections drawn, it seems to all be clipped away.] Plane in eye space: (0, -1, 0, 0.5) [this looks right? - the camera is looking along the z axis, and is at y=0.5] The perspective matrix before modification is: [ 2.414 0 0 0 ] [ 0 2.414 0 0 ] [ 0 0 -1.0002 -0.2 ] [ 0 0 -1 0 ] The 3rd row is changed to: [ 0 -4.823 1 2.411 ] Now I have some code to extract the frustum planes from the perspective matrix, and the result from this is: RIGHT -0.923880 0.000000 -0.382683 0.000000 LEFT 0.923880 0.000000 -0.382683 0.000000 BOTTOM 0.000000 0.923880 -0.382683 0.000000 TOP 0.000000 -0.923880 -0.382683 0.000000 FAR 0.000000 0.923716 -0.383078 -0.461858 NEAR 0.000000 -1.000000 0.000000 0.500000 So the near plane has been correctly modified(?) Is it the modified far plane that is causing the problem? The orientation would seem to give the result I am observing of objects being clipped as I move close to them. But that doesn't explain why the near plane doesn't seem to be clipping anything, nor does it explain why the z-ordering seems to be reversed? Also, comparing the Far plane to the Bottom plane, it seems to me that the far plane is below the bottom plane, i.e., it shouldn't intersect the view frustum (the intersection point, I believe, is at ( 0 413.252883 997.682347 ))? Any ideas? Thanks in advance.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.