36 lines
1.3 KiB
C#
36 lines
1.3 KiB
C#
using UnityEngine;
|
|
using UnityEngine.Serialization;
|
|
|
|
namespace Visual
|
|
{
|
|
/// <summary>
|
|
/// https://luka712.github.io/2018/07/01/Pixelate-it-Shadertoy-Unity/#:~:text=First%20I%E2%80%99m%20going%20to%20create%20script%20for%20loading%20shader.
|
|
/// </summary>
|
|
[ExecuteInEditMode]
|
|
public class RetroPostProcess : MonoBehaviour
|
|
{
|
|
[FormerlySerializedAs("cellSize")] [SerializeField]
|
|
private Vector2 m_CellSize = new Vector2(4, 4);
|
|
|
|
private Material _material;
|
|
private static readonly int ScreenWidth = Shader.PropertyToID("_ScreenWidth");
|
|
private static readonly int ScreenHeight = Shader.PropertyToID("_ScreenHeight");
|
|
private static readonly int CellSizeX = Shader.PropertyToID("_CellSizeX");
|
|
private static readonly int CellSizeY = Shader.PropertyToID("_CellSizeY");
|
|
|
|
private void Awake()
|
|
{
|
|
_material = new Material(Shader.Find("Retroed"));
|
|
}
|
|
|
|
private void OnRenderImage(RenderTexture source, RenderTexture destination)
|
|
{
|
|
_material.SetFloat(ScreenWidth, Screen.width);
|
|
_material.SetFloat(ScreenHeight, Screen.height);
|
|
_material.SetFloat(CellSizeX, m_CellSize.x);
|
|
_material.SetFloat(CellSizeY, m_CellSize.y);
|
|
Graphics.Blit(source, destination, _material);
|
|
}
|
|
}
|
|
}
|