Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rmodels] More performant point cloud rendering with DrawModelPoints() #4203

Merged
merged 13 commits into from
Aug 24, 2024

Conversation

satchelfrost
Copy link
Contributor

Currently, raylib has DrawPoint3D which works well for most things, but has a few issues:

  1. technically draws lines not points
  2. starts to become less performant as point cloud size increases

Instead I added a two new functions DrawModelPoints and DrawModelPointsEx. They follow the same pattern as DrawModelWires and DrawModelWiresEx, but instead temporarily sets rlEnablePointMode and rlDisableBackfaceCulling (which it then reverts after calling DrawModel). The following example provided demonstrates the performance difference between DrawModelPoints and DrawPoint3D for various point cloud sizes.

With my card (6700xt) 1,000,000 points are easily rendered @60 FPS using DrawModelPoints, whereas the same example with DrawPoint3D is unusable < 10 FPS. Your mileage may vary depending on the graphics card, but overall DrawModelPoints should be more performant than DrawPoint3D.

@raysan5
Copy link
Owner

raysan5 commented Aug 4, 2024

@satchelfrost Thanks for the addition, please, note that new examples should follow examples template, including the rules and conventions: https://github.com/raysan5/raylib/blob/master/examples/examples_template.c

@raysan5 raysan5 changed the title More performant point cloud rendering with DrawModelPoints [rmodels] More performant point cloud rendering with DrawModelPoints() Aug 4, 2024
examples/models/models_point_rendering.c Outdated Show resolved Hide resolved
examples/models/models_point_rendering.c Outdated Show resolved Hide resolved
@raysan5
Copy link
Owner

raysan5 commented Aug 6, 2024

Please, note that the following files should be updated when adding a new example, it's planned to create some script to automatize part of this process but not available yet.

 - raylib/examples/<category>/<category>_example_name.c
 - raylib/examples/<category>/<category>_example_name.png
 - raylib/examples/<category>/resources/*.*
 - raylib/examples/Makefile
 - raylib/examples/Makefile.Web
 - raylib/examples/README.md
 - raylib/projects/VS2022/examples/<category>_example_name.vcxproj
 - raylib/projects/VS2022/raylib.sln
 - raylib.com/common/examples.js
 - raylib.com/examples/<category>/<category>_example_name.html
 - raylib.com/examples/<category>/<category>_example_name.data
 - raylib.com/examples/<category>/<category>_example_name.wasm
 - raylib.com/examples/<category>/<category>_example_name.js

@satchelfrost
Copy link
Contributor Author

Ah, sorry about that, I will make those changes.

On a separate note I did some more investigation with the point rendering. On my machine rendering 10,000,000 points, I noticed that when I zoomed in, the frame rate started to drop. Which doesn't really make any sense for a point cloud.

So I opened renderdoc and found that even though the points are being shown in the final image, you can actually see the triangles in wireframe in renderdoc.

using_rlEnablePointMode_renderdoc

As a test, instead of using rlEnablePointMode(), I modified rlDrawVertexArray() to use GL_POINTS. Visually there is no difference in the final image. But when I zoom in at 10,000,000 points there is no performance drop, and its a solid 60 FPS, and the renderdoc image shows only points being drawn.

using_gl_points_renderdoc

Also just to see how far I could push it on my machine I was able to get 100,000,000 points at roughly 50 FPS. Kind of looks like a blob though.

blob

So my question is given that it is even more performant to just use GL_POINTS instead of just rlEnablePointMode(), would you like me to modify the current code to use this method instead? Perhaps a new function rlDrawVertexArrayPoints()? The current method works and doesn't mess with the API too much, it's just not as performant as it could be.

@raysan5
Copy link
Owner

raysan5 commented Aug 10, 2024

@satchelfrost I'm not sure how to address this improvement, not only because it's platform-dependant but also because if rlDrawVertexArray() uses GL_POINTS internally, it would use x3 vertex for any model, considering the data provided are usually 3-vertex per triangle...

@satchelfrost
Copy link
Contributor Author

In that case, I will stick to the previous approach which is still more performant than DrawPoint3D. I've updated the makefiles as well. I still need to figure out how to generate the vcxproj file since I don't use visual studio and it looks like a simple copy paste from one of the other examples won't work because a guid needs to be generated (currently using Linux). If you're okay with the current example then I will make a request on the raylib.com repo for the web version.

@raysan5 raysan5 merged commit 7bde76c into raysan5:master Aug 24, 2024
@raysan5
Copy link
Owner

raysan5 commented Aug 24, 2024

@satchelfrost Thanks for the review! Don't worry about the VS project, I'll try to address it myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants