I am working on a 2D “pixel perfect” project. Currently I am designing for a fixed resolution of 1200x675.
I would like to know how to prevent anti-aliasing when the build goes into full screen mode. I would like to release my project on a couple different platforms (xbox, steam), and I am hoping I can rely on the idea that the scaling the unity does will be enough to accommodate for different screen resolutions (though with the same aspect ratio).
For example, when i run the stand-alone player on my desktop, then enter full-screen mode, it seems like there is a bit of blurring. I have my sprites sent to point filtering, but I am wondering if there is yet another option in the player or build settings I should explore so that the graphics are as clean as possible when stretched.
I had briefly tried to adjust the quality settings only allowing for fatest, hoping that would force basic graphic scaling, but the build wound up running at 200fps, and caused a fair amount of strange behavior in the game.
Building on the solution from @Namey5 , I have the following code in C#. I simplified it down to just one script for my needs. I hope it helps others. In my case, I build most of my game via code, so having something rendering in the game preview when I am not playing the game wasn’t something I needed to consider.
PixelPerfectRenderer.cs (Attach to your camera)
using UnityEngine;
using System.Collections;
public class PixelPerfectRenderer : MonoBehaviour {
// PUBLIC VARS ----
public FilterMode filterMode;
public int scaling = 100;
public Depth depth = Depth.twentyfour;
// STRUCTS ----
public enum Depth {
none,
sixteen,
twentyfour
};
// PRIVATE VARS ----
private Camera renderCamera;
private RenderTexture src;
private bool isFullScreen;
// UNITY API ----
void Awake () {
isFullScreen = Screen.fullScreen;
SetRenderCam();
}
void Update() {
// have we toggled the windows/fullscreen mode?
if(Screen.fullScreen != isFullScreen) {
isFullScreen = !isFullScreen;
SetRenderCam();
}
}
void OnPreRender() {
// this ensures that w/e the camera sees is rendered to our RenderTexture
renderCamera.targetTexture = src;
}
void OnPostRender() {
// for some reason we need to se the traget texture to null before we blit
renderCamera.targetTexture = null;
// casting null as a RenderTexture allows us to blit to the screen
Graphics.Blit(src, null as RenderTexture);
}
// PUBLIC FUNCTIONS ----
public int DepthCalc(Depth d) {
if(d == Depth.none) {
return 0;
}
if(d == Depth.sixteen) {
return 16;
}
if(d == Depth.twentyfour) {
return 24;
}
return 0;
}
public void SetRenderCam() {
if (!renderCamera) {
renderCamera = GetComponent<Camera>();
}
// we could use this to do scaling at different percentages
int s = scaling / 100;
src = new RenderTexture(Screen.width * s, Screen.height * s, DepthCalc(depth));
src.filterMode = filterMode;
renderCamera.targetTexture = src;
}
}