DX9下使用
D3DXPLANE plane;
D3DXPlaneFromPointNormal( &plane, &vPoint, &vNormal ); //生成这个平面
D3DXMatrixReflect( &matReflect, &plane ); //取得该平面的反射矩阵
//设置剪切平面,使反射面上的内容被渲染,面下的被丢弃
m_pd3dDevice->SetClipPlane( 0, plane );
m_pd3dDevice->SetRenderState( D3DRS_CLIPPLANEENABLE, 0x01 );
DX10下模拟:
User Clip PlanesUser Clip Planes are emulated by specifying a clip distance output from the Vertex Shader with the SV_ClipDistance[n] flag, where n is either 0 or 1. Each component can hold up to 4 clip distances in x, y, z, and w giving a total of 8 clip distances.
用户裁减平面通过在VS里设定一个SV_ClipDistance[n]标记,定义一个裁减距离输出得到,n为0或1。这里一共能存放8个Clip Plane距离,分别使用数组两个元素的x,y,z,w通道。
In this scenario, each clip planes is defined by a plane equation of the form:
在这个场景里,每个clip plane被一个平面方程定义:
Ax + By + Cz + D =0;
Where <A,B,C> is the normal of the plane, and D is the distance of the plane from the origin. Plugging in any point <x,y,z> into this equation gives its distance from the plane. Therefore, all points <x,y,z> that satisfy the equation Ax + By + Cz + D = 0 are on the plane. All points that satisfy Ax + By + Cz + D < 0 are below the plane. All points that satisfy Ax + By + Cz + D > 0 are above the plane.
<A,B,C>是平面法向,D是平面到原点的距离。把任意点<x,y,z>代入方程能得到它到平面的距离。所有满足方程=0的点在平面上,<0的点在平面下而 >0的点在平面上。
In the Vertex Shader, each vertex is tested against each plane equation to produce a distance to the clip plane. Each of the three clip distances are stored in the first three components of the output component with the semantic SV_ClipDistance0. These clip distances get interpolated over the triangle during rasterization and clipped if the value every goes below 0.
在VS中,每个顶点会带入平面方程做测试。每个三角形的Clip距离存在SV_ClipDistance0语义输出的前三个通道中。这个距离在光栅化中被线性插值,所有小于0的像素被剔除。