unitycoder / UnityPointCloudViewer

Point Cloud Viewer and Tools for Unity
https://assetstore.unity.com/packages/tools/utilities/point-cloud-viewer-and-tools-16019?aid=1101lGti
128 stars 15 forks source link

LOD vs. loading and VRAM usage #108

Open nvoelzow opened 3 years ago

nvoelzow commented 3 years ago

as noted in #107 it seems like the LOD method currently only saves render time but not read time or VRAM buffer space - this comment in PointCloudViewerTilesDX11.cs recaps this issue:

            int newPointCount = tiles[index].totalPoints; // FIXME why whole count? but causes flicker if read only needed amount

so if I read your code correctly, the full tile is read from file and uploaded to gpu memory - only to render a fraction of the points contained depending on LOD. This causes severe performance issues with dense point clouds and effectively limits the part of the point cloud that can be rendered - not because of the number of points that need to be rendered (thanks to LOD) but because all of the contained points need to be read into memory.

The gpuUploadSteps uploads the buffers in multiple segments to avoid blocking from what I can tell, but the data already uploaded is not being used until the last bit is uploaded. Would it be possible to render the portion of the tile that is already uploaded so that the rendering reflects the incremental loading?

The other comments in the code suggest that you already have a fix in mind (loading batches of points instead of updating the buffers for single points etc) - is this something that could be available soon?

unitycoder commented 3 years ago

yeah had some issue with that fix, caused more flicker / disappearing tiles (but did improve the loading times), so still looking into better fix for that.

nvoelzow commented 3 years ago

are the tiles flickering/disappearing because they are being marked as unavailable while the buffers are updated?

unitycoder commented 3 years ago

quite sure that was it, but cant remember right now if i pin pointed it last time somewhere there.

nvoelzow commented 3 years ago

yes, flickering is due to the tiles being marked as loading/queued even when there is still data in the buffer that could be displayed (this is worse if gpuUploadSteps is used as they will be "blocked" for several frames) - rearranging the code a bit and setting the visiblePoints after the upload (using a new targetPoints variable to tell the loader how many points should be loaded to disentangle the required/loaded/visible counts) and removing the check for isLoading before the actual draw call fixed this for me when loading only the requested number of points in the buffers

nvoelzow commented 3 years ago

next thing I might try to figure out is how to modify the file handling (already replaced ReadAllBytes() but still only reads from beginning of file), MoveFromByteArray etc to do incremental reads/updates, as the data still gets reloaded from scratch even though part of the tile was previously already loaded (which interestingly enough is not that much of a performance issue though)