I am working on a project to generate road meshes in UE from road definition files. Every thing works fine except that the road mark mesh will get z fighting with the road mesh.
If I can control the draw order of actor, I can draw the road actors(primitive mesh component) first, and then disable z test and draw road mark actors(primitive mesh component), and restore z testing and draw other actors.
But it seems UE won’t let you control the draw order?
So I want to know if there is any suggested solution for this? Since all the mesh are generated from file, decal might not be a good solution as it needs predefined material. And for a road, the road mark could be very long.
What exactly do you mean by all meshes being generated from a file? More specifically, how is that preventing you from using a decal?
For example, the crosswalk shape is defined by a vector of corner point, so I will generate the white line meshes inside this defined polygon.
However decal is a box, right?
Z-fighting is part of the way 3D graphics work. There are several ways to go around ti:
- Move your road mark actors a tiny bit (0.01) above the road. This is the easiest and most common solution.
- Draw the materials in different buffers and combine them. This approach is very error prone and expensive (memory-wise). You would have to create 3 buffers (below markings, markings and above markings). From this point on, what ever you do you will not be able to change that order. If you need your car to hide behind an object from the “below markings” buffer you won’t be able to.
- Project the markings on the road textures and bake it. This means that you would have to create a unique texture for every patch of road during loading. This will slow down your loading considerably and use a bunch of texture memory.
- Manually create road patch textures with different marking masks and combine the parts of the road accordingly in your generator. This is the safest way but it takes a lot of manual work and reworking the generator.
I would strongly suggest you go with solution 1.
Decals take up a box area, yes, but they are ultimately defined by a material.
When the whole process is program generated, I can only have some fixed material