   Threshold on color in shaders
  The code is drawming 1 millions of point sprites with different color using a VBO with 2 arrays, g_vertices (contains the x,y,z coordinates of each point) and g_colors (contains the rgb color of each point, no alpha value). I'm using a vertex and fragment shader to show the point sprites as spheres. What i want to do in the shader is a threshold on the particles with a color that i don't want to see. For example, i don't want to see the particle with a red value over 0.5. How could i do this in the shaders?
  The easiest solution is probably something like if(red < 0.5) discard; in the fragment shader, which will skip those pixels.   ;  Do you mean :if(gl_color.r < 0.5) discard;??;  It's working, but now i'm getting alot of z-fighting. I'm using gl_FragDepth = gl_FragCoord.z;so everything is fine before doing the discard of red pixel.With the red discard, even if i call gl_FragDepth, there is still some z-fighting.;  Shouldn't that be if(gl_color.r > 0.5) discard; and not <I don't know why it would cause z-fighting. That doesn't make any sense.Perhaps you can check in the vertex shader if the color of the sprite is red, then push it offscreen. The GPU's clip ability will do the rest.   ;  And how would i do that in the vertex shader? right i'm doing the discard in the fragment shader. It's making the fps slower, so i'm not sure it is the best way to do it.   ;  shouldn't setting the position w coordinate resulting in clipping of the vertex?   ;  I have done it like thisif(red == GOOD){gl_Position = ProjectionModelviewMatrix * gl_Vertex;}else{   gl_Position = vec4(2.0, 2.0, 0.0, 1.0);}In your case, I guess you are using gl_PointSprite.   ;  Ok i tried this, so let me know if this is the correct way of doing it :if(gl_Color.r>0.80){gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;gl_FrontColor = gl_Color; //should i put this line here, or outside of the if statement?}else{gl_Position = vec4(2.0, 2.0, 0.0, 1.0); // i don't understand what is this line doing? When i don't compile this line, there are some weird stuff going on in my screen//when it is on, everything is normal as it should be.}