Distortion Effects in Unity

There are various ways to create distortion effects in Unity. One of them is to access the frame texture through the OnRenderImage callback for the Built-in pipeline and perform a blit operation on this texture. For URP, an equivalent method can be considered as making adjustments on the Opaque Texture within the Render Pipeline Asset.

You need to enable Opaque Texture option from your Universal Render Pipeline Asset in URP. This way, we will be able to use "_CameraColorTexture" in our HLSL file and/or Screen Color node in Shader Graph.

"Distortion Shader"

The fundamental idea behind obtaining a distortion effect in this method is to distort the screen space UVs before the generated Frame Texture, obtained at Camera's 2500 Queue render, is mapped to the screen. With the distortion of UVs, the image will be placed differently on the screen where the UVs are altered, causing a distortion-like effect. We will use the shader we've created by applying it to a transparent object, which we'll use as a distortion object. The pixels of the Opaque Texture at the location where the object aligns with the screen will be mapped to the screen in a distorted manner.

I'm sharing this shader with you both as a Shader Graph and an HLSL file. The HLSL file has been tested in Unity 2021.3.27f1, while the Shader Graph has been tested in Unity 2021.3.15f1.

"Distortion Shader" Shader Graph: Click to Download