I propose a waveform inversion scheme that estimates three-dimensional basin structure, in particular, the depth of the boundary between sediment and bedrock. This study is an extension of the boundary shape waveform inversion scheme (Aoi et al., 1995, 1997) to a three-dimensional structure. The idea is to directly parameterize the basin topography and invert it by using long-period strong ground motions including basin-induced waves and direct waves. The depth of the topography is represented by a series of model parameters and basis functions that are rectangular (boxcar) functions. By this choice of basis functions, the inversion determines the average depth of the bedrock inside rectangles with the constraint that the observation equation, which is nonlinear in the model parameters, be satisfied best in the sense of least squares. The observation equation is linearized by omitting higher-order terms and is solved iteratively by singular value decomposition. To solve this equation, sensitivity functions (differential seismograms) are required, as well as the synthetic waveforms themselves. In this study, the finite-difference method (FDM) is used to calculate waveforms. Sensitivity functions are obtained numerically by taking the difference of waveforms from perturbed and unperturbed models. The positions of the discontinuity of the medium are required to lie on, not between, the finite-difference (FD) grid points to maintain the accuracy of FD calculation. The basis functions having rectangular domain are chosen to overcome this limitation. Since the basis functions take a constant value in a particular rectangle, inside the rectangle the perturbed model is just one grid deeper than the unperturbed model. The inverted correction values of the parameters for each iteration are rounded to the nearest multiple of the grid spacing of the FD calculation. I show the formulation of the proposed scheme and demonstrate its validity by performing a numerical experiment.