Question: Building modular building assets for player usage, but how do I deal with z-fighting?

So i’ve been scouring the internet trying to find any resources on a particular use case for modular pieces. So far I have found talks with lee and other bethesda developers for tackling modular building kits, but for my particular situation, it does not work, but works in a pre-design scenario. The particular use case is for a survival/buildcraft environment, where the player can put down foundation pieces that have 6 sides on XYZ axis and have polygons on all those axis points as well. So you put say a cube next to a cube, how would you handle the inside faces overlapping?

I have been working in 3d to block out ideas on tackling this, but have an issue right out of the box with overlapping faces in the block out period.

I guess im asking is how do studios like funcom or those who made ARK approached overlapping faces and z-fighting with geometry that is pushed up against each other for modular base building for players?

At first I thought it was a replacing of the asset where you build versions of the asset per side and create a sort of “smart tile” approach where if you put 2 foundations together, the inside faces change to nothing there and attach at the top and bottom to line up with vertices, but when I went digging in their mod kits, I did not find any type of example for that.

Maybe im not asking the internet the right questions, so I figured I would post it here to maybe find one of the many unreal wizards out there who might of seen this particular issue and how we would go about tackling it. Any links or documentation, videos, etc. on handling this would be awesome.

Thanks again all, cheers.

1 Like

Hey there @JackieHex! Welcome to the community! So it’s somewhat dependent on how your game works, but some common ways I see building systems handle this is:

  • Checking if adjacent to the same type of object and changing to a connective mesh
  • Checking if adjacent to a block that occludes that side and just not rendering internals (Minecraft)
  • Have each piece offset in a way in which they clip inside of the other object but not 100% flush (Valheim).

Are all of your meshes blocks?

It partially depends on how complex you want your geometry to be. For lower poly stylized stuff, simple layouts I described here work.

As poly counts go up, it can be a bit trickier, but the same basic concept is still good. In Conan Exiles, some of the more irregular models have bricks and such that jut past the tile line and interlock with adjacent pieces kinda like the second pic in linked topic. Some of the smoother building types though are basically just a box with some detail on the front and back.

While stuff can be placed freely in CE, the walls/floor have snap sockets that essentially form a 256x256x256 grid. This means floors end at the midline of a wall, but there’s “foundation walls” one can stick on the outside to pretty it up.

From the outside, there’s no z-fighting because everything is snapped end-to-end, and has tapered or interlocking bits where needed. If you were to /ghost inside a building, you’d see all the missing faces, but that’s generally not supposed to happen.

That was actually really helpful and I did not even consider just offsetting edges a bit so overlap does not happen. I have your example opened up and will use it as a template reference point.

So ill just be basically making sure the side pieces interlock correctly and a little eye trickery so it all looks good regardless.

Thank you so much for the help and the quick replies. Ill definitely be lurking around the boards and adding some of my insight and tips as well to other threads to pay this forward.

I think i was just stuck on the mirroring aspect and stuck in the idea that just because its on a grid system and things need to “match” up, it does not mean things do not have to be symmetrical across the board, and with this knowledge, its going to be a bit easier to get away with interlocking walls without overlap.

z-fighting drives me nuts, so I’m glad i can knock that issue off my list.

Cheers!

The main thing to keep in mind is having some sort of rotational symmetry.

In one set of walls I did for a Conan mod, the blocks on the sides interlock like a zipper when side by side and facing the same direction, but look wonky if mismatched.

The top row of bricks ends at ±128x and the others are the zipper teeth. the trick there is keeping the offset small enough to not poke through perpendicular walls at a T junction.

When they meet at a corner, the “teeth” stack up like a log cabin.

For another mod with Egyptian-ish clay buildings, the walls look like this from above:

With only one side poklng out, they really only go one-way when making corners. When stuck together as a straight wall, it looks like a single flat mesh, as I edited the normals so the seams are flat. Fortnite uses a similar trick on their modern, beveled buildings.

In both cases, the center line of walls snap to the edge of a 256x256 floor piece.

All that said, this isn’t the only way to do it. Bethesda, for instance, usually lined up the outer edges of walls with the edge of floors in Fallout 4 and 76. To control z-fighting, their walls are just an extra half a unit thick. This method works well enough, but can get a bit wonky when building L shaped buildings and interior walls.

2 Likes

that is actually useful to know as well. I especially like the simple approach with the round corner to the square side where the overlap does not set any of the faces touching as well.

Thanks again for the info and the follow up. im going to take a lot of this into account for what im working on. cheers

1 Like