project a portal onto the near plane of a frustum


I try to implement the portal culling in the engine JMonkeyEngine 2.0. I read this to understand some important steps:

A portal can be split into triangles. Then, I follow what is written in the FAQ to convert the triangles from object coordinates to normalized device coordinates:

Object Coordinates are transformed by the ModelView matrix to produce Eye Coordinates.

Eye Coordinates are transformed by the Projection matrix to produce Clip Coordinates.

Clip Coordinate X, Y, and Z are divided by Clip Coordinate W to produce Normalized Device Coordinates.

Normalized Device Coordinates are scaled and translated by the viewport parameters to produce Window Coordinates.

After that, instead of converting the normalized device coordinates into window coordinates, I scale them and translate them by the frustum parameters (to have them projected onto the near plane???) like in the example below:

store = getNormalizedDeviceCoordinates( worldPosition , store );
store.x = ( ( ( store.x + 1 ) * ( frustumRight - frustumLeft ) / 2 ) ) + frustumLeft;
store.y = ( ( ( store.y + 1 ) * ( frustumTop - frustumBottom ) / 2 ) ) + frustumBottom;
store.z = ( store.z + 1 ) / 2;

Then, I look for the extremums (left most, right most, top most, bottom most coordinates) and I clip them into the current view frustum.

Finally, I use the coordinates I get in the previous step to build a sub-frustum that may have different values than the current frustum only for the parameters left, right, bottom and top.

My problem is that the obtained sub-frusta are always too small. That is why I would like to know if my method is correct. How would you convert normalized device coordinates into “frustum” coordinates? How would you project vertices onto the near plane of a frustum?

Best regards.

Julien Gouesse
Author of TUER:


My portal culling works only when the left and right parameters of the sub-frusta have the same sign (both positive or negative):

Is it legal to have such frusta in OpenGL?