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

Building TLAS on top of CWBVH? #104

Open
stuw-u opened this issue Feb 10, 2025 · 2 comments
Open

Building TLAS on top of CWBVH? #104

stuw-u opened this issue Feb 10, 2025 · 2 comments

Comments

@stuw-u
Copy link

stuw-u commented Feb 10, 2025

Hi, I'm very new to BVH construction and software raytracing.

I was wondering why CWBVH seem to only support geometry, and doesn't seem to have constructor to take in BlasInstances?
Is this not a good idea?

There's this Unity-based path tracer TrueTrace that seems to be using CWBVH for both BLAS and TLAS, so I think it's possible.

@jbikker
Copy link
Owner

jbikker commented Feb 10, 2025

It's possible, and in some cases it may be a good idea, e.g. when the number of BLAS nodes is very high. In other cases I think the CWBVH is not the best choice, for two reasons:

  1. The bounds stored in a CWBVH are approximate, to keep the node structure small (80 bytes). This leads to some 'false positives'. For BLAS traversal this is a trade-off that pays off, but I am not sure this will also be the case for the TLAS.
  2. Construction of a CWBVH involves several steps: Building a BVH, collapsing it to an 8-wide MBVH and then finally converting that to CWBVH. Since a TLAS is typically rebuilt per frame, this may be objectionable overhead that is probably not compensated by the theoretically faster traversal of the TLAS.

But I admit: There are several assumptions in there that I can't support with experimental evidence; you could give it a try and feed 'dummy triangles' that span up the AABBs of your BLASInstances to try it out.

@stuw-u
Copy link
Author

stuw-u commented Feb 10, 2025

This is very insightful, thank you.
I had assumed about the longer build time but I had forgotten about the approximation part.

To be honest, I haven't tried tinyBVH yet. I decided to port parts of it to Unity Burst for fun and as a learning experience, so any performance difference I'd notice on my side probably wouldn't translate well on your side, so I'll probably won't bother with experimental evidence for the time being.

I know for the sake of this project you made the assumption that CPU are often underutilized in games, so you opted for CPU TLAS building every frame. On top of TLAS CWBVH testing, I think there's some testing to be done on whether building the TLAS every N frame with refitting inbetween could be a better idea in certain case. Maybe GPU refitting for both TLAS and BLAS (for skinned rendered) and is also more viable in certain case? (but would be out of the scope of this project).

Feel free to close this issue now if you want, or leave it open until we do more benchmarks.

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

No branches or pull requests

2 participants