unity3d – How do I efficiently render a pixelated line?

I am working in Unity2D and have a character who can shoot in all directions. The game has mobile controls and the player will choose his shooting direction with a joystick on the right side.

After testing I found it rather difficult to correctly determin where the shot is going to land at. To convey this to the player I wanted to add a sort of “shooting line of sight” to the player. It is moving around the player according to the joysticks position. (As seen in the picture)

enter image description here

Because I want the line to be pixelated (to match the design theme of the game) I cant use the standard LineRenderer component as it doesn’t support such pixelated lines. So I started looking for solutions to this problem and stumbled upon Bresenham’s line algorithm. After implementing it into the game I knew which x, y coordinates I had to fill with a pixel. Currently every single white pixel in this line is a GameObject with its own SpriteRenderer and a single white pixel as a sprite. In my test scenario up to 400 pixels where rendered at once. I am already using an object pooling system to minimize the performance drag. Moving this line around drops me from around 1100 Fps down to like 200 Fps in the editor. I know it will be slightly better in the build game but I am sure it will take a toll on older mobile devices when enemys, animations etc. are present in the level.

So my question is: Is there a better or more efficient way to render the sprites? Or (preferably) do you have a better idea on how to render this line at all without creating ~300+ GameObjects. (e.g. Shaders (Zero experience), drawing on a texture)

I am grateful for any ideas that lead me into the right direction.

Source link