-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Translucency sort idea #5083
Comments
I forgot: this would sort nodes properly, but not translucent entities, particles and clouds. Translucent mesh nodes would also work, but only if their translucent part is convex (like flowing liquids). |
❤️ Kudos for putting some thoughtwork into fixing depth sorting. This is one of the oldest bugs in Minetest, namely #95. This would finally allow mods to have translucent nodes which don't look like shit (and broken). |
Interesting. |
Some kind of fix is needed for sure, minetest is full of rendering problems because of lack of sorting :( |
Somewhere in IRC dev channel logs hmmmm details how he was planning to add depth-sorting, something to do with materials, worth searching for. |
Yeah that's a later discussion, he goes into more detail before that. |
More than half the corner meshes for many mapblocks will probably never be used. I think corner meshes should only be generated and cached on demand. Perhaps corner meshes don't even need to be cached since as the player passes by the mapblock, 14 intervening meshes are being regenerated as the player moves assuming the player moves in a straight line. Leaving another one in shouldn't make performance much worse and should save some memory. Leaving us with only one mesh for each mapblock. A player perspective of a mapblock normally cannot switch corners without going through a bunch of passing by that mapblock in some way anyway. |
Pasting this from IRC http://irc.minetest.ru/minetest-dev/2017-10-31#i_5124931, this tool will be useful for someone who wants benchmark of their concepts of alpha sorting:
|
@juhdanad I have another suggestion: render translucent objects in 2 passes. In the first pass fill z-buffer but not color buffer; in the second pass use color buffer. This way, only the nearest translucent face will be seen; that’s not exactly correct but consistent at least, and annoying visual glitches will go away. |
Just my curiosity. Can you build small underwater glass tunnel/cube/whatever moderately deep and look through glass into the sea to see if that water on the surface still blinks like crazy? |
MTG glass does not use alpha transparency, though. You'll have to make a custom solid node with alpha to really test. There's also still the issue that anything with alpha would be invisible when looked through an alpha node, including particles (so you cannot see snow/rain particles through a node with alpha, like in #3761). |
Another approach: render everything always. The code (reasonably fast albeit a bit buggy, for aforementioned reason and the fact that some objects are marked translucent despite they shouldn’t be): //src/client/render/core.cpp:73
void RenderingCore::draw3D()
{
video::SOverrideMaterial &mat = driver->getOverrideMaterial();
mat.Material.ZWriteEnable = false;
mat.EnableFlags = video::EMF_ZWRITE_ENABLE;
mat.EnablePasses = scene::ESNRP_TRANSPARENT | scene::ESNRP_TRANSPARENT_EFFECT;
smgr->drawAll();
mat.EnableFlags = 0;
mat.EnablePasses = 0;
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
if (!show_hud)
return;
hud->drawSelectionMesh();
if (draw_wield_tool)
camera->drawWieldedTool();
} |
@Fixer-007 Thanks for testing.
|
Shaders also add some performance penalty |
Depends. |
@numberZero any more ideas? This is one of the most annoying and unfixed aspects of minetest. |
Weird, do you have waving water enabled? |
@paramat Yes, waving was enabled. The stone texture is an actual stone node, so that part isn't a bug. And here is the difference depending on y coord of the node (no waving): Same again but with waving: Porthole nodes are here: https://github.com/Ezhh/abriglass/blob/master/nodes.lua#L101 |
The water tiles are wrongly visible and z-fight with the nodebox faces, i guess because we assume nodeboxes do not have faces that are positioned like cube faces. We would need to analyse each face of the nodebox to see whether the water tile needs rendering, seems non-trivial. Even then a stair or slab node has part up against the cube and part not, so whether we render that water face or not it would be wrong. Waving water has big problems, it was about to be removed by RBA due to being so buggy, not surprised it doesn't work here. Why does this node have to be a nodebox if it's a cube? Just wondering. |
It's a nodebox because glasslike drawtype doesn't allow different textures per face. (Unless that changed since I last checked.) |
And I could understand the water just staying visible on the outside, but the flickering is a real issue, and the repeated water surface inside the nodebox is just odd. |
Ok, maybe it doesn't have to be glasslike drawtype? (maybe it does, just guessing). |
I couldn't find a way to do these nodes without using nodeboxes (Same issue with one-way windows). This would easily be fixed by allowing a different texture per side for glasslike, but... that's unrelated to what this thread is about, and I don't want to remove the focus from something that is more important. |
Yes i got interested and experimented, best result was glasslike but you have to then surround the node with other nodes to not see the extra portholes. I opened an issue for using 6 textures. |
Another solution to the transparency problem is using order independent transparency renderers. One such is WBOIT. From a technical standpoint fairly simple to implement: http://casual-effects.blogspot.com/2014/03/weighted-blended-order-independent.html It required a lot of tweaking for me to get it blend decently well with clouds + blocks + particles, but sure appreciate being able to offload most of the transparency work to the gpu |
Hmm, I had a similar idea. But as I wrote, it requires MRT and post-processing and all that stuff that is poorly supported. |
Ow, yea, rendering to an off-screen buffer would be necessary. I didn't see that part. |
Possible close? The issue is #95, this one was for discussion of a particular solution that didn't get much support IIUC. |
In this issue I would like to introduce a method to make translucent nodes sorted properly. Since there are advantages and drawbacks, I hope there will be suggestions to improve the method, and also I would like to know if this feature is needed.
Rendering a map block when we are looking at it from one of its corners (the nearest point of the block to the camera is the block's corner) is always can be done with one fixed order:
There are 8 corners, so this would require eight translucent meshes from a map block.
In the general case we have to split the map block to two (the nearest point is on the edge), four (the nearest point is on a side) or eight (the nearest point is in the block) sub-blocks. You can see the second case there, with the appropriate rendering order of the sub-blocks:
To achieve this, we have to render the map block multiple times, with different translucent meshes, while using user-defined clip planes (red on the image) (see also SViewFrustum::planes).
To sum up, the steps are:
On mesh creation: create eight translucent mesh buffers per block (if there are translucent nodes at all)
On render:
This method is efficient if there are a lot of translucent nodes, since you don't have to sort all rendered faces every frame, just rendered map blocks.
Memory usage is increased because there are more meshes per block. However, a mesh will only hold half as much geometry, as we know the viewing direction and can do the backface culling ourselves. Also, only translucent nodes will require more memory.
Minetest will have to process more vertices because some blocks are rendered multiple times. However, many blocks don't have to be split (increasing the viewing range increases the ratio of such blocks) and only one block requires eight renders. Also note that rendering multiple times does not necessarily slow down the game in a noticeable way because these extra vertices will be filtered out by the clipping planes and do not get to the rasterization phase.
And finally, Minetest does not use texture arrays or texture atlases. This means that each material will have to go in a separate draw call. If translucency sort is implemented, material switches will be inevitably more frequent. In my opinion this will be the most expensive part of translucency sort, not with just this implementation.
The text was updated successfully, but these errors were encountered: