  We have developed a new three-dimensional algorithm, based on the standard
P$^3$M method, for computing deflections due to weak gravitational lensing. We
compare the results of this method with those of the two-dimensional planar
approach, and rigorously outline the conditions under which the two approaches
are equivalent. Our new algorithm uses a Fast Fourier Transform convolution
method for speed, and has a variable softening feature to provide a realistic
interpretation of the large-scale structure in a simulation. The output values
of the code are compared with those from the Ewald summation method, which we
describe and develop in detail. With an optimal choice of the high frequency
filtering in the Fourier convolution, the maximum errors, when using only a
single particle, are about 7 per cent, with an rms error less than 2 per cent.
For ensembles of particles, used in typical $N$-body simulations, the rms
errors are typically 0.3 per cent. We describe how the output from the
algorithm can be used to generate distributions of magnification, source
ellipticity, shear and convergence for large-scale structure.
