Hi Guys
Looking at this video . I want to leave my game in Full res but only pixelate one layer.
Cause of all the jitter in Pixel perfect cam I am not using it but using Scriptable Render pass.
So I manged to get this working following some other guides and trying to understand it all.
It Work!! But full screen only. Which I wanted but I want to mix the styles.
I Added a LayerMask in PixelizeFeature.cs ( ScriptableRendererFeature ) and pass it to PixelizePass.cs ( ScriptableRenderPass)
But I have no Idea how to apply this Layermask to it. Here is the Code and the Shader. Would love if someone cane help me on this.
PixelizePass.cs
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
public class PixelizePass : ScriptableRenderPass
{
private PixelizeFeature.CustomPassSettings settings;
private RenderTargetIdentifier colorBuffer, pixelBuffer;
private int pixelBufferID = Shader.PropertyToID("_PixelBuffer");
//private RenderTargetIdentifier pointBuffer;
//private int pointBufferID = Shader.PropertyToID("_PointBuffer");
private Material material;
private int pixelScreenHeight, pixelScreenWidth;
public PixelizePass(PixelizeFeature.CustomPassSettings settings)
{
this.settings = settings;
this.renderPassEvent = settings.renderPassEvent;
if (material == null) material = CoreUtils.CreateEngineMaterial("Hidden/Pixelize");
}
public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
{
colorBuffer = renderingData.cameraData.renderer.cameraColorTarget;
RenderTextureDescriptor descriptor = renderingData.cameraData.cameraTargetDescriptor;
//cmd.GetTemporaryRT(pointBufferID, descriptor.width, descriptor.height, 0, FilterMode.Point);
//pointBuffer = new RenderTargetIdentifier(pointBufferID);
pixelScreenHeight = settings.screenHeight;
pixelScreenWidth = (int)(pixelScreenHeight * renderingData.cameraData.camera.aspect + 0.5f);
material.SetVector("_BlockCount", new Vector2(pixelScreenWidth, pixelScreenHeight));
material.SetVector("_BlockSize", new Vector2(1.0f / pixelScreenWidth, 1.0f / pixelScreenHeight));
material.SetVector("_HalfBlockSize", new Vector2(0.5f / pixelScreenWidth, 0.5f / pixelScreenHeight));
descriptor.height = pixelScreenHeight;
descriptor.width = pixelScreenWidth;
cmd.GetTemporaryRT(pixelBufferID, descriptor, FilterMode.Point);
pixelBuffer = new RenderTargetIdentifier(pixelBufferID);
}
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
CommandBuffer cmd = CommandBufferPool.Get();
using (new ProfilingScope(cmd, new ProfilingSampler("Pixelize Pass")))
{
// No-shader variant
//Blit(cmd, colorBuffer, pointBuffer);
//Blit(cmd, pointBuffer, pixelBuffer);
//Blit(cmd, pixelBuffer, colorBuffer);
Blit(cmd, colorBuffer, pixelBuffer, material);
Blit(cmd, pixelBuffer, colorBuffer);
}
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
public override void OnCameraCleanup(CommandBuffer cmd)
{
if (cmd == null) throw new System.ArgumentNullException("cmd");
cmd.ReleaseTemporaryRT(pixelBufferID);
//cmd.ReleaseTemporaryRT(pointBufferID);
}
}
PixelizeFeature.cs
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
public class PixelizeFeature : ScriptableRendererFeature
{
[System.Serializable]
public class CustomPassSettings
{
public RenderPassEvent renderPassEvent = RenderPassEvent.BeforeRenderingPostProcessing;
public int screenHeight = 144;
public LayerMask LayerMask;
}
[SerializeField] private CustomPassSettings settings;
private PixelizePass customPass;
public override void Create()
{
customPass = new PixelizePass(settings);
}
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
{
#if UNITY_EDITOR
if (renderingData.cameraData.isSceneViewCamera) return;
#endif
renderer.EnqueuePass(customPass);
}
}
8454995–1122044–Pixelize.shader (1.79 KB)
