Video player as post proceessing effect with custom scriptable render pass

Hello , I’ve a shader effect that takes render texture from a video player component then use Graphics.Blit(source, destination, _material); .

I need to enable /disable the effect at runtime , unfortunately I can’t use ScriptableRenderPass andMonoBehaviour at the same time .

can someone please help me convert this into urp .

//vhsprocesseffect.cs

using UnityEngine;
using UnityEngine.Video;
using UnityEngine.UI;
namespace effect {
    public class VHSPostProcessEffect : MonoBehaviour
    {
        public Shader shader;
        public VideoClip VHSClip;

        private float _yScanline;
        private float _xScanline;
        private Material _material = null;
        private VideoPlayer _player;
        //public bool rewinding = false;


        private void OnEnable()
        {
            _material = new Material(shader);
            _player = GetComponent<VideoPlayer>();
            _player.isLooping = true;
            _player.renderMode = VideoRenderMode.APIOnly;
            _player.audioOutputMode = VideoAudioOutputMode.None;
            _player.clip = VHSClip;
            _player.Play();

        }
        void Start()
        {
       
            //
        }

        void OnRenderImage(RenderTexture source, RenderTexture destination)
        {
            _material.SetTexture("_VHSTex", _player.texture);

            _yScanline += Time.deltaTime * 0.01f;
            _xScanline -= Time.deltaTime * 0.1f;

            if (_yScanline >= 1)
            {
                _yScanline = Random.value;
            }
            if (_xScanline <= 0 || Random.value < 0.05)
            {
                _xScanline = Random.value;
            }
            _material.SetFloat("_yScanline", _yScanline);
            _material.SetFloat("_xScanline", _xScanline);
            Graphics.Blit(source, destination, _material);
        }

        protected void OnDisable()
        {
            if (_material)
            {
                DestroyImmediate(_material);//
            }
        }

        void update()
        {

        }
    }
}

and here’s the shader

Shader "Hidden/VHSPostProcessEffect" {
    Properties{
        _MainTex("Base (RGB)", 2D) = "white" {}
        _VHSTex("Base (RGB)", 2D) = "white" {}
    }

        SubShader{
            Pass {
                ZTest Always Cull Off ZWrite Off
                Fog { Mode off }

                CGPROGRAM
                #pragma vertex vert_img
                #pragma fragment frag
                #pragma fragmentoption ARB_precision_hint_fastest
                #include "UnityCG.cginc"

                uniform sampler2D _MainTex;
                uniform sampler2D _VHSTex;

                float _yScanline;
                float _xScanline;
                float rand(float3 co) {
                     return frac(sin(dot(co.xyz ,float3(12.9898,78.233,45.5432))) * 43758.5453);
                }

                fixed4 frag(v2f_img i) : COLOR{
                    fixed4 vhs = tex2D(_VHSTex, i.uv);

                    float dx = 1 - abs(distance(i.uv.y, _xScanline));
                    float dy = 1 - abs(distance(i.uv.y, _yScanline));

                    //float x = ((int)(i.uv.x*320))/320.0;
                    dy = ((int)(dy * 15)) / 15.0;
                    dy = dy;
                    i.uv.x += dy * 0.025 + rand(float3(dy,dy,dy)).r / 500;//0.025;

                    float white = (vhs.r + vhs.g + vhs.b) / 3;

                    if (dx > 0.99)
                        i.uv.y = _xScanline;
                    //i.uv.y = step(0.99, dy) * (_yScanline) + step(dy, 0.99) * i.uv.y;

                    i.uv.x = i.uv.x % 1;
                    i.uv.y = i.uv.y % 1;

                    fixed4 c = tex2D(_MainTex, i.uv);

                    float bleed = tex2D(_MainTex, i.uv + float2(0.01, 0)).r;
                    bleed += tex2D(_MainTex, i.uv + float2(0.02, 0)).r;
                    bleed += tex2D(_MainTex, i.uv + float2(0.01, 0.01)).r;
                    bleed += tex2D(_MainTex, i.uv + float2(0.02, 0.02)).r;
                    bleed /= 6;

                    if (bleed > 0.1) {
                        vhs += fixed4(bleed * _xScanline, 0, 0, 0);
                    }

                    float x = ((int)(i.uv.x * 320)) / 320.0;
                    float y = ((int)(i.uv.y * 240)) / 240.0;

                    c -= rand(float3(x, y, _xScanline)) * _xScanline / 5;
                    return c + vhs;
                }
                ENDCG
            }
    }
        Fallback off
}

I tried to use a library from github which convnert any material into render feature but
unfortunately it doesn’t affect sprites (it render at the background ) the original effect does applys for gui too .
also using render texture as overlay doesn’t looks good as it isn’t native post processing effect .

I think it works :eyes:? but I didn’t set it up correctly ,

oh yes , I had to use screenspace camera mode on canvas ui
the library I used :