This is a rectangular geometry created with the boxgeometry, and eight LineSegments were created with LineSegments. The shader in the figure is used for the line segment. Why do I just offset its vertices, but it looks like the rendering order has changed? You can clearly see that the lines that should be shaded by the cuboid are also shown
The offset your are adding to ps
is incorrect. Keep in mind that ps
represents coordinates in clip space. Adding an offset in world space will produce wrong results (especially a corrupted depth value).

Yeah, I didn’t write it quite right yesterday, so I changed the code to look like this. First, the world coordinates of the vertices are obtained, and then a distance is offset in the direction of the lens. However, the effect shown here is not the same as What I expected. I shifted it by five units, but you can see in the figure that the position of the line does not seem to change. Is there any problem with my shader?
Hi!
It does, but straight towards the camera’s origin from each vertex. You can set 10 units shift and get the same result, except when your point is closer than near
plane of the camera, I think.