fenomas / noa

Experimental voxel game engine.
MIT License
611 stars 87 forks source link

How to do LODs? #120

Closed Jarred-Sumner closed 3 years ago

Jarred-Sumner commented 4 years ago

Do you have any sense for how hard it'd be to build this?

https://0fps.net/2018/03/03/a-level-of-detail-method-for-blocky-voxels/

I naively tried just running mesh.simplify but it seems to do nothing. Maybe I didn't configure the settings correctly though.

I might take a stab at it. I really want the game to work well on computers with without dedicated graphics cards and I suspect this is one of the things preventing that. But I'm really bad at algorithms & math stuff so I'm worried about how long it'd take me to build this.

There is a pop-buffers npm package and a couple ThreeJS demos of using them

The code he shows in the page looks simple enough, but I'm not really sure how to wire it up from the cells thing he describes to the way Babylon.js does it. cells seems related to simplicial-complex

My guess is:

fenomas commented 4 years ago

Hi, so I've seen that article but I haven't considered it deeply. On the one hand it looks very nontrivial to implement - it would mean significantly changing the meshing code (I don't really follow all the details yet), and also require changing to a custom shader.

But on the other hand, I'm not that confident it would significantly improve performance. My sense is that the limiting factor on the size of most noa worlds is the speed of terrain meshing, or the number of draw calls. Having LOD would decrease the total number of polys being drawn in a large world, but it wouldn't affect draw calls and one would expect that it would slow down terrain meshing, if anything. I may well be missing something important though...

Jarred-Sumner commented 4 years ago

I think you're right – it would make meshing slower, and that's worse than the need for LODs. The bigger perf problem for me right now is (which is not related to noa) is rendering lots of small 3D models is slow, so I'm not working on LODs right now

I was considering rewriting the meshing stuff in Rust using WASM, based on this: https://github.com/Technici4n/voxel-rs/blob/master/client/src/render/world/meshing.rs#L67

But only slightly considering it. Theoretically, could use WASM threads and then with SharedArrayBuffer, could run meshing in a separate thread entirely. And probably would be faster in Rust than JavaScript, however it might not be (If you try https://wasmboy.app/benchmark/, their AssemblyScript WASM code isn't consistently faster than the JavaScript code). WASM threads & SharedArrayBuffer are also only supported in Chrome, which is problematic unless you had a single separate & dedicated meshing worker. Might not be a big deal to copy over one of the UInt16Array's often

MaxGraey commented 4 years ago

https://wasmboy.app/benchmark and n-body benchmark is really can't significant outperform JavaScript. But intensive computation algorithms with float point math or int64 could behave better: https://github.com/nischayv/as-benchmarks https://github.com/playcanvas/engine/pull/2213 https://www.reddit.com/r/WebAssembly/comments/hrp6pt/i_created_a_proofofwork_captcha_using

fenomas commented 4 years ago

Thanks for the background @MaxGraey. To be clear here meshing doesn't really have any math, it's basically a lot of array reads and writes (into Uint16 arrays) and twiddling of array indexes. Naively I wouldn't expect it to be the sort of thing WASM would help with very much, but I could certainly be wrong.

fenomas commented 3 years ago

Closing this as no obvious way forward, but please reopen if people have specific suggestions.