I am rendering a huge point cloud (1.5 Mio. points) as GLPoints with WebGL and naturally encounter performance issues.
So my first idea is limit the amount of points be drawn on the screen. Especially points far away from the camera are “useless” and should not be rendered.
I went about it by calculating the distance between any point and the camera. In my vertex shader I would like to only render the points “close” enough to the camera. So far I try to skip them if the distance “s” is in between the camera and a clipping plane (hence negative).
if( s < 0.0){
gl_Position = vec4(0.0, 0.0, 0.0, 0.0);
frontColor = vec4(0.0, 0.0, 0.0, 1.0);
gl_PointSize = 0.0;
}else{
gl_Position = ps_ProjectionMatrix * ecPos4;
}
However, instead of completely skipping the vertex it is still rendered (even if I don’t see it) as I can tell by the FPS displayed.
Is there a way to completely disable/skip/”delete” a vertex within a vertex shader?
I can see how frustum culling would help speed things up. To clearify things, when should the culling take place? Since the culling has to be recalculated after every camera movement, should I put in my main loop? However doing 1 Mio. calculations in the render loop does not seem to be a very good idea.
Do I understand it correctely that once my camera looks in totally different direction than my points these should be clipped automatically by WebGl/the hardware? Yet, I get the feeling that looking “away” does not help. (FPS did not go up) Can someone please elaborte a bit!
The engine that I use has a default perspective projection matrix. Obiviously it affects the coordinates of every vertex. How does the projection matrix relate to the auto clipping?
It sounds like you need to tweak your projection matrix, so that your view frustum culls out those points that are too far away to meaningfully contribute to your image. This tutorial from lighthouse3d provides a description of the viewing frustum, and describes methods for implementing frustum-based culling in software. Note that this is not necessary in your case, since OpenGL does it for you, provided you’ve set up your projection matrix appropriately.