Skip to content

Instantly share code, notes, and snippets.

@snlehton
Created October 16, 2016 18:57
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save snlehton/b015bd123c2dd1889b9c96edab40b8b6 to your computer and use it in GitHub Desktop.
Save snlehton/b015bd123c2dd1889b9c96edab40b8b6 to your computer and use it in GitHub Desktop.
A simple Unity component to render the screen in lower resolution
using UnityEngine;
// Render the screen in lower resolution
[ExecuteInEditMode]
[RequireComponent(typeof(Camera))]
public class ResoScaler : MonoBehaviour
{
[Range(1, 8)]
public float scale = 1;
public FilterMode filterMode = FilterMode.Point;
private RenderTexture rt;
void OnPreRender()
{
// before rendering, setup our RenderTexture
int width = Mathf.RoundToInt(Screen.width / scale);
int height = Mathf.RoundToInt(Screen.height / scale);
rt = RenderTexture.GetTemporary(width, height, 24, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default, 1);
GetComponent<Camera>().targetTexture = rt;
}
void OnPostRender()
{
// after rendering we need to clear the targetTexture so that post effect will be able to render
// to the screen
GetComponent<Camera>().targetTexture = null;
RenderTexture.active = null;
}
void OnRenderImage(RenderTexture src, RenderTexture dest)
{
// set our filtering mode and blit to the screen
src.filterMode = filterMode;
Graphics.Blit(src, dest);
RenderTexture.ReleaseTemporary(rt);
}
}
@trialforce
Copy link

Thanks for sharing!

@trialforce
Copy link

In new versions of Unity it is not working anymore. Any sugestions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment