shaoruu / mine.js

:mount_fuji: A voxel world built with JS/TS/RS. (formerly mc.js) (maybe mine.ts? or even mine.rs?)
https://github.com/voxelize/voxelize
MIT License
308 stars 32 forks source link

Some suggestions #32

Closed Alchemist0823 closed 3 years ago

Alchemist0823 commented 3 years ago

I briefly went through your code. and did a profiling on the webpage. Your work is amazing. Just some suggestions here.

  1. Rendering every transparent material in a mesh for each chunk is a bottleneck for the rendering right now. If you can make transparent blocks in single mesh with an atlas, it will definitely improve the performance a lot.

  2. I saw you disabled frustum culling on client side. It's fairly easy to calculate a bounding box for each chunk and add back the frustum culling. It will improves reduce rendering cost by 60% based on fov.

shaoruu commented 3 years ago

Hi, thanks for the suggestions!

I'm not quite sure what you meant by making transparent blocks in a single mesh with an atlas. So far, each chunk is separated into 4 sub-chunks, and each sub-chunk has two meshes, one transparent and one opaque. They're both using the same atlas generated from the backend at textures/atlas.png. What do you mean by making transparent blocks in a single mesh? Do you mean to group all transparent blocks into one mesh in chunks instead of separating them into subchunks along with opaque meshes?

In terms of frustum culling, I'll definitely put some work on it. I disabled the default frustum culling because chunk's mesh bounds were erroneous and would often disappear from the scene. A 60% reduction in rendering cost definitely sounds fantastic!

shaoruu commented 3 years ago

Done:

Here I calculate the sub-mesh's bounding box. Here I check if it's captured within the frustum.

Thank you for your suggestion!

Alchemist0823 commented 3 years ago

I'm not quite sure what you meant by making transparent blocks in a single mesh with an atlas. So far, each chunk is separated into 4 sub-chunks, and each sub-chunk has two meshes, one transparent and one opaque. They're both using the same atlas generated from the backend at textures/atlas.png. What do you mean by making transparent blocks in a single mesh? Do you mean to group all transparent blocks into one mesh in chunks instead of separating them into subchunks along with opaque meshes?

If that's the case, I was wrong. I will look more into the performance optimization.

shaoruu commented 3 years ago

That would be great! Thank you~