Last active
May 15, 2020 17:28
-
-
Save saturngamesss/c09549c2029c3487d62575f41ddbac24 to your computer and use it in GitHub Desktop.
Simple pixel camera code for Unity Engine.
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
//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