   User defined clip planes & GLSL
  I'm trying to implement user defined clip planes using GLSL. It seems i'm missing something though because everytime i move the camera, the clipping plane moves too. I'm performing the calculations in view space. Here are the shaders:VERTEX SHADERvarying vec4 pos;varying vec4 plane;void main(){// plane = 0,1,0,-889.014float D= -889.014;   // Transform the normal to view space   plane = vec4(0,1,0,0);   plane = vec4(gl_NormalMatrix * vec3(0,1,0), 0); // transform the plane's distancemat3 a = gl_ModelViewMatrixInverse;vec4 T = vec4(0,0,0,1);   T = gl_ModelViewMatrix * T; // get the translation partplane.w = D - vec3(0,1,0) * a * vec3(T.x, T.y, T.z);pos = gl_ModelViewMatrix * gl_Vertex;gl_Position = ftransform();}FRAGMENT SHADERvarying vec4 pos;varying vec4 plane;void main(){    if (dot(pos.xyz,plane.xyz)+plane.w < 0)   return;    gl_FragColor = 1.0;}Can somebody shed some light on what i'm doing wrong?   
  If you do thisplane = vec4(gl_NormalMatrix * vec3(0,1,0), 0);yes, the plane will be in eye space or if you want to call it camera space. In other words, they move with the camera.   ;Quote:Original post by V-manIf you do thisplane = vec4(gl_NormalMatrix * vec3(0,1,0), 0);yes, the plane will be in eye space or if you want to call it camera space. In other words, they move with the camera.So how should i do it then? I transform the plane in view space so it's in the same space with the position i'm testing against it.   ;  You should always define your clip plane in world space. You should compute the plane on the CPU and upload it as a uniform. This will give the best performance. To test against a vertex, you would need to transform a vertex from object space to world space. Make a uniform mat4 and call it WorldMatrix. Do not bother with gl_NormalMatrix and gl_ModelviewMatrix.   ;Quote:Original post by V-manYou should always define your clip plane in world space. You should compute the plane on the CPU and upload it as a uniform. This will give the best performance. To test against a vertex, you would need to transform a vertex from object space to world space. Make a uniform mat4 and call it WorldMatrix. Do not bother with gl_NormalMatrix and gl_ModelviewMatrix.Thanks, world space there is, then!   