I'm writing a software 3D rasterizer.
I managed to get a gradient triangle to work in it:
And a triangle with z-depth shown on it:
But, how do I blend these two? So that I draw a gradient triangle in a way that the top vertice color is smaller as it's more far away while the others take up more space because they are closer?
What you probably need is usually called "fog".
Define fog color (e.g. grey) and its min/max depths. Then, depending on the depth you have on your triangles fragments (pixels) mix in the fog color.
if depth < fog_min then color else if depth < fog_max then color = mix(color, fog_color, (depth - fog_min) / (fog_max - fog_min)) else color = fog_color;