0

I'm trying cull away every face, if it's normal has an angle of: 90 < x < 270 (degrees) with the vector from cameraPosition to vertexPosition.

Everything I see is the screen turning black. I just started with GLSL so I don't know what the reason could be... Or how to debug.

Vertex Shader:

uniform vec3 camera_Position;

void main(void)
{
 vec4 vertex_Position = gl_ModelViewProjectionMatrix * gl_Vertex;

 vec3 N = gl_Normal.xyz; 

 vec3 V = camera_Position - vertex_Position;

 float angle = degrees(acos(dot(N,V)));
 if(angle >= 90) {
  return;
 }
 if(angle <= 270) {
  return;
 }

 gl_Position = vertex_Position;
}

Fragment Shader:

void main()
{
 gl_FragColor = gl_Color;
}
user3088126
  • 175
  • 1
  • 12
  • 1
    There is no way how one can discard a vertex in the vertex shader. Otherwise you would break the primitive assembly. I don't think your method can work in the vertex shader anyway when the normals are smoothed over the surface. Btw.: What you are trying to do is [backface culling](https://www.opengl.org/wiki/Face_Culling), which the hardware already does for you – BDL Sep 16 '15 at 07:29
  • I already use backface culling, but what about faces that face away from me after this culling? I want to remove these too, since it would probably double the render speed – user3088126 Sep 16 '15 at 07:51
  • 2
    How should there be faces pointing away from you after culling? Backface culling is the last stage before rasterization, so there is no way to change a primitive after this. – BDL Sep 16 '15 at 07:59
  • I got a voxel world, where I generate all the faces, even those who point away from me (for instance a hill in this world). This hill contains faces in all directions, but you can only see those, whose front faces are pointing towards you. I'm already only talking about front faces here. Otherwise there would be holes in the hill, if you would look from the other side. Do you get me now? – user3088126 Sep 16 '15 at 08:00
  • 3
    @user3088126: After backface culling there are no more primitives facing away (or toward you, depending on the culling mode) left. That's the whole point of backface culling. – datenwolf Sep 16 '15 at 08:04
  • Alright... Thank you! – user3088126 Sep 16 '15 at 08:06

0 Answers0