How to DrawRenderer in URP correctly

I am trying this shader in URP,but something just wrong
The shader tutorial

And here is the shader link

My shader and code if you need
DistortionParticle

Shader "Unlit/DistortionParticle"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
        _Magnitude ("Magnitude", Float) = 1
    }
    SubShader
    {
        Tags
        {
            "RenderType" = "Transparent"
            "Queue" = "Transparent"
        }
        Pass
        {
            Blend One One
            Cull Off
            ZWrite Off
            ZTest Always
       
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag           
            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
                float4 color : COLOR;
            };

            struct v2f
            {
                float4 vertex : SV_POSITION;
                float2 uv : TEXCOORD0;
                float alpha : TEXCOORD1;
                float4 projPos : TEXCOORD2;
            };

            sampler2D _MainTex;
            sampler2D_float _CameraDepthTexture;
            float4 _MainTex_ST;
            float _Magnitude;
           
            v2f vert (appdata v)
            {
                v2f o;
               
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                o.alpha = v.color.a;
                o.projPos = ComputeScreenPos(o.vertex);
                COMPUTE_EYEDEPTH(o.projPos.z);
               
                return o;
            }
           
            float2 frag (v2f i) : SV_Target
            {
                float sceneEyeDepth = DECODE_EYEDEPTH(tex2D(_CameraDepthTexture, i.projPos.xy / i.projPos.w));
                float zCull = sceneEyeDepth > i.projPos.z;
                float3 data = UnpackNormal(tex2D(_MainTex, i.uv)).xyz;
                float scale = data.b * i.alpha * _Magnitude;
                return data.rg * scale * zCull;
            }
            ENDCG
        }
    }
}

Distortion

Shader "Hidden/Distortion" {
    Properties{
        _MainTex("MainTex",2D) = "White"{}
        _GlobalDistortionTex("GlobalDistortionTex",2D) = "White"{}
        _Magnitude("Magnitude",float) = 1
    }
    SubShader{
        Tags { "RenderPipeline" = "UniversalPipeline" }

        HLSLINCLUDE
            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"

            CBUFFER_START(UnityPerMaterial)
            TEXTURE2D(_MainTex);
            SAMPLER(sampler_MainTex);
            TEXTURE2D(_GlobalDistortionTex);
            SAMPLER(sampler_GlobalDistortionTex);
            float4 _MainTex_TexelSize;
            float _Magnitude;
            float4 _MainTex_ST;
            CBUFFER_END
        ENDHLSL
                // No culling or depth
                Cull Off ZWrite Off ZTest Always
        Pass {
            Name "Distortion"
            HLSLPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            struct Attributes {
                float4 positionOS    : POSITION;
                float2 uv        : TEXCOORD0;
            };
            struct Varyings {
                float4 positionCS     : SV_POSITION;
                float2 uv        : TEXCOORD0;
            };
            Varyings vert(Attributes IN) {
                Varyings OUT;
                OUT.positionCS = TransformObjectToHClip(IN.positionOS.xyz);
                OUT.uv = TRANSFORM_TEX(IN.uv, _MainTex);
                return OUT;
            }
            half4 frag(Varyings i) : SV_Target {
            float2 mag = _Magnitude * _MainTex_TexelSize.xy;
            float2 distortion = SAMPLE_TEXTURE2D(_GlobalDistortionTex, sampler_GlobalDistortionTex, i.uv).xy * mag;
            float4 color = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv+ distortion);
            return color;
            }
            ENDHLSL
        }
    }
}

ScriptableRendererFeature

using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;

public class Heat : ScriptableRendererFeature
{
    public Setting settings = new Setting();
    CustomRenderPass m_ScriptablePass;
    RenderTargetHandle heatTexture;
    public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
    {
        m_ScriptablePass.set(renderingData.cameraData.cameraTargetDescriptor,renderer.cameraColorTarget, heatTexture);
        renderer.EnqueuePass(m_ScriptablePass);
    }

    public override void Create()
    {
        settings.heatItem = GameObject.FindObjectOfType<HeatItem>();
        m_ScriptablePass =
            new CustomRenderPass(settings.Magnitude, settings.DownScaleFactor,settings.heatItem,settings.mat);
    }
    [System.Serializable]
    public class Setting
    {
        public RenderPassEvent renderPassEvent;
        public int Magnitude;
        public int DownScaleFactor;
        public HeatItem heatItem;
        public Material mat;
    }
    class CustomRenderPass : ScriptableRenderPass
    {
        RenderTargetIdentifier sour;
        public int Magnitude;
        public int DownScaleFactor;
        public HeatItem heatItem;
        public Material mat;

        private RenderTargetHandle tempRenderTarget;
        private RenderTargetHandle heatRenderTarget;
        internal RenderTextureDescriptor descriptor { get; private set; }
        public CustomRenderPass(int Magnitude, int DownScaleFactor, HeatItem heatItem, Material mat)
        {
            this.Magnitude = Magnitude;
            this.DownScaleFactor = DownScaleFactor;
            this.mat = mat;
            this.heatItem = heatItem;
            tempRenderTarget.Init("TemporaryColorTexture");
            heatRenderTarget.Init("_GlobalDistortionTex");
        }
        public void set(RenderTextureDescriptor baseDescriptor,RenderTargetIdentifier sour, RenderTargetHandle heat)
        {
            this.sour = sour;
            this.heatRenderTarget = heat;
            baseDescriptor.colorFormat = RenderTextureFormat.RGFloat;
            baseDescriptor.depthBufferBits = 0;
            descriptor = baseDescriptor;
        }

        public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
        {
            cmd.GetTemporaryRT(heatRenderTarget.id, descriptor, FilterMode.Bilinear);
            ConfigureTarget(heatRenderTarget.Identifier());
            ConfigureClear(ClearFlag.Color, Color.clear);
        }
        public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
        {
            if (heatItem.material == null) return;
            mat.SetFloat("_Magnitude", Magnitude);
            RenderTextureDescriptor
            SSdesc = renderingData.cameraData.cameraTargetDescriptor;
            Camera cam = renderingData.cameraData.camera;
            CommandBuffer cmd = CommandBufferPool.Get("Heat");

            cmd.DrawRenderer(heatItem.renderer, heatItem.material);
            cmd.SetGlobalTexture("_GlobalDistortionTex", heatRenderTarget.id);


            cmd.GetTemporaryRT(tempRenderTarget.id, renderingData.cameraData.cameraTargetDescriptor);
            Blit(cmd, sour, tempRenderTarget.Identifier(), mat);
            Blit(cmd, tempRenderTarget.Identifier(), sour);

            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
        }
        public override void FrameCleanup(CommandBuffer cmd)
        {
            if (heatRenderTarget != RenderTargetHandle.CameraTarget)
            {
                cmd.ReleaseTemporaryRT(heatRenderTarget.id);
                heatRenderTarget = RenderTargetHandle.CameraTarget;
            }
        }
    }
}

HeatItem(add on the particle gameobject)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[ExecuteInEditMode]
public class HeatItem : MonoBehaviour
{
    public Renderer renderer;
    public Material material;

    private void Start()
    {
        material = renderer.sharedMaterial;
    }
}

I can see the Distortion in scene


But there is nothing in Game
6614230--752971--upload_2020-12-12_12-14-56.png
Any replay will be very helpful!!!

OK,i fixed it,Don’t use DrawRenderer:face_with_spiral_eyes:

            //cmd.DrawRenderer(heatItem.renderer, heatItem.material);
            if (!particleMesh) particleMesh = new Mesh();
           
            heatItem.renderer.BakeMesh(particleMesh, renderingData.cameraData.camera);

            bool localSpace = heatItem.particleSystem.main.simulationSpace == ParticleSystemSimulationSpace.Local;
            cmd.DrawMesh(particleMesh, localSpace ? heatItem.renderer.localToWorldMatrix : Matrix4x4.identity, heatItem.material);

Particles don’t render via DrawRenderer???
Did any one have better solution…:eyes: