How do you port old shaders to hlsl so they work with the new post-processing stack?

I recently upgraded my project’s graphics pipeline to the new lightweight srp. When it comes to shaders I’m a complete novice.
I tried to port several of my old shaders that I had attached to my camera to the new format so they work with the new post-processing stack, following this guide: Writing Custom Effects · Unity-Technologies/PostProcessing Wiki · GitHub. However I’m completely stumped as to what to do exactly. For example I tried to port this publicly available shader:

Shader "Hidden/Pixelation"
{
	Properties
	{
		_MainTex ("Texture", 2D) = "white" {}
	}
	SubShader
	{
		Pass
		{
			CGPROGRAM
			#pragma vertex vert_img
			#pragma fragment frag
			
			#include "UnityCG.cginc"

			sampler2D _MainTex;	
			float2 BlockCount;
			float2 BlockSize;

			fixed4 frag (v2f_img i) : SV_Target
			{
				float2 blockPos = floor(i.uv * BlockCount);
				float2 blockCenter = blockPos * BlockSize + BlockSize * 0.5;

				float4 tex = tex2D(_MainTex, blockCenter);
				return tex;
			}
			ENDCG
		}
	}
}

And this was my attempt:

Shader "Hidden/Custom/Pixelisation"
{

	

    HLSLINCLUDE

        #include "Packages/com.unity.postprocessing/PostProcessing/Shaders/StdLib.hlsl"

        TEXTURE2D_SAMPLER2D(_MainTex, sampler_MainTex);
		float2 BlockCount;
		float2 BlockSize;

    ENDHLSL

    SubShader
    {
        Cull Off ZWrite Off ZTest Always

        Pass
        {
            HLSLPROGRAM

                #pragma vertex VertDefault
                #pragma fragment Frag

				#include "Packages/com.unity.postprocessing/PostProcessing/Shaders/StdLib.hlsl"

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

				struct v2f
				{
					float2 uv:TEXCOORD0;
					float4 vertex:SV_POSITION;
				};

				v2f vert(appdata v)
				{
					v2f o;
					o.vertex=UnityObjectToClipPos(v.vertex);
					o.uv=v.uv;
					return o;
				}

				float4 Frag(v2f i) : SV_Target
			    {
				    float2 blockPos = floor(i.uv * BlockCount);
					float2 blockCenter = blockPos * BlockSize + BlockSize * 0.5;
	
					float4 tex = tex2D(_MainTex, blockCenter);
					return tex;
				}
				

            ENDHLSL
        }
    }
}

here it throws an error on UnityObjectToClipPos, saying it’s an undeclared identifier.

Can someone tell me where I’m going wrong? Or maybe point me in the right direction on this? I’m completely lost here.

@SpasticDad
I know this answer is very late and you’ve probably solved your problem by now, but as there are no responses and it might help others:

The error you’re getting is because UnityObjectToClipPos is a helper function defined in UnityCG.cginc, which you shouldn’t (can’t?) use in PPv2 and SRP’s. I’m not sure if there’s an equivalent function in stdlib.hlsl, which is the helper include file for PPv2 because I’m not too good with vertex shaders myself, but if you look here: Unity - Manual: Built-in shader helper functions you can see that you could probably write your own version of UnityObjectToClipPos. Otherwise look through the stdlib.hlsl file here: PostProcessing/PostProcessing/Shaders/StdLib.hlsl at v2 · Unity-Technologies/PostProcessing · GitHub to see if it has what you need.

As for porting old CG shaders to PPv2 HLSL shaders, the code you’ve posted has the right idea. You need to convert all CG blocks into HLSL blocks, use stdlib.hlsl instead of UnityCG.cginc, (and do the necessary cleanup that implies), and you will need to convert your scripts from a MonoBehaviour to a PostProcessingEffectRenderer. I’d recommend looking at the PPv2 documentation to see what that looks like: Writing Custom Effects | Package Manager UI website

Hope this helps somebody, nothing worse than see a question you need answered come up on Google and its unanswered when you click in.

Try using this:-

//From Built-in to URP

float4 UnityObjectToClipPos (float3 pos)
{
	float4 temp = TransformObjectToHClip(pos);
	return  temp;
}