GraphicSir
游戏技术,实时渲染技术
posts - 0,  comments - 3,  trackbacks - 0

近日因公司项目需要,写了个屏幕分割渲染的功能。

如下图所示:假设我们有一个场景,场景里面大多数是静态对象(对应图中黑色点),而只有小量的动态对象并且相对集中(对应图中红色点),那么我们在渲染的时候,只要一开始将整个屏幕渲染一次,在后面只更新动态对象所在的区域就可以了。



在测试例子中,我们将整个屏幕分成左右2块,各自分别对应一个投影矩阵和一个视口,他们共用一个视图矩阵和世界矩阵。在如何决定子屏幕所使用的投影矩阵时,主要采用 D3DXMatrixPerspectiveOffCenterLH()或 D3DXMatrixPerspectiveOffCenterRH()这2个函数。具体描述如下:

D3DXMatrixPerspectiveOffCenterLH()
Builds a customized, left-handed perspective projection matrix.

    
D3DXMATRIX * D3DXMatrixPerspectiveOffCenterLH(
        D3DXMATRIX * pOut,
        FLOAT        l,
        FLOAT        r,
        FLOAT        b,
        FLOAT        t,
        FLOAT        zn,
        FLOAT        zf);
  
Parameters
pOut
[in, out] Pointer to the D3DXMATRIX structure that is the result of the operation.
l
[in] Minimum x-value of the view volume.
r
[in] Maximum x-value of the view volume.
b
[in] Minimum y-value of the view volume.
t
[in] Maximum y-value of the view volume.
zn
[in] Minimum z-value of the view volume.
zf
[in] Maximum z-value of the view volume.
Return Values
Pointer to a D3DXMATRIX structure that is a customized, left-handed perspective projection matrix.

Remarks
All the parameters of the D3DXMatrixPerspectiveOffCenterLH function are distances in camera space. The parameters describe the dimensions of the view volume.

The return value for this function is the same value returned in the pOut parameter. In this way, the D3DXMatrixPerspectiveOffCenterLH function can be used as a parameter for another function.

This function uses the following formula to compute the returned matrix.

2*zn/(r-l)   0            0              0
0            2*zn/(t-b)   0              0
(l+r)/(l-r)  (t+b)/(b-t)  zf/(zf-zn)     1
0            0            zn*zf/(zn-zf)  0

 


D3DXMatrixPerspectiveOffCenterRH()
Builds a customized, right-handed perspective projection matrix.
    
D3DXMATRIX * D3DXMatrixPerspectiveOffCenterRH(
        D3DXMATRIX * pOut,
        FLOAT        l,
        FLOAT        r,
        FLOAT        b,
        FLOAT        t,
        FLOAT        zn,
        FLOAT        zf);
    
  
Parameters
pOut
[in, out] Pointer to the D3DXMATRIX structure that is the result of the operation.
l
[in] Minimum x-value of the view volume.
r
[in] Maximum x-value of the view volume.
b
[in] Minimum y-value of the view volume.
t
[in] Maximum y-value of the view volume.
zn
[in] Minimum z-value of the view volume.
zf
[in] Maximum z-value of the view volume.
Return Values
Pointer to a D3DXMATRIX structure that is a customized, right-handed perspective projection matrix.

Remarks
All the parameters of the D3DXMatrixPerspectiveOffCenterRH function are distances in camera space. The parameters describe the dimensions of the view volume.

The return value for this function is the same value returned in the pOut parameter. In this way, the D3DXMatrixPerspectiveOffCenterRH function can be used as a parameter for another function.

This function uses the following formula to compute the returned matrix.

2*zn/(r-l)   0            0                0
0            2*zn/(t-b)   0                0
(l+r)/(r-l)  (t+b)/(t-b)  zf/(zn-zf)      -1
0            0            zn*zf/(zn-zf)    0

  


download: DEMO and source

posted on 2009-06-21 15:51 阅读(856) 评论(0)  编辑 收藏 引用 所属分类: DirectX

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理



<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用链接

留言簿(1)

文章分类

文章档案

相册

搜索

  •  

最新评论