Low-Res URP Feature
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
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