Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Low-Res URP Feature
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
public class PixalizationRenderFeature : ScriptableRendererFeature
{
class PixalizationRenderPass : ScriptableRenderPass
{
PixalizationRenderFeature _parent;
RenderTargetIdentifier _sourceID;
string _profilingName;
RenderTargetHandle _tempTextureHandle;
public PixalizationRenderPass(PixalizationRenderFeature parent)
{
_parent = parent;
_profilingName = parent.name;
_tempTextureHandle.Init("_TempPixalizationTexture");
}
public void SetSource(RenderTargetIdentifier source)
{
_sourceID = source;
}
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
CommandBuffer cmd = CommandBufferPool.Get(_profilingName);
cmd.GetTemporaryRT(
_tempTextureHandle.id,
_parent._RenderTextureWidth,
_parent._RenderTextureHeight,
0,
FilterMode.Point,
RenderTextureFormat.ARGB32,
RenderTextureReadWrite.Default,
1,
false
);
Blit(cmd, _sourceID, _tempTextureHandle.Identifier());
Blit(cmd, _tempTextureHandle.Identifier(), _sourceID);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
public override void FrameCleanup(CommandBuffer cmd)
{
cmd.ReleaseTemporaryRT(_tempTextureHandle.id);
}
}
[SerializeField]
int _RenderTextureWidth = 256 * 2;
[SerializeField]
int _RenderTextureHeight = 144 * 2;
[SerializeField]
RenderPassEvent _RenderEvent = RenderPassEvent.AfterRenderingOpaques;
PixalizationRenderPass _renderPass;
public override void Create()
{
_renderPass = new PixalizationRenderPass(this);
_renderPass.renderPassEvent = _RenderEvent;
}
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
{
_renderPass.SetSource(renderer.cameraColorTarget);
renderer.EnqueuePass(_renderPass);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment