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

Parts of slime entity model are not rendered anymore when shaders are turned on (regression from 5.4.1) #11852

Closed
erlehmann opened this issue Dec 11, 2021 · 17 comments · Fixed by minetest/irrlicht#102
Labels
Bug Issues that were confirmed to be a bug @ Client / Audiovisuals Regression Something that used to work no longer does. Shaders

Comments

@erlehmann
Copy link
Contributor

erlehmann commented Dec 11, 2021

Minetest version

Minetest commit 80d12db
Minetest commit 76aa610

OS / Hardware

Operating system: Debian GNU/Linux
CPU: Intel Core i7-8565U

GPU model: Intel UHD Graphics 620 (Whiskey Lake) rev 02
OpenGL version: 3.0 Mesa 18.3.6

Summary

Eyes, interior and backside of slime entity from Mineclonia are not rendered.

This entity model works in both 5.4.1 and on my Thinkpad T60 with OpenGL 1.4.

Steps to reproduce
  1. Spawn a slime in Mineclonia creative mode with a slime egg.
  2. Watch.
Screenshot

https://mister-muffin.de/p/xShz.jpg

@erlehmann erlehmann added the Unconfirmed bug Bug report that has not been confirmed to exist/be reproducible label Dec 11, 2021
@erlehmann
Copy link
Contributor Author

Mineclonia bug report: https://git.minetest.land/Mineclonia/Mineclonia/issues/211

@erlehmann erlehmann changed the title Large part of entity model is not rendered (this worked in 5.4.1) Parts of entity model is not rendered (regression from 5.4.1) Dec 11, 2021
@erlehmann erlehmann changed the title Parts of entity model is not rendered (regression from 5.4.1) Parts of slime entity model are not rendered anymore (regression from 5.4.1) Dec 11, 2021
@sfan5
Copy link
Member

sfan5 commented Dec 11, 2021

Do you have link to the model file and entity definition in Lua?

@sfan5
Copy link
Member

sfan5 commented Dec 12, 2021

I cannot reproduce this by assigning the model to an entity individually.

Testing in Mineclonia was not possible for me because it crashes instantly on startup with not one but two errors. This makes your claim that you reproduced this bug with "Minetest commit 76aa610" appear dubious.

@erlehmann
Copy link
Contributor Author

@sfan5 which errors does Mineclonia crash with?

@erlehmann
Copy link
Contributor Author

erlehmann commented Dec 12, 2021

@sfan5 just in case Mineclonia crashes due to #11828 then …

a) you introduced that bug – after I told you it would break stuff to not use proper boundaries for the check.

b) you can disable the mcl_selftests mod. It tests if the Minetest engine can find all nodes it has placed, by placing nodes at numerous positions and then trying to find them using minetest.find_nodes_in_area(). I still think it is ridiculous that Minetest will refuse to find nodes it has placed.

Anyways, please provide an error message instead of just writing “it crashes”.

I promise I will try to fix it so you can look at the slime.

@erlehmann
Copy link
Contributor Author

erlehmann commented Dec 12, 2021

Important new information: The bug only happens if shaders are turned on.

@erlehmann erlehmann changed the title Parts of slime entity model are not rendered anymore (regression from 5.4.1) Parts of slime entity model are not rendered anymore when shaders are turned on (regression from 5.4.1) Dec 12, 2021
@sfan5
Copy link
Member

sfan5 commented Dec 12, 2021

2021-12-12 11:28:44: ERROR[Main]: ServerError: AsyncErr: Lua: Runtime error from mod 'mcl_selftests' in callback environment_Step(): .../games/Mineclonia/mods/MISC/mcl_selftests/init.lua:85: assertion failed!
2021-12-12 11:28:44: ERROR[Main]: stack traceback:
2021-12-12 11:28:44: ERROR[Main]: 	[C]: in function 'assert'
2021-12-12 11:28:44: ERROR[Main]: 	.../games/Mineclonia/mods/MISC/mcl_selftests/init.lua:85: in function 'func'
2021-12-12 11:28:44: ERROR[Main]: 	.../minetest/builtin/common/after.lua:20: in function <.../minetest/bin/../builtin/common/after.lua:5>
2021-12-12 11:28:44: ERROR[Main]: 	.../minetest/builtin/game/register.lua:425: in function <.../minetest/bin/../builtin/game/register.lua:409>
2021-12-12 11:28:45: ACTION[Main]: Server: Shutting down
2021-12-12 11:28:45: ACTION[Main]: [doc] Server shuts down. Player data is about to be saved.
2021-12-12 11:28:45: ACTION[Main]: [doc] Wrote player data into .../minetest/bin/../worlds/world2/doc.mt.
2021-12-12 11:28:45: ERROR[Main]: ModError: Runtime error from mod 'mcl_weather' in callback on_shutdown(): .../mods/ENVIRONMENT/mcl_weather/weather_core.lua:42: bad argument #2 to 'set_int' (number expected, got nil)
2021-12-12 11:28:45: ERROR[Main]: stack traceback:
2021-12-12 11:28:45: ERROR[Main]: 	[C]: in function 'set_int'
2021-12-12 11:28:45: ERROR[Main]: 	.../mods/ENVIRONMENT/mcl_weather/weather_core.lua:42: in function <...Mineclonia/mods/ENVIRONMENT/mcl_weather/weather_core.lua:40>
2021-12-12 11:28:45: ERROR[Main]: 	.../minetest/builtin/game/register.lua:425: in function <.../minetest/bin/../builtin/game/register.lua:409>

mcl_selftests can indeed be disabled and then the game runs but I don't want to hear any excuses. Reproduction steps must actually work.

Regardless, the slime model renders and is textured perfectly fine for me.
Are you sure you tested this on commit 76aa610? I am mentioning this again because if you are testing on a version that is 5 months out of date you will be missing commits that could have already fixed it.

@erlehmann
Copy link
Contributor Author

the slime model renders and is textured perfectly fine for me

For me it does not. I also found out that it vanishes behind nodes with transparency (a different bug).

Screenshot as proof: https://mister-muffin.de/p/XAo_.png

@sfan5
Copy link
Member

sfan5 commented Dec 13, 2021

Can you answer my question?

Are you sure you tested this on commit 76aa610?

@erlehmann
Copy link
Contributor Author

erlehmann commented Dec 13, 2021

Oh sorry, yes. The screenshot https://mister-muffin.de/p/XAo_.png was taken with commit 76aa610.

I have built it completely anew to exclude any possibility of build system bugs being involved.

@sfan5
Copy link
Member

sfan5 commented Dec 13, 2021

Okay thanks.

I just remembered that I have my renderer set to ogles2 on my primary install.
Just retested on OpenGL and I couldn't reproduce it by manually spawning the model but inside Mineclonia it was indeed broken.

@sfan5 sfan5 added Bug Issues that were confirmed to be a bug and removed Unconfirmed bug Bug report that has not been confirmed to exist/be reproducible Possible close labels Dec 13, 2021
@sfan5
Copy link
Member

sfan5 commented Dec 13, 2021

I couldn't tell you why it presumably worked in 5.4.1 or with shaders disabled but this seems to be a texture coordinate-related error. If I color in these squares in the texture the eyes show up blue and the mouth red:
grafik

@paradust7
Copy link
Contributor

@sfan5

I have an explanation.

The mesh is not just a cube, it is actually 5 cubes. An outer cube, inner cube, two eyes, and an off-center mouth.
Only the outer cube has non-blank texture, the other 4 cubes map to areas with rgba = 0.

slime
slime_uv

The three fully-transparent cubes protruding from the front need to be discarded (not rendered) by the shader, or else they prevent the main cube from rendering under them (due to depth testing, presumably).

When GLES is enabled, there is an explicit discard at the beginning of the fragment shader:

// If alpha is zero, we can just discard the pixel. This fixes transparency
// on GPUs like GC7000L, where GL_ALPHA_TEST is not implemented in mesa,
// and also on GLES 2, where GL_ALPHA_TEST is missing entirely.
#ifdef USE_DISCARD
if (base.a == 0.0)
discard;
#endif

This is why GLES is unaffected. Removing this discard causes the misrendering effect on GLES.

According to the comments, it is expected that GL_ALPHA_TEST will be used to do the discard on OpenGL. That is indeed what is done for the built-in renderer for EMT_TRANSPARENT_ALPHA_CHANNEL:

https://github.com/minetest/irrlicht/blob/24594ce2265800aa88e087d4e6f2d4a54a5f2eb8/source/Irrlicht/COpenGLMaterialRenderer.h#L368-L371

However, for custom shaders based on EMT_TRANSPARENT_ALPHA_CHANNEL, the driver sets the blending function, but doesn't set an alpha test:

https://github.com/minetest/irrlicht/blob/24594ce2265800aa88e087d4e6f2d4a54a5f2eb8/source/Irrlicht/COpenGLShaderMaterialRenderer.cpp#L45

https://github.com/minetest/irrlicht/blob/24594ce2265800aa88e087d4e6f2d4a54a5f2eb8/source/Irrlicht/COpenGLShaderMaterialRenderer.cpp#L205-L206

This seems like a simple mistake. Pull request incoming soon.

@NathanSalapat
Copy link
Contributor

Why does the slime have those meshes if they are just transparent anyway? Not that the bug should be ignored or not fixed, but it seems silly to add extra geometry if it's not used. Probably not a question to ask here I suppose.

@paradust7
Copy link
Contributor

@NathanSalapat Agreed, the mesh would be better off as one cube. I figure since non-shader rendering and other drivers already have the "correct" behavior of discarding alpha=0 faces, it makes sense for the OpenGL driver to do the same.

@paradust7
Copy link
Contributor

FYI, I found this document which describes this exact issue and possible solutions.

@sfan5 sfan5 added the Regression Something that used to work no longer does. label May 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Issues that were confirmed to be a bug @ Client / Audiovisuals Regression Something that used to work no longer does. Shaders
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants