6 Replies - 587 Views - Last Post: 17 April 2013 - 03:57 PM Rate Topic: -----

#1 Behemyth  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 19-July 12

Deriving a View Frustum's Planes and Excluding a Triangle

Posted 09 April 2013 - 10:28 PM

In a GLSL shader I need to omit a few tessellation patches to drastically increase performance. These patches are triangles with given world coordinates for each vertex. However, when I convert these coordinates into view space for frustum culling, there is a margin of error.

This is the original terrain.

Posted Image

This is how the error affects it on the top.

Posted Image

This is a closeup of a section with dirt.

Posted Image

These errors happen namely around the top of the screen but also the sides and the bottom. Also a triangle that is completely in the center can sometimes disappear. Here is the code I use to determine if I should exclude the triangle (in GLSL).
bool inFrustum( vec3 p,vec3 q,vec3 r) {
    vec4 Pclip = camera * vec4(p, 1.0f);
    vec4 Qclip = camera * vec4(q, 1.0f);
    vec4 Rclip = camera * vec4(r, 1.0f);
    if(((-Pclip.w>Pclip.x&&-Qclip.w>Qclip.x&&-Rclip.w>Rclip.x)||    (Pclip.x>Pclip.w&&Qclip.x>Qclip.w&&Rclip.x>Rclip.w))||
       ((-Pclip.w>Pclip.y&&-Qclip.w>Qclip.y&&-Rclip.w>Rclip.y)||(Pclip.y>Pclip.w&&Qclip.y>Qclip.w&&Rclip.y>Rclip.w))||
       ((-Pclip.w>Pclip.z&&-Qclip.w>Qclip.z&&-Rclip.w>Rclip.z)||(Pclip.z>Pclip.w&&Qclip.z>Qclip.w&&Rclip.z>Rclip.w))){
    return false;
    }
    else{
    return true;
    }
}


I am completly certain that my view matrix is correct as has been tested before to perfection. However am I mistaken in assuming I can derive the planes with these inequalities as demonstrated by this site?
I would greatly appreciate any help given! Behemyth

This post has been edited by stayscrisp: 10 April 2013 - 03:23 AM
Reason for edit:: Use CODE TAGS!


Is This A Good Question/Topic? 0
  • +

Replies To: Deriving a View Frustum's Planes and Excluding a Triangle

#2 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1329
  • View blog
  • Posts: 4,555
  • Joined: 19-February 09

Re: Deriving a View Frustum's Planes and Excluding a Triangle

Posted 11 April 2013 - 02:20 PM

If a part of the triangle is within the frustrum then it is rendered.

View Frustum Culling
Was This Post Helpful? 0
  • +
  • -

#3 Behemyth  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 19-July 12

Re: Deriving a View Frustum's Planes and Excluding a Triangle

Posted 11 April 2013 - 09:13 PM

That is indeed correct! However, in a situation like that it sometime occurs where multiple points of the triangle exceed different planes while the actual face of the triangle is onscreen. Therefore I need to test every point with a single plane, which I am trying to do.
Behemyth
Was This Post Helpful? 0
  • +
  • -

#4 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Deriving a View Frustum's Planes and Excluding a Triangle

Posted 14 April 2013 - 06:18 AM

I think you need to debug exactly where your frustum is culling. Look up 'glslDevil' and take it from there.
Was This Post Helpful? 0
  • +
  • -

#5 Behemyth  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 19-July 12

Re: Deriving a View Frustum's Planes and Excluding a Triangle

Posted 14 April 2013 - 02:29 PM

While I appreciate the help, I cull the triangles before they are further put forth into the pipeline in the tessellation control shader. The idea of getting a glsl debugger is a good one though. Thank you very much!
Was This Post Helpful? 0
  • +
  • -

#6 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Deriving a View Frustum's Planes and Excluding a Triangle

Posted 14 April 2013 - 04:44 PM

No problem.
Was This Post Helpful? 0
  • +
  • -

#7 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1329
  • View blog
  • Posts: 4,555
  • Joined: 19-February 09

Re: Deriving a View Frustum's Planes and Excluding a Triangle

Posted 17 April 2013 - 03:57 PM

View Post#define, on 11 April 2013 - 10:20 PM, said:

If a part of the triangle is within the frustrum then it is rendered.


I think I was suggesting that your code's logic is : if a part of the triangle is outside the frustrum then it is not rendered.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1