Oblique near clipping on perspective matrix

Hello all,

I try to use the sample from Eric Lengyel without success,

I think my problem is related to the clip plane, since my plane is from world coordinate, it say it need to be in camera eye coord,
Do I need transform my plane (world space) before using it?

The perspective matrix is build using glm::perspective, my matrix are basically glm::mat4…


    matrix4 oblique = projection;
    vector4 plane(normal, distance);
    vector4 q;
    q.x = (sign(plane.x) + projection[0][2]) / projection[0][0];
    q.y = (sign(plane.y) + projection[1][2]) / projection[1][1];
    q.z = -1.0f;
    q.w = (1.0f + projection[2][2]) / projection[2][3];
    vector4 c = plane * (2.0f / glm::dot(plane, q));

    oblique[0][2] = c.x;
    oblique[1][2] = c.y;
    oblique[2][2] = c.z + 1.0f;
    oblique[3][2] = c.w;

Here the shot using the projection without the oblique. The second shot show the issue I try to resolve with oblique near clip plane.

If I am using this code, I am jumping out of the map, I just see the sky :slight_smile:

By oblique perspective, I assume you mean a case where it is not symmetric perspective but rather asymmetric perspective.

Simplest thing is to just use glFrustum() to cook this PROJECTION matrix and gluLookAt to cook your VIEWING matrix (or use work-alikes, in the now-common case where you aren’t using GL built in matrix math).

In WORLD-SPACE, define your eyepoint and near clip plane. Draw a vector from the eyepoint through and perpendicular to the near clip plane. This is your EYE-SPACE -Z axis. You can define your up-vector as well, and then (incidentally) you have enough to completely define your VIEWING transform – just call gluLookAt to get it.

Now back to that PROJECTION transform. Take that vector you drew from the eyepoint orthogonal to the near clip plane. Take the distance between the eyepoint and the point where it hits the near clip plane. That is your “near” distance for glFrustum(). Now look at the sides of your frustum and where they hit the near clip plane. Those provide your l,r,b,t values. Finally, just pick your “far” value and you’ve just finished collecting all the parameters to pass glFrustum() to build your projection matrix.

By oblique i mean, when you are not in front of a mirror, but on the side, look my image from my app, I use q3dm0 map to test the mirror and portal. see the images, you will understand when you compare both of them.

It’s just i need to transform my plane before using it, I did not find the right transformation to make my oblique work so far.

I try to accomplish this:
http://www.terathon.com/code/oblique.html

Yes.

Note that, with a projection matrix generated by gluPerspective(), setting clipPlane to [0,0,-1,-zNear] leaves the projection matrix unchanged.

So the solution is to change the plane distance for the distance between the camera pos and face origin i guess

I will try that tomorow i am outside for 2 days

Ok I resolved my issues,

I needed to transform my plane in order to use it

matrix4 reflection = plane.reflection();
vector4 q(plane.normal, plane.distance);
q = glm::transpose(glm::inverse(parent.view() * reflection)) * q;