分享
 
 
 

Oblique Frustum Clipping

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

这里是例子代码:http://www.terathon.com/code/oblique.html

具体的说明可以参见 http://www.opengl.org/discussion_boards/cgi_directory/ultimatebb.cgi?ubb=get_topic;f=6;t=000170

其重要部分摘录如下:

Let P = (Px, Py, 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 the

camera, so Pz < 0.

Let Q be an eye-space point. If P dot Q = 0, then Q lies on the plane P.

What we want to do is modify the projection matrix M so that points Q for

which P dot Q = 0 get transformed in such a way that the transformed z-coordinate

is the negation of the transformed w-coordinate. This corresponds to

the projected z-coordinate that you would ordinarily get for a point lying

on the near plane. After division by the w-coordinate, you get -1.

The projection matrix M transforms points from eye space into homogeneous clip

space. To obtain the clip-space plane P', we need to multiply P by the inverse

transpose of M. (This is because planes are covariant vectors.) The clip-space

plane P' is given by

-1 T

P' = (M ) P

Let Q' be the projection 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 that it corresponds to the near plane.

So we force it by subtracting 1 from the w-coordinate of P'. Before doing this,

however, we want to divide P' by its z-coordinate as to avoid scaling the z

direction in clip space. Doing all of this gives us the following plane P":

P'x P'y P'w

P" = (-----, -----, 1, ----- - 1)

P'z P'z P'z

We integrate this into the projection matrix M by constructing a new projection

matrix M' as follows.

[ 1 0 0 0 ]

[ ]

[ 0 1 0 0 ]

M' = [ ] M

[ P"x P"y 1 P"w ]

[ ]

[ 0 0 0 1 ]

The matrices M and M' only differ in the entries of the 3rd row, so we could just

calculate replacements for 3rd-row entries of M as follows:

M'(3,1) = P" dot M_1

M'(3,2) = P" dot M_2

M'(3,3) = P" dot M_3

M'(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 don't care what

it is. We'll modify the third row of M so that the near plane coincides with the arbitrary

clipping plane C. We aren't allowed to modify the fourth row of M because doing so would screw

up the perspective-correct vertex attribute interpolation. (The fourth row usually just

moves 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 always

M_4 - M_3. (M_i means the i-th row of M.) To force the near plane to coincide with the

clipping plane C, we must have M_3 = aC - M_4, where a is some positive scale factor that we

can adjust.

Why adjust a? Because now our far plane F has been moved to F = 2*M_4 - aC, which is not

generally parallel to C. F intersects C on the x-y plane, so it's really not in a good

position. The best we can do is minimize the size of the view frustum by choosing the

constant 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. (The points (+/-1, +/-1, 1, 1) are the

four corners of the view frustum on the far plane in clip space.) The scale factor a is now

given by

a = (2*M_4 dot Q) / (C dot Q).

Since M_4 is usually (0, 0, -1, 0), this can be simplified a little.

All we have to do to the original projection matrix M is replace the third row with aC - M_4.

-- Eric Lengyel

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有