Jump to content

  • Log In with Google      Sign In   
  • Create Account

Geometry shader backface culling


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Chriph   Members   -  Reputation: 109

Like
0Likes
Like

Posted 21 July 2013 - 11:11 AM

Hello!

I'm trying to perform backface culling in a geometry shader. So I'm sending a point as a vec3 from the cpu to the gpu through a vbo and then I generate a cube relative to that point in the shader, and I only wish to generate the sides that are acually visible, so I must test if each side is visible to the camera. What I have right now kind of works, but the faces cull too early.

 

I'm using the dot product technique where I take the difference between the camera position and the position of one vertex on the side I wish to test against and dot it with the sides normal.

vec3 point = gl_in[0].gl_Position.xyz + vec3(-0.5f,-0.5f,-0.5f);
vec3 diff = point - CameraPosition[0];
float k = dot(diff, vec3(-1.0f, 0.0f, 0.0f));
if (k <= 0.0f) {
   ..visible
}

That's how I do it in my shader, the gl_in[0].gl_Position lies in the center of the cube. The cube is not rotated (but the world is when the camera rotates) so I assumed that the normal for the left side would just be (-1,0,0).

 

I hope I've given enough information to give you an idea what might cause the problem.

 

-Christopher.



Sponsor:

#2 DDoS   Members   -  Reputation: 312

Like
0Likes
Like

Posted 23 July 2013 - 03:35 PM

i'd suggest to transform the points first by the view*model matrix, then make dot product of the point (normalized) with the view direction, probably (0,0,-1)

to your solution:

float k = dot(diff, vec3(-1.0f, 0.0f, 0.0f));

gives you: k = |diff| * cos(angle_between_vectors) so this is actually a projection and not the angle you want, to erase the impact from the length of diff normalize diff first. 


Edited by DDoS, 23 July 2013 - 03:35 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS