- Home /
Backface Culling on LineRenderer
Hey folks!
I'm currently working on a project that requires LineRenderers that can be custom drawn by the user. The problem I'm facing is that when a LineRenderer makes a turn, it'll often have artifacts, as can be seen in the image below
if I try front-face culling, it shows only the artifacted areas, as seen here:
However, if I try to back-face cull, the artifacts are still visible, as can be seen on the first image.
I'm wondering if anyone would have any idea how to stop these artifacts from being visible?
Answer by Bunny83 · Apr 06, 2018 at 10:58 AM
Well, the problem is not back or front face culling as by default most shaders use backface culling. The problem is that you have "negative" faces and overlapping faces because given your linewidth and the sharp bend the linerenderer wasn't able to create a continuous triangle strip. Usually all faces will actually face the camera but your "line" is basically "folded" because the bend is too sharp. It all boils down to the algorithm Unity uses to create the mesh for the given points.
You can try adjusting the numCornerVertices and see if it gets better. However infinitly sharp corners will always give you trouble as it's not possible to have a continuous gradient without overlapping. The only alternative would be to create a custom mesh and ensure to have no overlaps. Though i've done this in the past and it's a pain to cover all edge cases. If you want to actually "draw" freely you may want to "draw" to a texture / blending mask. Though it's difficult to recommend alternatives if the actual purpose is not clear.
Thanks for the reply/! The use-case is creating maps in 2D, where the linerenderers are used as paint brushes. I've currently got a system where it will create a new linerenderer web the drawn angle is over a threshold, but it's not the most efficient. A custom mesh may be the best way to go forward.
Your answer
Follow this Question
Related Questions
How to cut a LineRenderer ? 2 Answers
having a camera render an object only if it appears after a plane 1 Answer
Semi transparent Object behind walls? 1 Answer
Creating a line between different colors? 0 Answers
Partial object culling/cutoff 2 Answers