edit raytrace to make it function well

make initial p value be relevent to velocity of different layers