- Home /
How do I achieve pixel perfect effect and what do I need to have in mind if I go the Pixel Perfect route?
I know this has been asked before, and please understand that I have read as many Unity Answer questions as I have been able to find. Not to mention numerous tutorials and blogs that discuss Pixel Perfect orthographic cameras. I feel like I'm close but I'm still having issues with getting everything working correctly and there seems to be a few different strategies to achieving this and I think this is confusing me. Honestly, this does not seem all that complicated but something is still confusing me.
Here's what I know:
First I should have a resolution in mind, let's say 1024 x 768
I should also have an idea about the size of my sprites, how about 64 x 64
I create an orthographic camera in the Unity Editor and set the size to 6 because I want to be able to display 12 sprites vertically. (12 units will be equal to the vertical measurement of my camera)
I've set my resolution by clicking Edit > Project Settings > Player and my settings look like this:
Default Screen Width: 1024 Default Screen Height: 768 Supported Resolutions: All of them are checked.
I create a mesh in blender that is 1 x 1 unit wide according to blender's default scale (I've read that Blender and Unity both use 1 meter as the default unit)
I import the mesh and set the scale to 1 because by default Unity imports .3ds at 0.1
The first texture I create will be the ground(It's a 2D top-down perspective game). I create the texture with the measurements of the resolution because I want this to cover the entire screen.
---Questions--- 1. I know that my 1 x 1 mesh will not work for the background texture because that the mesh will hold only 64 x 64 pixels, what size mesh would I create to hold the background image and how is this calculated?
Are the above steps correct, is my understanding of what I need to do complete or am I missing something? If so can you please point out what is missing and where I can go to broaden my understanding?
It's clear to me how to work with the vertical size but the horizontal size is a mystery to me. I've seen someone write that it's based on the aspect ratio. How do I ensure that the game will be correct no matter what resolution display? I feel like it needs a script of some sort to adjust the horizontal measurements based on the current resolution, I know C# but I'm not sure what I need to adjust to accomplish this.
If my understanding of the setting of the orthographic camera size is not correct, can you please explain where I am wrong and the correct procedure?
Thank you to anyone who takes the time to read and/or answer my question. I've made a decent number of games from scratch in pygame and even a game in Unity (A 2D shooter at that!) but pygame is 2D by design and because I didn't release the 2D shooter I didn't even mess with the resolution/orthographic size at all since it was only played on my personal monitor. This pixel perfect effect is really tricky for some reason because it really seems simple yet when I load up my background texture, make a material out of it, and attach it to the mesh renderer component it is never the size I need it to be.
Answer by robertbu · Aug 06, 2013 at 08:03 PM
1) The mesh will hold any size you want. So if you scale it to (2,2,2), then something 128 x 128 will display pixel perfect (given your other settings).
2) The aspect ratio of your game will be Screen.width/Screen.height. So for 1024 x 768 it will be 1.3333. So if your screen is 12 units high it will be 16 units wide. As resolution changes, the width will change but not the height. So how you handle this will be game specific.
robertbu: So I got around my problem by changing the scale of the quad I created (1x1 in Blender) to x: 16 and y: 12, my ortho size is 6 and I've changed my resolution to 640 x 480. So, correct me if I am wrong, my background texture I created is 640 x 480 pixels therefor if I attach this texture to my quad scaled to x: 16 and y: 12 I should have 640 pixels horizontal and 480 vertical correct?
And each one of my Unity world units will be 40 x 40 pixels? That seems wrong or just unusual for some reason, I'm not really understanding why but I thought that I could get the size in pixels of world units by dividing the vertical resolution by the ortho size * 2...
All your calculations are correct. Not sure what you are seeing that make you think they are not. $$anonymous$$ake sure your camera is at (0,0,0). Note there is a CreatePlane script that would allow you to create a plane of any specific size and in either a vertical or horizontal orientation in the Unity editor here:
Okay, I think I'm satisfied with what I've got so far. Thank you!