LineRenderer vertex bug

Hey, i’m facing some linerenderer mesh problems when i try to use the alphaKeys with values less than 1. Is there some way to resolve it?

I tryied to bake the line and then optmize it but didn’t work.

I’m currently using the default line shader.

*Note: I’m making a game where the player can draw something on the screen, that’s why the line have a lot of points

Not really a bug per se. This is expected behavior for overlapping transparent geometry. And line renderers like this will always end up creating overlapping geometry just due to them being general case 3D geometry strips. They’re not attempting to generate clean geometry based on the extents of the outline. That’s expensive, and nearly impossible to calculate for the 3D use case, so they don’t.

There are three ways to fix this.

  1. Generate clean geometry yourself in script based on the exterior edge of the drawn line. I don’t recommend this. It’s difficult and expensive. Search for “2D CSG” if you want to make your head hurt.

  2. Use a custom shader that culls back faces (which will improve the above slightly) and stencils to prevent overdraw. The hard part of this is each line will need it’s own stencil ref, so you’ll be limited to 255 lines unless you’re baking them down to a render texture after being drawn. It also only works if you’re using a constant alpha value, and the geometry or alpha testing for the edges. If you use an variable opacity over the line or an alpha texture this will fail.

  3. Render each line, fully opaque, to a render texture, then composite the render texture into the scene. Takes a bit more work, but can support an infinite number of lines, and variable alpha. It also has a higher rendering cost per line than option 2.

1 Like

Thanks for the solutions! I will try to edit de default-line shader in order to culls back faces and prevent overdraw. If i sucess, I’ll post the solution here.