I have implemented a software rasterizer for occlusion culling. However, In some cases I get strange depth map results when polygons get clipped by frustum, especially when clipped by near plane. I am clipping points in homogenous coordinates (before w division) using -w <= x,y,z <= w.
Point interpolation along the edge (for near plane) is done like this:
newPoint = p1 + (p2-p1) * t;
t = (-p1.w - p1.z) / (p2.z - p1.z + p2.w - p1.w);
Depth map with wrong depth interpolation is in the attachment.