Chinaunix首页 | 论坛 | 博客
  • 博客访问: 13462
  • 博文数量: 10
  • 博客积分: 320
  • 博客等级: 一等列兵
  • 技术积分: 110
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-07 14:12
文章分类
文章存档

2011年(1)

2009年(9)

我的朋友
最近访客

分类:

2009-07-15 16:36:16

glClipPlane平面方程参数的求解

    glClipPlane对裁剪frustum是很管用的,可进一步定义视图体的范围。裁剪平面由方程Ax+By+Cz+D=0确定。所有满足[A B C D]M-1[Xe Ye Ze We]T>0的人眼坐标[Xe Ye Ze We]的点都位于该平面定义的半空间中,而该半空间以外的所有点都被裁剪掉——摘自Redbook。

void findPlane(GLfloat plane[4], vec3 p1, vec3 p2, vec3 p3)
{

/* Need 2 vectors to find cross product. */
 vec3 vec1, vec2;
 vec1= p2 - p1;
 vec2 = p3 - p1;

/* find cross product to get A, B, and C of plane equation */

 plane[A] = vec1.y * vec2.z - vec1.z * vec2.y;
 plane[B] = -(vec1.x * vec2.z - vec1.z * vec2.x);
 plane[C] = vec1.x * vec2.y - vec1.y * vec2.x;
 plane[D] = -(plane[0]*p1.x + plane[1]*p1.y + plane[2]*p1.z);


/////////

for user clip planes,there are at least the following options:


  1. Use the built in User Clip plane functionality already available in GL or GLES1.1. This would be exactly what I need, but I've read that there are all sorts of issues when trying to get this to work on both ATI & Nvidia hardware when using GLSL.

  2. Perform the clipping using a fragment shader. I don't know much about this technique (any information would be appreciated!), but I'm under the impression that this is not very efficient since the pixel is rejected very late in the rendering pipeline.

  3. Use oblique frustum culling and use the near plane to perform clipping. I've already used this technique to perform clipping in a few cases. However, this technique only allows one clip plane and cannot be turned on and off at will since it manipulates the depth buffer. I currently need one clip plane to be used against all primitives (oblique frustum is perfect for this) and a second which can be turned on and off at will while still allowing culled objects to be rendered correctly with the existing depth information.

  4. Perform clipping using alpha values in conjunction with the Alpha test. I don't know where alpha testing is perform within the rendering pipeline, but if it's earlier than fragment shader execution, it could be more efficient than option 2. The application of alpha values for testing would use a 1d alpha texture (one pixel opaque, one pixel transparent) which could be applied to match the clip plane using texture matrix manipulation.
阅读(1011) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~