Skip to content

Instantly share code, notes, and snippets.

@saturngamesss
Last active May 15, 2020 17:28
Show Gist options
  • Save saturngamesss/c09549c2029c3487d62575f41ddbac24 to your computer and use it in GitHub Desktop.
Save saturngamesss/c09549c2029c3487d62575f41ddbac24 to your computer and use it in GitHub Desktop.
Simple pixel camera code for Unity Engine.
//FROM PROJECT ROROPE || REAL GAMES STUDIO
//************************************************
//https://realgamesss.weebly.com
//https://gamejolt.com/@RealGamesss
//https://realgamesss.newgrounds.com/
//https://real-games.itch.io/
//https://youtube.com/channel/UC_Adg-mo-IPg6uLacuQCZCQ
//************************************************
using UnityEngine;
[ExecuteInEditMode]
[AddComponentMenu("Image Effects/Pixelation")]
public class Pixelation : MonoBehaviour
{
public int w = 720;
int h;
protected void Start()
{
if (!SystemInfo.supportsImageEffects)
{
enabled = false;
return;
}
}
void Update()
{
float ratio = ((float)Camera.main.pixelHeight / (float)Camera.main.pixelWidth);
h = Mathf.RoundToInt(w * ratio);
}
void OnRenderImage(RenderTexture source, RenderTexture destination)
{
source.filterMode = FilterMode.Point;
RenderTexture buffer = RenderTexture.GetTemporary(w, h, -1);
buffer.filterMode = FilterMode.Point;
Graphics.Blit(source, buffer);
Graphics.Blit(buffer, destination);
RenderTexture.ReleaseTemporary(buffer);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment