Pixel perfect camera in Unity. The LowRezJam way.


Posted: 2020-06-10 16:55:07 |    Posted by TylerCode |    tylercode.itch.io/

1
Login to like

So, for those of us who use unity as our primary, it's always nice to find ways to do things in unity without doing anything too hacky or dirty.  I've been looking at this technique a for a few days so I want to split it into two parts. One with lighting, one without. (With lighting might be out of date, this is a repost from my post on the LOWREZJAM 2019 board. If something doesn't work hit me up on here or on Twitter: https://twitter.com/Tyler_Code and I'll answer any questions you might have) 

Normal 2D Mode (NO LIGHTING)

Now, the way to do this before was a render texture set to 64x64 (as I did last year in my horrible 3d platformer). BUT, now there's a better way (This seems to work in 3d too, but I haven't tested it. I plan on trying it for the 2020 LOWREZJAM). 

I've looked around the last few days and found that in the package manager, if you go to the top right under advanced and click "show preview packages". (It might be out of preview as of 2019.3)

Package Manager, Show Preview Packages

You'll now have the ability to install the 2D Pixel Perfect package. Install that bad boy and add the "Pixel Perfect Camera" component to your main camera. Then, set it up as it is shown below. (These values are specific to the 64x64 jam but give a good starting point, if you wanted to lock to a 16:9 ratio you could set a low res like 480p) 

2D Pixel Perfect (In Package Manager)

Pixel Perfect Component

EDIT: GO AHEAD AND SET "UPSCALE RENDER TEXTURE" TOO. You can run in edit mode to preview in the game window.

Now after you've got that, you will have a pixel perfect game camera. I haven't messed with it too much more but wanted to share the research I'd done with the other people.

Camera In Action

 

camera rotation in action

 

With Lighting:

If you're wanting to use the new lighting systems, you need to first setup LWRP on your project.  Sykoo has a really good video showing how to set it up. 

https://youtu.be/ZJvCphxCGJU

At 5:30ish when he has you convert your resources to the new system go ahead and do it for the whole project.

After you've done that, all you need to do is add the Pixel Perfect Camera (Experimental) to your camera and give it the same settings as the non lighting version above (it works almost the same but it's been updated for LWRP (and it DOES NOT WORK on the default renderer) and also is the only way to get it to work on the lights.  (LWRP COMES WITH THE EXPERIMENTAL VERSION SO YOU DO NOT NEED TO GET THE OTHER PACKAGE) Also, if you are adding lighting midway through the project, make sure you still use the experimental one because otherwise lighting doesn't work.

Original Pixel Perfect Camera:

Game example

Pixel Perfect Camera (Experimental):

Game Example 2

 

Hard to tell the difference I know, but it's there. 

I ended up just uninstalling the normal 2D package after that. 

 

Conclusion: 

Some of this info might be out of date, but I will try to come back and update this article if anyone finds something incorrect. As mentioned above, feel free to hit me up here or on Twitter if you need some help. I've been using Unity for 10 years and I can typically noodle through any issues that come up :D

Happy Devving. 

Would you like to comment on this post? Create an account in less then 1 minute Click here

0
Login to like
1 year ago
Huemerson Commented:

Very good, it will help a lot, thank you.

0
Login to like
4 years ago
iDev Commented:

Great tutorial, Thanks for sharing!

1
Login to like
4 years ago
TylerCode Commented:

I will be updating this next month (July 2020) to reflect the current state of 2D in Uinty, it's in a batter spot now and unfortunately LWRP is no longer supported and has been replaced by URP. So I will update the guide with that. If it's July 15th 2020 and this guide doesn't show how to do this on URP hit me up on twitter to remind me to get it done.



Back to top

`Zas Alem Bump Reminder ChiefBuddy DISBOARD Dyno
11 Online Discord
·