Skip to content

Instantly share code, notes, and snippets.

Created October 5, 2022 13:22
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Cyanilux/d16dbfec869dbfb690426c837745679c to your computer and use it in GitHub Desktop.
RenderFeature used in Glitch Highlights effect -
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
public class GlitchRenderFeature : ScriptableRendererFeature {
class CustomRenderPass : ScriptableRenderPass {
private Settings settings;
private FilteringSettings filteringSettings;
private ProfilingSampler m_ProfilingSampler;
private List<ShaderTagId> m_ShaderTagIdList = new List<ShaderTagId>();
private RenderTargetHandle tempRT;
public CustomRenderPass(Settings settings) {
this.settings = settings;
filteringSettings = new FilteringSettings(RenderQueueRange.opaque, settings.layerMask);
m_ShaderTagIdList.Add(new ShaderTagId("SRPDefaultUnlit"));
m_ShaderTagIdList.Add(new ShaderTagId("UniversalForward"));
m_ProfilingSampler = new ProfilingSampler("Glitch");
public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData) {
// Setup temporary render texture
RenderTextureDescriptor opaqueDesc = renderingData.cameraData.cameraTargetDescriptor;
opaqueDesc.depthBufferBits = 0;
cmd.GetTemporaryRT(, opaqueDesc, FilterMode.Bilinear);
// Configure which render target we are drawing to
ConfigureClear(ClearFlag.Color, Color.clear);
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) {
CommandBuffer cmd = CommandBufferPool.Get();
// Draw renderers to render target
using (new ProfilingScope(cmd, m_ProfilingSampler)) {
SortingCriteria sortingCriteria = renderingData.cameraData.defaultOpaqueSortFlags;
DrawingSettings drawingSettings = CreateDrawingSettings(m_ShaderTagIdList, ref renderingData, sortingCriteria);
drawingSettings.overrideMaterialPassIndex = 0;
drawingSettings.overrideMaterial = settings.glitchMaterial;
context.DrawRenderers(renderingData.cullResults, ref drawingSettings, ref filteringSettings);
// Blit tempRT to camera target, using blitMaterial
cmd.Blit(tempRT.Identifier(), renderingData.cameraData.renderer.cameraColorTarget, settings.blitMaterial, 0);
public override void OnCameraCleanup(CommandBuffer cmd) {
CustomRenderPass m_ScriptablePass;
public class Settings {
public RenderPassEvent renderPassEvent;
public Material glitchMaterial;
public Material blitMaterial;
public LayerMask layerMask;
public Settings settings;
public override void Create() {
m_ScriptablePass = new CustomRenderPass(settings);
m_ScriptablePass.renderPassEvent = settings.renderPassEvent;
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment