Faster nodebox rendering

For people working on the C++ code.
Post Reply
erlehmann
Member
Posts: 48
Joined: Mon Jan 31, 2022 00:41
GitHub: erlehmann
IRC: erlehmann

Faster nodebox rendering

by erlehmann » Post

I have tried to render Minetest nodes like lego-like bricks, by making common Mineclonia nodes like stone render as fixed nodeboxes and putting little studs on them. By default, this leads to an extreme FPS drop, because nodeboxes are not culled when occluded – i.e. all their faces are still rendered. You can see this in wireframe debug mode.

With a very simple (quite a bit too simple) patch I can demonstrate that not rendering nodeboxes is easily achievable: By not rendering nodeboxes that have nodes on each of their faces, the rendering speeds up noticeably.
Attachments
mineclonia-lego-nodebox-rendering-patch.jpg
mineclonia-lego-nodebox-rendering-patch.jpg (47.21 KiB) Viewed 417 times
mineclonia-lego-nodebox-node-definition.jpg
mineclonia-lego-nodebox-node-definition.jpg (33.15 KiB) Viewed 417 times
cdb_b9da8bbc6338

erlehmann
Member
Posts: 48
Joined: Mon Jan 31, 2022 00:41
GitHub: erlehmann
IRC: erlehmann

Re: Faster nodebox rendering

by erlehmann » Post

sfan5 posted two related issues in the #minetest IRC channel:

https://github.com/minetest/minetest/issues/6409 Efficient ways to render layered nodes like default:snow (discuss)
[…] snow in Minetest Game (default:snow) renders slowly which was stated as a reason to not use it so much in mapgen v6.

A quick look in wireframe mode or just viewing the nodes from below with noclip mode reveals why: There are 6 faces per snow node, neighboring snow is not combined to a single face at all, like normal full-cube nodes are. The same applies to slabs, too. The bad thing is that all 6 faces appear to be rendered for each single node, even those you can't see. No wonder why paramat was opposed to add tons of snow to v6. :D
https://github.com/minetest/minetest/issues/9126 Mesher should discard triangles more aggressively
The mesher only ever attempts to optimize plain, solid nodes.
This can lead to pathological situations where more than half of a mapblock's geometry is never actually drawn.
Avoiding rendering single faces of nodes can avoid even more rendering work than just not rendering entire nodes.
Attachments
minetest-issue-9126-wireframe.jpg
minetest-issue-9126-wireframe.jpg (93.24 KiB) Viewed 414 times
cdb_b9da8bbc6338

erlehmann
Member
Posts: 48
Joined: Mon Jan 31, 2022 00:41
GitHub: erlehmann
IRC: erlehmann

Re: Faster nodebox rendering

by erlehmann » Post

Likely inspired by the above, x2048 started optimizing nodebox rendering: https://github.com/x2048/minetest/tree/nodeboxes

So far (2022-05-03) there exist only two commits on this branch:

https://github.com/x2048/minetest/commi ... ebe098ab11 Add infrastructure to optimize nodeboxes
https://github.com/x2048/minetest/commi ... 89e5b60919 Limit culling to faces that touch the node boundary

The underlying idea is to not render the faces touching solid nodes or other nodeboxes.
You can see in the screenshot below that the bottom face of the snow is not rendered.
Attachments
minetest-snow-bottom-side-not-rendered.jpg
minetest-snow-bottom-side-not-rendered.jpg (9.04 KiB) Viewed 411 times
cdb_b9da8bbc6338

erlehmann
Member
Posts: 48
Joined: Mon Jan 31, 2022 00:41
GitHub: erlehmann
IRC: erlehmann

Re: Faster nodebox rendering

by erlehmann » Post

The snow optimizations of x2048 got merged; adjacent faces of snow nodes are no longer rendered.

https://github.com/minetest/minetest/pull/12262 Avoid rendering invisible faces of simple nodeboxes

sfan5 noted during the review that this must only happen for opaque nodes, as otherwise glass looks different.
cdb_b9da8bbc6338

User avatar
runs
Member
Posts: 2785
Joined: Sat Oct 27, 2018 08:32
GitHub: runsy

Re: Faster nodebox rendering

by runs » Post

This is cool, Minetets speedup
⛏️ KeKo Site | 👕 ShopZ | ☕ Ko-fi

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests