BramStoutProductions / MiEx

A modern Minecraft Exporter
BSD 3-Clause "New" or "Revised" License
60 stars 9 forks source link

Z-Fighting #59

Closed Fyoncle closed 4 months ago

Fyoncle commented 6 months ago

image

image

When 2 transparent faces get inside of each other in any block with alpha, that weird black glitches happy only in "viewport" but fixes when rendering mode, any fix or not? Since alpha blend with show backface option also fixes that in viewport.

BramStout commented 6 months ago

Every face has a front side and a back side. If a mesh is "double sided" then both the front side and the back side is shown. If a mesh is "single sided" then only the front side is shown and the back side is not. Not showing the back side (so single sided meshes) is also called "backface culling".

Minecraft by default renders blocks as single sided meshes (so with backface culling). MiEx does this as well. When you then want to show a face that's double sided, the model will actually have two faces right on top of each other facing opposite directions. Because the models are rendered out as single sided meshes in Minecraft, this all works. But, if you take these meshes into Blender and it renders them out as double sided, then you'll back those black glitch-y areas. This is the back side of the other face.

MiEx does write out into the USD file that these meshes are single sided, and that's why when rendering doesn't show this glitch-y behaviour, since it will render the meshes out as single sided. It looks like the viewport just ignores whether a mesh is double or single sided and always render them out as double sided, unless you turn the show backface option off. Then it will render them out as single sided.

The most important part is that it renders out correctly in rendering mode. For the viewport, you could then turn off the show backface option.

MiEx does have an option in miex_config.json called doubleSided which is where you can give it block names that should be exported out as double sided meshes. In that case if there are two single sided faces that are directly on top of each other, it will just put in a single face that's double sided. That way you don't get the black glitch-y area, but it could mean that the back side has its texture flipped. In some cases that's also there in the original model and so nothing changes, but in others it does technically change (but sometimes it's fine and no-one will notice)

Fyoncle commented 6 months ago

Every face has a front side and a back side. If a mesh is "double sided" then both the front side and the back side is shown. If a mesh is "single sided" then only the front side is shown and the back side is not. Not showing the back side (so single sided meshes) is also called "backface culling".

Minecraft by default renders blocks as single sided meshes (so with backface culling). MiEx does this as well. When you then want to show a face that's double sided, the model will actually have two faces right on top of each other facing opposite directions. Because the models are rendered out as single sided meshes in Minecraft, this all works. But, if you take these meshes into Blender and it renders them out as double sided, then you'll back those black glitch-y areas. This is the back side of the other face.

MiEx does write out into the USD file that these meshes are single sided, and that's why when rendering doesn't show this glitch-y behaviour, since it will render the meshes out as single sided. It looks like the viewport just ignores whether a mesh is double or single sided and always render them out as double sided, unless you turn the show backface option off. Then it will render them out as single sided.

The most important part is that it renders out correctly in rendering mode. For the viewport, you could then turn off the show backface option.

MiEx does have an option in miex_config.json called doubleSided which is where you can give it block names that should be exported out as double sided meshes. In that case if there are two single sided faces that are directly on top of each other, it will just put in a single face that's double sided. That way you don't get the black glitch-y area, but it could mean that the back side has its texture flipped. In some cases that's also there in the original model and so nothing changes, but in others it does technically change (but sometimes it's fine and no-one will notice)

This thing is ruins every single emission or texture edit i add, there should be solution for that :(

BramStout commented 6 months ago

Every face has a front side and a back side. If a mesh is "double sided" then both the front side and the back side is shown. If a mesh is "single sided" then only the front side is shown and the back side is not. Not showing the back side (so single sided meshes) is also called "backface culling". Minecraft by default renders blocks as single sided meshes (so with backface culling). MiEx does this as well. When you then want to show a face that's double sided, the model will actually have two faces right on top of each other facing opposite directions. Because the models are rendered out as single sided meshes in Minecraft, this all works. But, if you take these meshes into Blender and it renders them out as double sided, then you'll back those black glitch-y areas. This is the back side of the other face. MiEx does write out into the USD file that these meshes are single sided, and that's why when rendering doesn't show this glitch-y behaviour, since it will render the meshes out as single sided. It looks like the viewport just ignores whether a mesh is double or single sided and always render them out as double sided, unless you turn the show backface option off. Then it will render them out as single sided. The most important part is that it renders out correctly in rendering mode. For the viewport, you could then turn off the show backface option. MiEx does have an option in miex_config.json called doubleSided which is where you can give it block names that should be exported out as double sided meshes. In that case if there are two single sided faces that are directly on top of each other, it will just put in a single face that's double sided. That way you don't get the black glitch-y area, but it could mean that the back side has its texture flipped. In some cases that's also there in the original model and so nothing changes, but in others it does technically change (but sometimes it's fine and no-one will notice)

This thing is ruins every single emission or texture edit i add, there should be solution for that :(

Is this something that only happens in the viewport, but when you do a render it doesn't happen, or does it also happen when rendering?

Fyoncle commented 6 months ago

Every face has a front side and a back side. If a mesh is "double sided" then both the front side and the back side is shown. If a mesh is "single sided" then only the front side is shown and the back side is not. Not showing the back side (so single sided meshes) is also called "backface culling". Minecraft by default renders blocks as single sided meshes (so with backface culling). MiEx does this as well. When you then want to show a face that's double sided, the model will actually have two faces right on top of each other facing opposite directions. Because the models are rendered out as single sided meshes in Minecraft, this all works. But, if you take these meshes into Blender and it renders them out as double sided, then you'll back those black glitch-y areas. This is the back side of the other face. MiEx does write out into the USD file that these meshes are single sided, and that's why when rendering doesn't show this glitch-y behaviour, since it will render the meshes out as single sided. It looks like the viewport just ignores whether a mesh is double or single sided and always render them out as double sided, unless you turn the show backface option off. Then it will render them out as single sided. The most important part is that it renders out correctly in rendering mode. For the viewport, you could then turn off the show backface option. MiEx does have an option in miex_config.json called doubleSided which is where you can give it block names that should be exported out as double sided meshes. In that case if there are two single sided faces that are directly on top of each other, it will just put in a single face that's double sided. That way you don't get the black glitch-y area, but it could mean that the back side has its texture flipped. In some cases that's also there in the original model and so nothing changes, but in others it does technically change (but sometimes it's fine and no-one will notice)

This thing is ruins every single emission or texture edit i add, there should be solution for that :(

Is this something that only happens in the viewport, but when you do a render it doesn't happen, or does it also happen when rendering?

It also happens when you render it, the topology is going crazy, no matter what blending mode, no matter if u merge it by distance, no matter WHATEVER you do, the meshes are insanely messed up, mineways is not like that, idk why MiEx does that, may be because of the optimiser but i didnt try.

BramStout commented 6 months ago

Every face has a front side and a back side. If a mesh is "double sided" then both the front side and the back side is shown. If a mesh is "single sided" then only the front side is shown and the back side is not. Not showing the back side (so single sided meshes) is also called "backface culling". Minecraft by default renders blocks as single sided meshes (so with backface culling). MiEx does this as well. When you then want to show a face that's double sided, the model will actually have two faces right on top of each other facing opposite directions. Because the models are rendered out as single sided meshes in Minecraft, this all works. But, if you take these meshes into Blender and it renders them out as double sided, then you'll back those black glitch-y areas. This is the back side of the other face. MiEx does write out into the USD file that these meshes are single sided, and that's why when rendering doesn't show this glitch-y behaviour, since it will render the meshes out as single sided. It looks like the viewport just ignores whether a mesh is double or single sided and always render them out as double sided, unless you turn the show backface option off. Then it will render them out as single sided. The most important part is that it renders out correctly in rendering mode. For the viewport, you could then turn off the show backface option. MiEx does have an option in miex_config.json called doubleSided which is where you can give it block names that should be exported out as double sided meshes. In that case if there are two single sided faces that are directly on top of each other, it will just put in a single face that's double sided. That way you don't get the black glitch-y area, but it could mean that the back side has its texture flipped. In some cases that's also there in the original model and so nothing changes, but in others it does technically change (but sometimes it's fine and no-one will notice)

This thing is ruins every single emission or texture edit i add, there should be solution for that :(

Is this something that only happens in the viewport, but when you do a render it doesn't happen, or does it also happen when rendering?

It also happens when you render it, the topology is going crazy, no matter what blending mode, no matter if u merge it by distance, no matter WHATEVER you do, the meshes are insanely messed up, mineways is not like that, idk why MiEx does that, may be because of the optimiser but i didnt try.

Could you try for each object where it's doing this, that you go to its material and in the material turn on the "Backface Culling" option? It should be a checkbox in the material's settings.

Minecraft uses Backface culling, and the block models are created with this in mind. And since MiEx uses Minecraft's block models, the meshes that MiEx creates are by default meant to have backface culling turned on (in other apps it would be "double sided" turned off). MiEx does try to tell Blender to turn backface culling on, but Blender just ignores that.

In theory, turning backface culling on should fix this. If it does, then we can look into updating the addon to automatically do that

BramStout commented 4 months ago

MiEx now has a new Blender addon that fixes this issue. The new Blender addon will turn on Backface culling for all materials and the example Blender resource pack also informs MiEx of this so that MiEx will export out the meshes accordingly.

You can read more about the new Blender addon here: https://github.com/BramStoutProductions/MiEx/wiki/8.-Importing-into-DCCs#blender