Oblique frustum clipping

xiaoxiao2021-03-06  34

Here is an example code:

http://www.terathon.com/code/oblique.html

See specific instructions can be found

http://www.opengl.org/discussion_boards/cgi_directory/ultimatebb.cgi?ubb=get_topic;f=6;t=000170

Its important part is extracted as follows:

Let P = (PX, PX, PZ, PW) be the Eye-Space Plane to Which You Would Like To Clip.This Will Replace Your Ordinary Near Plane and Should Be Facing Away from Thecamera, SO PZ <0. Let rt q be an Eye-Space Point. if P Dot Q = 0, Then Q LIES ON THE P. What We want to do is modify the Projection Matrix M So That Points Q forwhich P Dot Q = 0 get transformed in Such a Way That That That That That That THE THETS z-coordinateis the negation of the transformed w-coordinate. This corresponds tothe projected z-coordinate that you would ordinarily get for a point lyingon the near plane. After division by the w-coordinate, you get -1. The projection matrix M transforms points from eye space into homogeneous clipspace. to obtain the clipspace plane P ', we need to multiply P by the inversetranspose of M. (This is because planes are covariant vectors.) The clip-spaceplane P' is given by -1 TP '= (m) p let q' be the process of the point q, given by q '= mq. If q LIES ON THE PLANE P, THEN P' DOT Q '= 0, But we want it to be -q'w so it.so we forced it by subtracting 1 from the w-coordinate of p '. Before doing this, howeever, we want to divide p' BY ITS Z-Coordinate As To Avoid Scaling The ZDIRECTION IN Clip Space. doing all of this gives us The following plane p ": p'X p'y p'Wp" = (-----, -----, 1, ----- - 1) P'z P'z P'z We Integrate this Into The Projection Matrix M by Constructing A New ProjectionMatrix M 'As Follows. [1 0 0] [] [0 1 0 0 ] M '= [] m [p "xp"

Y 1 p "w] [] [0 0 0 1] The Matrice m and m 'Only Difer in The Entries of the 3rd Row, SO We Could Justcalculate Replacements for 3rd-Row Entries of M as Follows: M' (3, 1) = P "DOT M_1M '(3, 2) = P" DOT M_2M' (3, 3) = P "DOT M_3M '(3, 4) = P" DOT M_4 WHERE M_I Means The I-TH Column of M And m '(i, j) means the (i, j) -th entry of m'.

.. Okay - here's the short, short version of the optimal implementation of the oblique frustum Let C = camera-space clipping plane Assume the camera is on the negative side of the plane: C_w <0. Let M be the original projection matrix ;. M must be invertible, but otherwise we do not care whatit is We'll modify the third row of M so that the near plane coincides with the arbitraryclipping plane C. We are not allowed to modify the fourth row of M because doing so would screwup the perspective-correct vertex attribute interpolation. (The fourth row usually justmoves the z-coordinate of a camera-space point into the w-coordinate of a clip-space point.) Given a projection matrix M, the near plane IS AlWays M_4 M_3, And The Far Plane IS AlwaySM_4 - M_3. (M_i Means The I-Th Row Of M.) To Force the Near Plane To Coincide with Theclipping Plane C, We Must Have M_3 = AC - M_4, WHERE A IS Some Positive Scale Factor That Wecan Adjust. Why Adjust A? Because Now Our Far Plane F Has Been Moved To F = 2 * M_4 -. AC, which is notgenerally parallel to C. F intersects C on the xy plane, so it's really not in a goodposition The best we can do is minimize the size of the view frustum by choosing theconstant a so that F Contains The Corner Q of the View Frustum Opposite The Near Plane C.THIS POINT Q IS GIVEN BY q = m ^ -1 * (SGN (C_x), SGN (C_Y), 1, 1), WHERE M ^ -1 IS The Inverse of The Projection Matrix. ( /- 1, /- 1, 1, 1) Are Thefour Corners of The View Frustum on The Far Plane In Clip Space.) The scale factor a is nowgiven by a =

转载请注明原文地址:https://www.9cbs.com/read-62625.html

New Post(0)