This paper presents a shortest-path gradients setup algorithm for directed diffusion in wireless sensor networks. Based on the research of one basic gradients setup algorithm implemented in ns2.29 for directed diffusion protocol, this paper analyzes the algorithm's key point: intermediate node's interest re-send adopts random time delay and happens only one time in one interest propagation round. Then it points out that this basic algorithm can establish some inefficient gradients which construct longer paths. This paper improves this gradients setup algorithm utilizing interest packet's forwarded times. The improved algorithm greatly decreases the probability to build "parallel gradients" and "reverse gradients", and almost set up a best gradient topology which can construct multiple shortest paths from source node to sink node. The simulation results show, using the shortest-path gradients setup algorithm, data packets will be delivered along shorter paths, and directed diffusion for wireless sensor networks is more energy efficient.