ray casting and calculate depth value

now I use ray casting algorithm do volume rendering.And I need draw a object(some lines) in fixed pipeline.I hope the lines can display correct.like the follow image
.It seems I need calculate depth value in fragment shader,any one can tell me how to do it?thanks