Created
October 16, 2016 18:57
-
-
Save snlehton/b015bd123c2dd1889b9c96edab40b8b6 to your computer and use it in GitHub Desktop.
A simple Unity component to render the screen in lower resolution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
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
Thanks for sharing!