Posts Pixelater (픽셀화 렌더링)
Post
Cancel

Pixelater (픽셀화 렌더링)

Note


  • 렌더 텍스쳐의 해상도를 강제로 변경하여 화면을 픽셀화시킨다.
  • 스크립트를 카메라에 부착하여 사용한다.

Preview


Download


Source Code


.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

// 날짜 : 2021-01-19 PM 5:01:57
// 작성자 : Rito

namespace Rito
{
    [ExecuteInEditMode]
    public class Pixelater : MonoBehaviour
    {
        [Range(1, 100)]
        public int _pixelate = 1;

        public bool _showGUI = true;

        private void OnRenderImage(RenderTexture source, RenderTexture destination)
        {
            source.filterMode = FilterMode.Point;
            RenderTexture resultTexture = RenderTexture.GetTemporary(source.width / _pixelate, source.height / _pixelate, 0, source.format);
            resultTexture.filterMode = FilterMode.Point;

            Graphics.Blit(source, resultTexture);
            Graphics.Blit(resultTexture, destination);
            RenderTexture.ReleaseTemporary(resultTexture);
        }

        private void OnGUI()
        {
            if (!_showGUI) return;
            string text = $"Pixelate : {_pixelate,3}";

            Rect textRect = new Rect(60f, 60f, 440f, 100f);
            Rect boxRect = new Rect(40f, 40f, 460f, 120f);

            GUIStyle boxStyle = GUI.skin.box;
            GUI.Box(boxRect, "", boxStyle);

            GUIStyle textStyle = GUI.skin.label;
            textStyle.fontSize = 70;
            GUI.TextField(textRect, text, 50, textStyle);
        }
    }
}

References


This post is licensed under CC BY 4.0 by the author.