Add support for pixelated LineRenderer, 2D Lights/shadows and ParticleEffects

I’m working on a 2D Pixelart platformer game and it’s become a real pain to do this in Unity.

At first I was using the PixelPerfectCamera and let it upscale the render texture so that the whole scene is renderered to a rendertexture the size of my resolution(480x270) which then is scaled back to full screen, this looks real great because everything in your scene will be ‘pixelated’ because it’s actually rendered at a smaller resolution. But the big downside to this all is that all movement(player, camera, moving objects) looks real jenky especially with faster movement. I’ve managed to get it somewhat smoother but in the end it still looks bad.

So then I asked myself, do I really need all the pixelart lined up on a pixel grid? And the answer is no, noone will notice that the pixel don’t all line up every frame. So I disabled the ‘upscale rendertexture’. Now the movement looks great but the big downside is that my linerenderers, 2D Lights and ParticleEffects now are no longer pixelated.

For normal sprites I ended up creating a shader which pixelates a sprite according to my PPU so I can rotate them without having to create a spritesheet for the whole rotation. Only downside to this is that the sprites I want to rotate this way cannot be in an atlas because then you see parts of neighbouring sprites in the atlas.

For 2D lights I thought I could just make a custom render pass which applies my pixelate shader after the 2D lighting pass. But it’s impossible to inject a pass for 2D, I found out that I can only inject a pass before everything is rendered, or after everything is rendered. So that won’t work either.

For the LineRenderer I haven’t found anything, for lines that are either vertical or horizontal I can make them look great, but as soon as you go diagonal it looks awefull. There is someone who created a pixelated linerenderer library for Unity but that only works for solid colors and you can’t use materials so that’s usable for some lines but not for all.

I’ve read enough forum posts on here and other sites to know that there are a lot of people running into these problems. Can you please put these things on the roadmap so that creating pixelart games becomes easier?

So a way to pixelate the LineRenderer, 2D Lights and Shadows and Particle Effects.

I understand that it won’t be fixed right away, but at least put it on the roadmap so it will be in eventually.

1 Like

+1 for the lines

look how far you have to go to make pixel art lines

1 Like

Noone from the devteam who wants to weigh in?

The workaround I’m using for this now is as follows:

  • Create a physics layer for everything you want to be pixelated
  • Add a new camera which is a child of your main camera
  • Set the culling mask of the new camera to ONLY the new layer
  • Make sure to remove that layer from the culling mask of your main camera
  • Disable post processing on the new camera
  • Create a rendertexture the size of your pixelated resolution, in my case 480x270 pixels
  • Set the render target for the new camera to this rendertexture
  • Make sure to set the background type of the new camera to solid color and make sure the color is black and the alpha chanel is 0, don’t know if this is required but it works for me.
  • Then add a UI->Raw image to the scene, a parenting Canvas will also be created
  • In the canvas, set the Render Mode to Screen Space Camera
  • In the canvas, set your main camera as the render camera
  • Add a new sorting layer for just the pixelated stuff
  • In the canvas, set the sorting layer to this new layer
  • In the Raw Image, set the rendertexture you created as the texture of the raw image
  • Create a new shader graph which only has a _MainTex texture, set this to your created rendertexture, and connect the color and alpha chanels to the output. Then in the Graph Settings set the Blending Mode to Premultiply.
  • Now use this new Shader as the material of the raw image.
  • Make sure to set the physics layer of the linerenderer, particle effect or anything you want to be pixelated to the new layer you created.

It’s a hell of a workaround, and it’s not super flexible, but for linerenderers and particle effects it works good enough for me.

For 2D Lights I have no solution though.

The final result:

https://www.youtube.com/watch?v=XeqM4hbwnyc

The two linerenderers on either side are pixelated using the method described above, so are the two particle system smoke plumes. The middle linerenderer is the original unpixelized version. The compression on Youtube does make it look less impressive though:-)

It is in no way perfect, but it will have to do for now as there is no way to do this in Unity otherwise.

I just wanted something clean, I wanted to sort pixel art lines with sprite renderers, make the line affected by 2d lights, so i could do ropes for example

we also need sprite masks with alpha, but I dont think these things will ever be added

1 Like

Yeah I wanted a clean solution too, and it seems to me that it would be relatively simple to implement too. But I’ve been struggling for some time with this and this is the best I could do. I was too far into development to switch to another engine or to write my own so this will have to do for me.

I did manage to find a solution for particle systems too though, so the solution posted above I only use for lines now. For the particles I used my own shader that pixelates sprites, and by using Custom Vertex Streams to send information about the size/rotation of the particles to my shader.