Setting up Material Domain

First, we create a basic material and set ‘Material Domain’ to ‘Post Process’.


Screen Position Center

With ScreenPosition we get the viewportUV data. Now with “component mask” we mask layer B to only have the information of R and G.
Then we need ‘Add’ set on -0.5. 


Creating Radial Gradient

Create a radial gradient to adjust the radius and falloff. For this, you can use the “RadialGradientExponential” node.
Add the result of the ‘Screen Position -Center’ to ‘UVs’. (Keeps the Center Position at 0)
Next, create a scalar parameter for AreaRadius(value=2) and AreaFalloff(value=2) so that you can expose the parameter and adjust it later within the material instance.
With the radius, we can adjust the size of the gradient from its center. Use density to adjust the hardness of the gradient.
Last but not least, we add a Switch Parameter Node with “OneMinus” after AreaRadius to invert the radius and switch between Barrel Distortion and Pincushion Distortion.


Multiplying UV Coordinates with our Radial Mask

Multiply the UV cords with the radial gradient and add an intensity function with a scalar parameter called ‘intensity’ and multiply again.  

(Be sure to use 1 as default when you multiply nodes!)


Subtracting from UV

Lastly, we subtract the multiply intensity node from our RG component mask node.
The subtraction result will go into the PostProcessInput0 Node and then in our shader.


Material Instance

Save the material and create a material instance of it.
Open it to see the scalar parameter you created earlier. You can now adjust values and distortion.

(For the Barrel Distortion we must uncheck “Invert” and set the value “AreaFalloff = 2” and “AreaRadius =2” )
(For the Pincushion Distortion we must check “Invert” and set the value “AreaFalloff = 1” and “AreaRadius =2” )


Creating and Assigning Material to Post Process

Now you can put a  “PostProcessVolume” into the scene and assign the material in the “Post Process Materials” Slot


Endresult

And this is your result!
If you have any questions feel free to send me a message 

(Screenshot of the lens distortion material)